1. Configure the SSH Key for Password-free login in Linux
The implementation steps are as follows:
-
To create a key, run the ssh-keygen -t rsa command
-
Run the ssh-copy-id -i ~/. SSH /id_rsa.pub userName@ip command to send the local public key to the remote server (you need to enter the login password of the server for the first time)
Parameter description: userName: indicates the userName for logging in to the remote server. IP: indicates the IP address of the remote server
-
Connect to the remote server and test whether SSH userName@ip is successfully connected
-
If the key has been generated, to connect to another server, repeat step 2 (send the local key to the new server)
Second, write Shell automatic deployment scripts
- Create a publish.sh file in the root directory of your project with the following script:
#! $(date +%Y%m%d-%H% m) # SSH root@ip "CD /usr/local/nginx_proj/8088; mv sdmqs bak_sdmqs/sdmqs_${currentDate};" /dist/* root@ip:/usr/local/nginx_proj/8088/ echo "*************** Deployment successful ***************"Copy the code
-
Add “publish”: “sh./publish.sh” to scripts in package.json
-
Run the script NPM run publish