[关闭]
@bornkiller 2017-10-31T15:40:58.000000Z 字数 3028 阅读 1628

NPM 私服搭建

前端实践


特别说明

数据库

配置 yum

  1. # 推荐命名为 `MariaDB.repo`
  2. # MariaDB 10.2 CentOS repository list - created 2017-10-20 02:54 UTC
  3. # http://downloads.mariadb.org/mariadb/repositories/
  4. [mariadb]
  5. name = MariaDB
  6. baseurl = http://yum.mariadb.org/10.2/centos7-amd64
  7. gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
  8. gpgcheck=1

安装数据库

  1. # 快速安装
  2. yum install -y MariaDB-server MariaDB-client;

配置数据库

同步过程中,遇到 emoji 等特殊字符,会导致无法入库,造成同步失败,问题为数据库编码.

修改配置文件:

  1. [client]
  2. default-character-set = utf8mb4
  3. [mysql]
  4. default-character-set = utf8mb4
  5. [mysqld]
  6. character-set-client-handshake = FALSE
  7. character-set-server = utf8mb4
  8. collation-server = utf8mb4_unicode_ci
  1. # 启动数据库
  2. systemctl start mariadb;
  3. # 设置开机启动
  4. systemctl enable mariadb;
  1. # 设置密码
  2. SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('123456');
  3. SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
  1. # 创建数据库
  2. create database cnpmjs CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

cnpmjs.org 提供初始化脚本 docs/db.sql,需要调整编码声明:

  1. ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='*******';

可用版本详见 https://gist.github.com/bornkiller/739b60a5eef8d52f52e70b7228297a12,执行内容即可完成库表初始化。

配置 cnpmjs.org

配置 cnpmjs.org 必要信息:

  1. {
  2. /**
  3. * Cluster mode
  4. */
  5. enableCluster: true,
  6. // default system admins
  7. admins: {
  8. // name: email
  9. },
  10. database: {
  11. db: 'cnpmjs',
  12. username: 'root',
  13. password: '123456',
  14. // the sql dialect of the database
  15. // - currently supported: 'mysql', 'sqlite', 'postgres', 'mariadb'
  16. dialect: 'mariadb',
  17. dialectOptions: {
  18. charset: 'utf8mb4',
  19. collate: 'utf8mb4_unicode_ci',
  20. socketPath: '/var/lib/mysql/mysql.sock' // 指定套接字文件路径
  21. },
  22. // custom host; default: 127.0.0.1
  23. host: '127.0.0.1'
  24. },
  25. // registry url name
  26. registryHost: 'rn.juxinli.com',
  27. // enable private mode or not
  28. // private mode: only admins can publish, other users just can sync package from source npm
  29. // public mode: all users can publish
  30. enablePrivate: true,
  31. // registry scopes, if don't set, means do not support scopes
  32. scopes: [ '@universal', '@overseas', '@its', '@coco'],
  33. // sync mode select
  34. // none: do not sync any module, proxy all public modules from sourceNpmRegistry
  35. // exist: only sync exist modules
  36. // all: sync all modules
  37. syncModel: 'exist', // 'none', 'all', 'exist'
  38. }

开启服务

私服启动后,默认为绑定本机,需要安装 nginx 用以代理,对外提供服务:

配置 yum

  1. # Nginx.repo
  2. [nginx]
  3. name=nginx repo
  4. baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
  5. gpgcheck=0
  6. enabled=1

安装 Nginx

  1. # 快速安装
  2. yum install -y nginx;

配置 Nginx

  1. server
  2. {
  3. listen 80;
  4. server_name rnw.juxinli.com;
  5. index index.html;
  6. location /
  7. {
  8. proxy_redirect off;
  9. proxy_set_header Host $host;
  10. proxy_set_header X-Real-IP $remote_addr;
  11. proxy_set_header REMOTE-HOST $remote_addr;
  12. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  13. proxy_connect_timeout 60;
  14. proxy_send_timeout 60;
  15. proxy_read_timeout 60;
  16. proxy_pass http://127.0.0.1:7002;
  17. }
  18. }
  19. server
  20. {
  21. listen 80;
  22. server_name rn.juxinli.com;
  23. index index.html;
  24. location /
  25. {
  26. proxy_redirect off;
  27. proxy_set_header Host $host;
  28. proxy_set_header X-Real-IP $remote_addr;
  29. proxy_set_header REMOTE-HOST $remote_addr;
  30. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  31. proxy_connect_timeout 60;
  32. proxy_send_timeout 60;
  33. proxy_read_timeout 60;
  34. proxy_pass http://127.0.0.1:7001;
  35. }
  36. }

配置防火墙

启动 nginx 之后,系统防火墙配置可能会导致无法对外服务,配置如下:

  1. firewall-cmd --get-active-zones;
  2. firewall-cmd --zone=public --add-port=80/tcp --permanent;
  3. firewall-cmd --reload;

私服接入

Contact

Email: hjj491229492@hotmail.com

qrcode_for_gh_d8efb59259e2_344.jpg-8.7kB

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注