NPM 사복 구축

7594 단어 Linux 운영
NPM 사복 구축
인터넷 문서에 사용된 NodeJS와 CNPM 버전이 너무 오래되었기 때문에GitHub 홈페이지를 포함하여 다소 문제가 있었고 최종적으로 고생과 정리를 거쳐 이 문서를 형성했다. 문서에서 데이터베이스에 MySQL을 선택하고 Nginx 에이전트를 설치하는 것은 필수적이지 않다.
1. NodeJS 설치
mkdir -p /App/src
cd /App/src
wget https://nodejs.org/dist/v6.4.0/node-v6.4.0-linux-x64.tar.xz
tar Jxf node-v6.4.0-linux-x64.tar.xz
mv node-v6.4.0-linux-x64 /App/node
useradd node
echo 'export PATH=/App/node/bin:$PATH' >> /home/node/.bash_profile

2. CNPM 서버 설치
su - node
git clone https://github.com/cnpm/cnpmjs.org.git
cd cnpmjs.org/
npm install

3. MySQL 데이터베이스 만들기 및 권한 부여
CREATE DATABASE cnpmjs;
GRANT ALL ON cnpmjs.* ON cnpmjs@'127.0.0.1' IDENTIFIED BY 'Password';
FLUSH PRIVILEGES;

4. 데이터베이스 가져오기 데이터
mysql -uroot cnpmjs < docs/db.sql

5. 프로필 수정config/index.js
  • 클러스터 모드 사용 가능
  • enableCluster: true,
  • 포트 설정, registryPort 등록 서비스 포트, webPort 웹 액세스 포트, 기본값
  • registryPort: 7001,
    webPort: 7002,
  • 관리자 설정
  • admin: '[email protected]',
  • 데이터베이스 구성
  • db: 'cnpmjs',
    username: 'cnpmjs',
    password: 'Password',
    dialect: 'mysql',
    host: '127.0.0.1',
    port: 3306,
  • 귀속 감청 주소, 옵션 가능.이 컴퓨터에 접근해야 하지 않으면, 기호 // 를 추가해서 이 줄을 주석합니다.또한 Nginx를 기본 프레임에 리버스 에이전트로 설치할 수 있으므로 이 행을 수정할 필요가 없습니다.
  • bindingHost: '127.0.0.1',
  • 등록 호스트 이름을 IP 주소 또는 도메인 이름으로 변경
  • registryHost: 'npm.songsong.org',
  • 개인 모드를 열고 관리자만 패키지를 발표할 수 있으며 기본 공유 모드는 모든 사용자가 패키지를 발표할 수 있습니다.
  • enablePrivate: true,
  • 개인 패키지에 반드시 있어야 하는 이름 접두사를 발표할 수 있도록 허용
  • scopes: [ '@songsong.org' ],
  • 동기식 소스 설정, 기본값
  • sourceNpmRegistry: 'https://registry.npm.taobao.org',
  • 동기화 모드, none 동기화되지 않고 원본 공유 모듈만 대리한다.exist 이미 존재하는 모듈만 동기화하기;all 모든 모듈을 동기화합니다.
  • syncModel: 'exist', 

    6. CNPM 서비스 시작
    bin/nodejsctl start

    7. Nginx 역방향 에이전트를 추가하고 두 개의 도메인 이름으로 CNPM 웹 서비스와 등록 서비스를 구분하고 설정을 다시 불러옵니다
  • 웹 서비스
  • upstream npm.songsong.org
    {
        server 127.0.0.1:7002 weight=10;
    }
    
    server
    {
        listen       80;
        server_name  npm.songsong.org;
        index        index.html;
    
        location /
        {
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_connect_timeout 60;
            proxy_send_timeout 60;
            proxy_read_timeout 60;
            proxy_pass http://songsong.org;
        }
    }
  • 등록 서비스
  • upstream reg.songsong.org
    {
        server 127.0.0.1:7001 weight=10;
    }
    
    server
    {
        listen       80;
        server_name  reg.songsong.org;
        index        index.html;
    
        location /
        {
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_connect_timeout 60;
            proxy_send_timeout 60;
            proxy_read_timeout 60;
            proxy_pass http://reg.songsong.org;
        }
    }

    8. CNPM 클라이언트 설치
    npm install -g cnpm

    9. CNPM 클라이언트 액세스 사복을 설정합니다. 두 가지 방법이 똑같습니다.
  • 명령줄
  • cnpm set registry http://reg.songsong.org
  • 프로필 수정~/.cnpmrc
  • registry=http://reg.songsong.org

    좋은 웹페이지 즐겨찾기