赞
踩
说明
目前使用verdaccio做为前端npm私服,保存一些项目私有的前端组件,npm私库目前和nexus仓库部署在同一台ECS,目前设置IP为10.100.10.100
一、安装过程
- ###verdaccio使用docker-compose的方式,官方镜像一键搭建
- [root@zhgd-jumpserver-prod verdaccio]# cat docker-compose.yml
- version: "3.0"
- services:
- verdaccio:
- container_name: zhgd-verdaccio
- image: "verdaccio/verdaccio"
- ports:
- - "4873:4873"
- environment:
- VERDACCIO_PUBLIC_URL: 'https://zhgd-npm.xingshicloud.com'
- volumes:
- - "./storage:/verdaccio/storage"
- - "./conf/config.yaml:/verdaccio/conf/config.yaml"
- restart: "always"
-
- ###一键启动
- [root@zhgd-jumpserver-prod verdaccio]# docker-compose up -d
二、基本设置
- ###挂载的配置文件如下
- [root@zhgd-jumpserver-prod verdaccio]# cat conf/config.yaml
- storage: /verdaccio/storage/data
-
- plugins: /verdaccio/plugins
-
- web:
-
- title: Verdaccio
-
-
- auth:
- htpasswd:
- file: /verdaccio/storage/htpasswd
- ###这里现在写成不允许新注册用户了,zhgd这个用户是在没有这个配置的情况下先注册的
- max_users: -1
-
- ###配置代理仓库地址
- uplinks:
- npmjs:
- url: https://registry.npmjs.org/
- taobao:
- url: https://registry.npmmirror.com/
-
- packages:
- '@*/*':
- # scoped packages
- access: $authenticated
- publish: $authenticated
- unpublish: $authenticated
- proxy: taobao npmjs
-
- '**':
- # allow all users (including non-authenticated users) to read and
- # publish all packages
- #
- # you can specify usernames/groupnames (depending on your auth plugin)
- # and three keywords: "$all", "$anonymous", "$authenticated"
- access: $authenticated
-
- # allow all known users to publish/publish packages
- # (anyone can register by default, remember?)
- publish: $authenticated
- unpublish: $authenticated
-
- # if package is not available locally, proxy requests to 'npmjs' registry
- proxy: taobao
-
- server:
- keepAliveTimeout: 60
-
- middlewares:
- audit:
- enabled: true
三、本地开发适配
verdaccio仓库目前没有集成LDAP或者gitlab的账号认证系统,故也是所有开发者使用同一个“zhgd”账号的认证方式
###本地开发者如需使用此私库,需要先添加并登陆 [root@8-70-nginx ~]# nrm add zhgd https://zhgd-npm.xingshicloud.com add registry zhgd success [root@8-70-nginx ~]# nrm ls npm ---------- https://registry.npmjs.org/ yarn --------- https://registry.yarnpkg.com/ tencent ------ https://mirrors.cloud.tencent.com/npm/ cnpm --------- https://r.cnpmjs.org/ taobao ------- https://registry.npmmirror.com/ npmMirror ---- https://skimdb.npmjs.com/registry/ pmcnpm ------- http://172.16.9.19:7001/ * pm ----------- http://172.16.9.19:4873/ zhgd --------- https://zhgd-npm.xingshicloud.com/ [root@8-70-nginx ~]# nrm use zhgd Registry has been set to: https://zhgd-npm.xingshicloud.com/ [root@8-70-nginx ~]# npm login Username: zhgd Password: Email: (this IS public) test@163.com Logged in as zhgd on https://zhgd-npm.xingshicloud.com/.
四、npm仓库备份
- ###参照nexus仓库的方式,npm仓库也用rsync脚本进行了备份,完整脚本如下
- [root@zhgd-mysql-cloudcanal-kubepi-prod ~]# crontab -l
- 00 02 * * * /bin/bash /k8slog/10.100.10.206/npm_backup/rsync_npm.sh
- 30 02 * * * /bin/bash /k8slog/10.100.10.206/nexus_backup/rsync_nexus.sh
- [root@zhgd-mysql-cloudcanal-kubepi-prod ~]# cat /k8slog/10.100.10.206/npm_backup/rsync_npm.sh
- #!/bin/bash
- remote_ip=10.100.10.206
- rsync_user=opshaibo
- rsync_dir=/k8slog/$remote_ip/npm_backup/verdaccio
- DATE=`date +%Y%m%d%H%M%S`
- LogFile=/k8slog/$remote_ip/npm_backup/npmbackup.log
-
- echo -e "\033[36m ---------------------开始备份 $DATE -----------------\033[0m">>$LogFile
- #备份命令如下:
- ##--delete删除目标目录比源目录中多的文件
- rsync -avzu --delete --progress rsync://${rsync_user}@${remote_ip}/npmdata ${rsync_dir} --password-file=/etc/rsync_client.pas
-
- if [ $? -eq 0 ];
- then
- echo -e " \033[32m 三局私有npm仓库 rsync备份成功\033[0m">>$LogFile
- #企业微信报警
- curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=126acc51-3bd8-421d-ae1c-19bfdbff70e2' \
- -H 'Content-Type: application/json' \
- -d '
- {
- "msgtype": "markdown",
- "markdown": {
- "content": "<font color=\"warning\">三局私有npm仓库 rsync备份成功</font>"
- }
- }'
- else
- echo -e "\033[31m 三局私有npm仓库 rsync备份失败\033[0m">>$LogFile
- #企业微信报警
- curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=126acc51-3bd8-421d-ae1c-19bfdbff70e2' \
- -H 'Content-Type: application/json' \
- -d '
- {
- "msgtype": "markdown",
- "markdown": {
- "content": "<font color=\"warning\">三局私有npm仓库 rsync备份失败,请快速解决问题!!</font>"
- }
- }'
- fi
-
- now_time=`date +%Y%m%d%H%M%S`
- tar -czPf npm-${now_time}.tar.gz /k8slog/$remote_ip/npm_backup/verdaccio
- mv npm-${now_time}.tar.gz /k8slog/$remote_ip/npm_backup/tar/
- find /k8slog/$remote_ip/npm_backup/tar -name "*.tar.gz" -mtime +7 -exec rm -f {} \;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。