Ching-Chuan Chen's Blogger

Statistics, Machine Learning and Programming

0%

Create A Mirror of NPM Registry

這篇主要是創一個mirror of NPM Registry

首先是安裝CouchDB

1
2
3
4
5
6
7
8
9
10
11
yum install epel-release -y
tee /etc/yum.repos.d/npm_repo.repo << EOF
[apache-couchdb-rpm]
name=bintray--apache-couchdb-rpm
baseurl=http://apache.bintray.com/couchdb-rpm/el7/$basearch/
gpgcheck=0
repo_gpgcheck=0
enabled=1
EOF
yum repolist all
yum install couchdb -y

接下來修改設定,然後啟動

1
2
3
4
5
6
sed -i '/\[httpd\]/a allow_jsonp = true' /opt/couchdb/etc/local.ini
sed -i '/\[httpd\]/a secure_rewrites = false' /opt/couchdb/etc/local.ini
sed -i '/\[httpd\]/a port = 8092' /opt/couchdb/etc/local.ini
sed -i '/\[httpd\]/a bind_address = 0.0.0.0' /opt/couchdb/etc/local.ini
systemctl start couchdb
systemctl enable couchdb

開防火牆

1
2
3
4
5
6
7
8
9
10
11
firewall-cmd --add-port=8092/tcp
firewall-cmd --add-port=8094/tcp
firewall-cmd --reload

# 測試localhost
curl http://localhost:8092/
# {"couchdb":"Welcome","version":"2.1.2","features":["scheduler"],"vendor":{"name":"The Apache Software Foundation"}}

# 測試網路位置
curl http://192.168.1.116:8092/
# {"couchdb":"Welcome","version":"2.1.2","features":["scheduler"],"vendor":{"name":"The Apache Software Foundation"}}

開始mirror:

1
2
3
4
5
6
7
# create user
curl -X PUT http://localhost:8092/_config/admins/jamal -d '"jamal"'
# create database
curl -X PUT http://jamal:jamal@localhost:8092/registry
# replicate
curl -X POST http://localhost:8092/_replicate -d '{"source":"https://skimdb.npmjs.com/registry", "target":{"headers":{"Authorization":"Basic amFtYWw6amFtYWw="},"url":"http://192.168.1.116:8092/registry"}, "continuous":true, "create_target": false, "user_ctx": {"name": "jamal","roles":["_admin","_reader","_writer"]}}' -H "Content-Type: application/json"
# amFtYWw6amFtYWw=為jamal:jamal的decode