使用Sinopia部署私有npm仓库
[root@localhost ~]# hostnamectl set-hostname --static npm-server
[root@npm-server ~]# curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash [root@npm-server ~]# yum install -y nodejs # 先要有nodejs [root@npm-server ~]# node -v # 查看nodejs的版本 v10.21.0 [root@npm-server ~]# npm -v 6.14.4
# 将node源改为淘宝源,有两种方式查看是否修改成功 [root@npm-server ~]# npm config set registry https://registry.npm.taobao.org # 永久修改 [root@npm-server ~]# npm info express express@4.17.1 | MIT | deps: 30 | versions: 264 Fast, unopinionated, minimalist web framework http://expressjs.com/ dist .tarball: https://registry.npm.taobao.org/express/download/express-4.17.1.tgz .shasum: 4491fc38605cf51f8629d39c2b5d026f98a4c134 dependencies: accepts: ~1.3.7 depd: ~1.1.2 on-finished: ~2.3.0 array-flatten: 1.1.1 encodeurl: ~1.0.2 parseurl: ~1.3.3 body-parser: 1.19.0 escape-html: ~1.0.3 path-to-regexp: 0.1.7 content-disposition: 0.5.3 etag: ~1.8.1 proxy-addr: ~2.0.5 content-type: ~1.0.4 finalhandler: ~1.1.2 qs: 6.7.0 cookie-signature: 1.0.6 fresh: 0.5.2 range-parser: ~1.2.1 cookie: 0.4.0 merge-descriptors: 1.0.1 safe-buffer: 5.1.2 debug: 2.6.9 methods: ~1.1.2 send: 0.17.1 (...and 6 more.) maintainers: - jasnell <jasnell@gmail.com> - mikeal <mikeal.rogers@gmail.com> dist-tags: latest: 4.17.1 next: 5.0.0-alpha.8 published a year ago by dougwilson <doug@somethingdoug.com> [root@npm-server ~]# npm config get registry https://registry.npm.taobao.org/ ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' # 如果想还原npm仓库地址的话,只需要在把地址配置成npm镜像就可以了 [root@npm-server ~]# npm config set registry https://registry.npmjs.org/
# 安装sinopia [root@npm-server ~]# npm install -g sinopia # -g表示全局安装,没有-g需要在当前目录下安装 [root@npm-server ~]# sinopia # 看到下面两行,表示启动成功了 Sinopia doesn't need superuser privileges. Don't run it under root. warn --- config file - /root/.config/sinopia/config.yaml warn --- http address - http://localhost:4873/ [root@npm-server ~]# cd .config/sinopia/ [root@npm-server sinopia]# ls config.yaml storage [root@npm-server sinopia]# cp config.yaml{,.bak} [root@npm-server sinopia]# vim config.yaml listen: 0.0.0.0:4873 # 最后一行添加这一句,不然只能本机访问
# sinopia配置文件详解 # # This is the default config file. It allows all users to do anything, # so don't use it on production systems. # # Look here for more config file examples: # https://github.com/rlidwka/sinopia/tree/master/conf # # path to a directory with all packages storage: ./storage # npm包存放的路径 auth: htpasswd: file: ./htpasswd # 保存用户的账号密码等信息 # Maximum amount of users allowed to register, defaults to "+inf". # You can set this to -1 to disable registration. max_users: -1 # 默认为1000,改为-1,禁止注册 # a list of other known repositories we can talk to uplinks: npmjs: url: http://registry.npm.taobao.org/ # 默认为npm的官网,由于国情,修改 url 让sinopia使用 淘宝的npm镜像地址 packages: # 配置权限管理 '@*/*': # scoped packages access: $all # 表示哪一类用户可以对匹配的项目进行安装 【$all 表示所有人都可以执行对应的操作,$authenticated 表示只有通过验证的人可以执行对应操作,$anonymous 表示只有匿名者可以进行对应操作(通常无用)】 publish: $authenticated # 表示哪一类用户可以对匹配的项目进行发布 '*': # 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: $all # 表示哪一类用户可以对匹配的项目进行安装 # allow all known users to publish packages # (anyone can register by default, remember?) publish: $authenticated # 表示哪一类用户可以对匹配的项目进行发布 # if package is not available locally, proxy requests to 'npmjs' registry proxy: npmjs # 如其名,这里的值是对应于 uplinks # log settings logs: - {type: stdout, format: pretty, level: http} #- {type: file, path: sinopia.log, level: info} # you can specify listen address (or simply a port) listen: 0.0.0.0:4873 # 默认没有,只能在本机访问,添加后可以通过外网访问