1. Deploy nexus
This article uses docker to deploy nexus and
install docker
yum install -y docker
Pull nexus mirror
docker pull sonatype/nexus3
Prepare a local mapping directory for localized and continuous data storage. The directory can be set freely according to your needs:
mkdir -p /opt/nexus-data
Locally created directories are given permissions to avoid abnormal service startup (trampled holes)
chmod -R 777 /opt/nexus-data
Start nexus service
docker run -d --name nexus3 \
--restart=always \
-p 8081:8081 \
-p 8082:8082 \
-p 8083:8083 \
-p 8084:8084 \
-p 8085:8085 \
-v /opt/nexus-data:/nexus-data \
sonatype/nexus3
After the service is started, use the deployment machine ip+8081 port to log in to the nexus page. It may take 1-2 minutes to enter the page normally after the deployment is completed.
2. NPM configuration
(1) Log in to the nexus page: ip:8081
(2) The admin password to log in to nexus for the first time: enter the nexus container, and check /nexus-data/admin.password
(3) Enter the password found in step 2 directly Start to modify the password operation
(4) After the password is changed, it is prompted whether to enable anonymous access, and you need to select enable, otherwise the npm local warehouse will fail to access when using it, and you need to log in to report an error.
(5) Open the Settings -> repositories page and click the Create repository button , Create a warehouse
(6) First create an npm (proxy) warehouse, that is, a proxy warehouse.
Fill in the warehouse name and proxy address. The proxy address can use the official npm mirror address https://registry.npmjs.org. You
only need the above 2 items to click The Creaete repository at the bottom is created
(7) Create an npm (hosted) warehouse, that is, a private server warehouse.
Enter the warehouse name and click on the Creaete repository at the bottom to complete the creation.
(8) Create npm(group) warehouse, npm group
When we install npm package from npm(group) this warehouse, we will first check whether the warehouse exists, if it does not exist, we will use the proxy warehouse to download to the official warehouse to
create npm (group) You need to fill in the warehouse name, and then set npm(proxy) and proxy(hosted) as members. Click on the Creaete repository at the bottom to complete the creation
Three, use npm
1. When executing npm install on another machine, add –registry to specify the private npm warehouse address. The following code example is my local virtual machine test ip, which needs to be changed according to the actual deployment ip
npm install --registry=http://172.16.27.109:8081/repository/npm-group/
2. If the following error is reported
because nexus does not allow anonymous access, you need to set it to allow anonymous access.
Open the settings page Security -> Anonymous, check Allow anonymous users to access the server, and click save.
3. If you think it is troublesome to specify --registry every time, we can use it on the machine that needs to install npm dependency
npm config set registry http://172.16.27.109:8081/repository/npm-group/
Change the default mirror of npm to the mirror of our private server, so that there is no need to specify the mirror source every time. Of course, the ip, port, and group name inside need to be modified according to the actual situation.
Finish Sahua❀❀❀If there is
an error, please comment and correct it~