当前位置:   article > 正文

verdaccio搭建_verdaccio 搭建

verdaccio 搭建

说明

目前使用verdaccio做为前端npm私服,保存一些项目私有的前端组件,npm私库目前和nexus仓库部署在同一台ECS,目前设置IP为10.100.10.100

 一、安装过程

  1. ###verdaccio使用docker-compose的方式,官方镜像一键搭建
  2. [root@zhgd-jumpserver-prod verdaccio]# cat docker-compose.yml
  3. version: "3.0"
  4. services:
  5. verdaccio:
  6. container_name: zhgd-verdaccio
  7. image: "verdaccio/verdaccio"
  8. ports:
  9. - "4873:4873"
  10. environment:
  11. VERDACCIO_PUBLIC_URL: 'https://zhgd-npm.xingshicloud.com'
  12. volumes:
  13. - "./storage:/verdaccio/storage"
  14. - "./conf/config.yaml:/verdaccio/conf/config.yaml"
  15. restart: "always"
  16. ###一键启动
  17. [root@zhgd-jumpserver-prod verdaccio]# docker-compose up -d

二、基本设置

  1. ###挂载的配置文件如下
  2. [root@zhgd-jumpserver-prod verdaccio]# cat conf/config.yaml
  3. storage: /verdaccio/storage/data
  4. plugins: /verdaccio/plugins
  5. web:
  6. title: Verdaccio
  7. auth:
  8. htpasswd:
  9. file: /verdaccio/storage/htpasswd
  10. ###这里现在写成不允许新注册用户了,zhgd这个用户是在没有这个配置的情况下先注册的
  11. max_users: -1
  12. ###配置代理仓库地址
  13. uplinks:
  14. npmjs:
  15. url: https://registry.npmjs.org/
  16. taobao:
  17. url: https://registry.npmmirror.com/
  18. packages:
  19. '@*/*':
  20. # scoped packages
  21. access: $authenticated
  22. publish: $authenticated
  23. unpublish: $authenticated
  24. proxy: taobao npmjs
  25. '**':
  26. # allow all users (including non-authenticated users) to read and
  27. # publish all packages
  28. #
  29. # you can specify usernames/groupnames (depending on your auth plugin)
  30. # and three keywords: "$all", "$anonymous", "$authenticated"
  31. access: $authenticated
  32. # allow all known users to publish/publish packages
  33. # (anyone can register by default, remember?)
  34. publish: $authenticated
  35. unpublish: $authenticated
  36. # if package is not available locally, proxy requests to 'npmjs' registry
  37. proxy: taobao
  38. server:
  39. keepAliveTimeout: 60
  40. middlewares:
  41. audit:
  42. enabled: true

三、本地开发适配

        verdaccio仓库目前没有集成LDAP或者gitlab的账号认证系统,故也是所有开发者使用同一个“zhgd”账号的认证方式

  1. ###本地开发者如需使用此私库,需要先添加并登陆
  2. [root@8-70-nginx ~]# nrm add zhgd https://zhgd-npm.xingshicloud.com
  3. add registry zhgd success
  4. [root@8-70-nginx ~]# nrm ls
  5. npm ---------- https://registry.npmjs.org/
  6. yarn --------- https://registry.yarnpkg.com/
  7. tencent ------ https://mirrors.cloud.tencent.com/npm/
  8. cnpm --------- https://r.cnpmjs.org/
  9. taobao ------- https://registry.npmmirror.com/
  10. npmMirror ---- https://skimdb.npmjs.com/registry/
  11. pmcnpm ------- http://172.16.9.19:7001/
  12. * pm ----------- http://172.16.9.19:4873/
  13. zhgd --------- https://zhgd-npm.xingshicloud.com/
  14. [root@8-70-nginx ~]# nrm use zhgd
  15. Registry has been set to: https://zhgd-npm.xingshicloud.com/
  16. [root@8-70-nginx ~]# npm login
  17. Username: zhgd
  18. Password:
  19. Email: (this IS public) test@163.com
  20. Logged in as zhgd on https://zhgd-npm.xingshicloud.com/.

四、npm仓库备份

  1. ###参照nexus仓库的方式,npm仓库也用rsync脚本进行了备份,完整脚本如下
  2. [root@zhgd-mysql-cloudcanal-kubepi-prod ~]# crontab -l
  3. 00 02 * * * /bin/bash /k8slog/10.100.10.206/npm_backup/rsync_npm.sh
  4. 30 02 * * * /bin/bash /k8slog/10.100.10.206/nexus_backup/rsync_nexus.sh
  5. [root@zhgd-mysql-cloudcanal-kubepi-prod ~]# cat /k8slog/10.100.10.206/npm_backup/rsync_npm.sh
  6. #!/bin/bash
  7. remote_ip=10.100.10.206
  8. rsync_user=opshaibo
  9. rsync_dir=/k8slog/$remote_ip/npm_backup/verdaccio
  10. DATE=`date +%Y%m%d%H%M%S`
  11. LogFile=/k8slog/$remote_ip/npm_backup/npmbackup.log
  12. echo -e "\033[36m ---------------------开始备份 $DATE -----------------\033[0m">>$LogFile
  13. #备份命令如下:
  14. ##--delete删除目标目录比源目录中多的文件
  15. rsync -avzu --delete --progress rsync://${rsync_user}@${remote_ip}/npmdata ${rsync_dir} --password-file=/etc/rsync_client.pas
  16. if [ $? -eq 0 ];
  17. then
  18. echo -e " \033[32m 三局私有npm仓库 rsync备份成功\033[0m">>$LogFile
  19. #企业微信报警
  20. curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=126acc51-3bd8-421d-ae1c-19bfdbff70e2' \
  21. -H 'Content-Type: application/json' \
  22. -d '
  23. {
  24. "msgtype": "markdown",
  25. "markdown": {
  26. "content": "<font color=\"warning\">三局私有npm仓库 rsync备份成功</font>"
  27. }
  28. }'
  29. else
  30. echo -e "\033[31m 三局私有npm仓库 rsync备份失败\033[0m">>$LogFile
  31. #企业微信报警
  32. curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=126acc51-3bd8-421d-ae1c-19bfdbff70e2' \
  33. -H 'Content-Type: application/json' \
  34. -d '
  35. {
  36. "msgtype": "markdown",
  37. "markdown": {
  38. "content": "<font color=\"warning\">三局私有npm仓库 rsync备份失败,请快速解决问题!!</font>"
  39. }
  40. }'
  41. fi
  42. now_time=`date +%Y%m%d%H%M%S`
  43. tar -czPf npm-${now_time}.tar.gz /k8slog/$remote_ip/npm_backup/verdaccio
  44. mv npm-${now_time}.tar.gz /k8slog/$remote_ip/npm_backup/tar/
  45. find /k8slog/$remote_ip/npm_backup/tar -name "*.tar.gz" -mtime +7 -exec rm -f {} \;
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/399134
推荐阅读
相关标签
  

闽ICP备14008679号