With major project functions developed, document the deployment of the server.
Connect to the server through power Shell
ssh root@ip -p 22
root@ip's password:
Copy the code
Enter the password after password
If the server has been reset, type the following command to clear the cache
ssh-keygen -R ip
Copy the code
Update the CentOS yum source
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
yum -y update
Copy the code
3. Install the nodejs
Node.js v12.x(the latest version is not installed because of compatibility issues, which will make the code not run)
# As root
curl -fsSL https://rpm.nodesource.com/setup_12.x | bash -
bash -
# No root privileges
curl -fsSL https://rpm.nodesource.com/setup_12.x | sudo bash -
yum install -y nodejs
Copy the code
Check the version
node -v
Copy the code
4. Install the mongo
1. Create warehouse file:
Vi/etc/yum. Repos. D/mongo - org - 3.4. Repo
Then copy the following configuration, save and exit
[mongo - org - 3.4]
name=MongoDB Repository
Baseurl = HTTPS: ` ` / / repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
Gpgkey = HTTPS: ` ` / / www.mongodb.org/static/pgp/server-3.4.asc
2. Yum install
yum install -y mongodb-org
Copy the code
If you do not have permission, add sudo
Modify the configuration file after installation:
vi /etc/mongod.conf
Copy the code
Modify the bind_IP of the configuration file. The default is 127.0.0.1 for local connections only. So after the installation is complete, you must change this to 0.0.0.0, otherwise you will not be able to connect through another machine!
3, Start, stop, restart
By default, MongoDB stores data files in /var/lib/mongo and log files in /var/log/mongodb. If you want to change, you can specify alternate log and data file directories in the /etc/mongod.conf configuration.
Start command:
service mongod start
Copy the code
Stop command:
service mongod stop
Copy the code
Restart command:
service mongod restart
Copy the code
You can check whether mongoDB is started successfully by viewing the log file:
cat /``var``/log/mongodb/mongod.log
The log file should have the following statement
[initandlisten] waiting for connections on port <port>
Copy the code
Is the mongodb running port
5. Back up and install mongodb
The mongodump command script syntax is as follows:
>mongodump -h dbhost -d dbname -o dbdirectory
Copy the code
-
– h:
Address of the server where MongDB resides, for example, 127.0.0.1. You can also specify the port number 127.0.0.1:27017
-
– d:
Database instance to be backed up, for example, test
-
– o:
Location for storing backup data. For example: C :\data\dump. This folder must be created in advance. After the backup is complete, the system automatically creates a test folder in the dump folder. This folder holds the backup data for the database instance.
Mongorestore command script syntax example:
Mongorestore-host 0.0.0.0:27017 -d echarts /home/meng/echarts only valid codeCopy the code
6. Install nginx
yum -y install nginx
nginx -v
Copy the code
Start the
service nginx start
Copy the code
Check whether the startup is successful
ps -ef | grep nginx
Copy the code
Log update check and restart
nginx -t
nginx -s reload
Copy the code
7. Nodejs depends on the installation
Use Filezilla to import the nodeJS code file
Commands for replacing an image
npm install -g cnpm --registry=https://registry.npm.taobao.org
Copy the code
Install global dependencies
cnpm i -g yarn pm2 nodemon
yarn config set registry https://registry.npm.taobao.org/
yarn install
Copy the code
Go to the Node code directory, install the partial dependencies, and start PM2
cnpm install
pm2 start app.js
Copy the code
check
pm2 list
Copy the code
Check whether the server code works properly
curl http://www.localhost:8888/ocean
Copy the code
8. Whole code problem handling and related configuration
The code deployment area has its own personal issues, so HERE are a few of the main issues I encountered and solved:
- Cross-domain problem
Was at the time of the machine test cross-domain deployment is data problem has been solved, but don’t know why I always can’t get the data uploaded to the server, the tortuous, I changed the code logic, to choose the data on the server exposed through public IP, in to get the data from the exposure of the IP, this is called perfect solve the problem. Nginx configuration is as follows:
- Static Resource import
I put the static resources (china.json) in the front-end folder, using the absolute path import method at first
http://localhost:8999/static/map/china.json
Copy the code
When the local test is easy to report errors, can not get data; Put on the server a success also did not have, later search for information to obtain the file way to change the relative path to solve.
import Map from '.. /.. /public/static/map/china.json'Copy the code
- Upload back-end files
Upload all files except node_modules and then go to the folder to install dependencies
cnpm install
Copy the code
Did you get any errors
- Front-end file upload
Change the base path to the server IP address
Axios. Defaults. BaseURL = 'http://42.193.131.94/api/'Copy the code
The index.js module under the router finds the following module and makes the following changes
Const router = new VueRouter({// mode: 'hash', routes})Copy the code
The basic configuration of vue.config.js is shown in the figure below
Module. exports = {devServer: {port: 8999, // config port number open: true}, publicPath: './', productionSourceMap: false}Copy the code
Then go to the front-end folder and type the following command to pack:
npm run build
Copy the code
The dist folder is generated and the contents are uploaded to the server
- Configure nginx
I only changed the contents of the server as follows: