Table of contents
Second, the installation of centos7
4. Front-end project deployment
1. Make sure the foreground project is available
2. Package the foreground project npm run build
4. Complete the configuration of default.conf for Nginx dynamic and static separation
5. Upload the dist project of the front-end component number to the cloud server /usr/local/...
1. VMware
Centos7 installation
1. Open the installation package:
Click Next:
. . . . . .
(Just go to the next step here, choose a hard disk with enough space for the installation location , and finally click on the license )
Due to copyright issues, a license is required to privately message the blogger
Second, the installation of centos7
Create a new virtual machine:
Select Custom --> Next
Default --> Next
Choose the third one: install later ——> next step
Operating system selection:
Linux (L)
version selection: CentOS 7 64 bits——next step
Choose your own name, choose a non-Chinese directory for the location——next step
Processor: Default; --> Next
Virtual machine memory:
allocate according to your own computer configuration (recommended 2GB)
next step x 7 - complete
Click to edit the virtual machine settings (the reason for choosing to install later: it is here that you can adjust the cpu and memory)
to use the image file
Turn on the virtual machine
Click to complete the installation, select the first one and press Enter
Scroll down to choose where to install
After entering, directly default and complete:
After coming out:
Set your own password and account here
When you're done, just wait until it's loaded
After the virtual machine is installed, you need to set dhcp to 63 days, which means that the virtual machine can be rented for 63 days
Then reboot:
centos installation is complete
1. Check the ip address ifconfig
2. Modify the network settings vi /etc/sysconfig/network-scripts/ifcfg-ens33 Note
: tab automatically completes the Linux command
3. Restart the network card service service network restart
ifconfig display ip
details please see: y1-linux-environment construction (in courseware)
change source
Command:
cd switch directory
ll view all files and folders in the current file directory
vi edit file
cat view the content inside the file
mv cut
cp copy
ifconfig search ens33 port number
Open the MobaXterm software ,
add a new session (session)
and click SSH - enter the Id you generated in the CentOS (virtual machine) in the Remote host:
Just click ok after inputting,
and then enter your account and password:
For example: root 123456
After successful login, click yes (whether to save the password)
and enter ll to view the number of files
Back up the EPEL source that comes with linux
and enter the /etc/yum.repos.d directory——cd into it and
enter cp /etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base .repo.bakpwd: View the file path
yum install -y wget Download the wget plug-in
and then download the Ali source
wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
and then clean the cache
yum clean all
and then in Regenerate the cache
yum makecache
download plugin tree
yum install -y tree
test:
Goal:
J2EE project deployment and release
Command:
mkdir create directory
tar -zxvf .....zip decompression command
Create a directory:
Use tar -zxvf to decompress the compressed package
Download vim command
yum -y install vim-enhanced
: q! - Exit without saving
: wq - Exit and save
Configure environment variables:
Enter: vim /etc/profile
to find the bottom and press i to edit
#java environment
export JAVA_HOME=/javayuyan/software/jdk1.8.0_151(/javaxl/jdk1.8.0_151(jdk解压路径))
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
Then enter: wq to exit and save,
set environment variables to take effect
, enter source /etc/profile
and enter java -version
Start tomcat
and go to the bin directory
cd apache-tomcat-8.5.20/bin
start tomcat
Download the monitoring command: (check if the current computer port is used)
yum install -y lsof
for monitoring port number:
lsof -i:8080
Firewall setting
open port:
firewall-cmd --zone=public --add-port=8080/ tcp --permanent
update firewall rules:
firewall-cmd --reload
firewall list:
firewall-cmd --zone=public --list-ports
(Replenish)
Firewall status:
systemctl status firewalld
enable firewall
systemctl status firewalld
disable firewall
systemctl stop firewalld.service
systemctl disable firewalld.service
ifconfig View port number
Copy into URL:
3. Mysql installation
1. Uninstall mariadb, otherwise there will be conflicts when installing MySql (check first and then delete and then check)
Check the database where the current virtual computer is located:
rpm -qa|grep mariadb
and then delete:
(mariadb.... refers to the one just found line database code)
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
and then check again to confirm whether the deletion is successful:
2. Download the MySQL installation package online (you can also download and upload it in advance)
Online download command: (estimated about half an hour)
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar
3. Unzip the MySQL installation package to the specified directory
Create a folder about mysql:
mkdir mysql-5.7
Unzip:
tar -xvf mysql-5.7.35-1.el7.x86_64.rpm-bundle.tar -C mysql-5.7
4 .Start the installation, -ivh where i means to install, v means to display the installation process, h means to display the progress
cd mysql-5.7
The name of the database in each virtual machine will be different,
the same is
the version after mysql-community-common-XXXXXXX It needs to be entered against the sql version in the virtual machine
rpm -ivh mysql-community-common-5.7.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.35-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.35-1.el7.x86_64.rpm
5. Start the MySQL service
systemctl start mysqld
and check the status of mysql after startup:
systemctl status mysqld
6. Log in to mysql to change the password
Check the original mysql password
grep "password" /var/log/mysqld.log
Start changing the password:
mysql -uroot -p
Copy and paste the queried password into it:
Set password level:
set global validate_password_policy=0;
set password length:
set global validate_password_length=4;
update password
set password = password("123456");
refresh:
FLUSH PRIVILEGES;
then exit to exit;
finally we try to log in again again:
But now we still can't connect to the database.
The database is not authorized, allowing remote login to mysql as root.
GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
After inputting, the following statement is required to make the modification take effect
FLUSH PRIVILEGES;
After modification, you can test whether you can connect to the database remotely
Background project deployment:
Check whether the background can be started successfully.
After the startup is successful, it will be packaged into a war package
<packaging>war</packaging>
and then imported into the tomcat path.
Then add related table data in the cloud database
Then restart tomcat
Goal: Deploy front-end project
Nginx introduction
1. Load balancing: flow sharing (sharing server pressure)
2. Dynamic and static separation: determine whether dynamic requests or static requests, and selectively access designated servers
3. Reverse proxy: determine the problem of accessing the internal network from the external network
1. Nginx installation
Add the official yum source provided by nginx (requires networking and takes a long time)
rpm -Uvh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.14.2-1.el7_4. ngx.x86_64.rpm
Use yum to install nginx
yum install nginx
to view nginx version
rpm -qa | grep nginx
default port is: 80
80 port can be hidden, such as Baidu;
then start and set boot start
systemctl start nginx.service
systemctl enable nginx.service
Use lsof -i:80 to view
Set the firewall to open port 80
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload && firewall-cmd --list-port
Prepare two Tomcats,
enter and download to the tomcat-related folder
cd /javayuyan/software
cp -r apache-tomcat-8.5.20/ apache-tomcat-8.5.20_8081/
enter the config directory layer in tomcat and copy server.xml Modify the port number in
- HTTP port, default 8080, change to 8081 as follows
- Remote stop service port, default 8005, change to 8006 as follows
- AJP port, default 8009, change as follows, 8010
Then save the startup project
Open port 8081 on the firewall:
firewall-cmd --zone=public --add-port=8081/tcp --permanent
firewall-cmd --reload && firewall-cmd --list-port
will be in the root of webapps Change the content of <body></body> in index.jsp to 8080 and 8081
View the hierarchical structure in nginx:
systemctl status nginx
Go to the etc/nginx directory and change the content in nginx.conf
Copy the following into the red box above
upstream tomcat_list { #服务器集群名字
server 127.0.0.1:8080 weight=1; #服务器1 weight是权重的意思,权重越大,分配的概率越大。
server 127.0.0.1:8081 weight=1; #服务器2 weight是权重的意思,权重越大,分配的概率越大
}
Then click on the conf.d folder to modify it in default.conf
location / {
#root /usr/share/nginx/html;
#proxy_pass http://172.17.0.3:8080;
proxy_pass http://tomcat_list;
index index.html index.htm;
Restart after saving:
systemctl restart nginx
At this time, we have a permission problem:
Check the log:
cat /var/log/nginx/error.log
Solution: Execute the following command
setsebool -P httpd_can_network_connect 1
If we have a server crash, but we can still run normally
Then run:
It can still run successfully: because we have set up multiple Tomcat
Ensure the high availability of our project
4. Front-end project deployment
1. Make sure the foreground project is available
Find the t_spa project we wrote before for integration
Go to the current directory cmd to start:
Effect:
2. Package the foreground project npm run build
Note: The tool I use is HBuilder X, and when hbuilderX packs the vue project, there will be a white screen problem
Solution:
1. Find the index.js in the config in the vue project
and change the assetsPublicPath: '/'
to assetsPublicPath:' ./'This adds a dot before /
2. Find the generateLoaders function method in utils.js in the build
and add a line in if (options.extract)
// to solve the icon path loading error
publicPath:'../../'
Guide package: npm run build
3. Do ip/host host mapping
Map the virtual machine ip to the domain name www.yuyan.com
4. Complete the configuration of default.conf for Nginx dynamic and static separation
Definition rule: URL conforms to the xxx standard and uses dynamic requests, and does not conform to static requests
Add the mapping relationship in C:\Windows\System32\drivers\etc\hosts
(if you need permission, you can first drag the file to the desktop, open it for modification, and then drag it back)
192.168.195.139 www.yuyan.com
after modification Then open default.conf in the /etc/nginx/conf.d/ file
proxy configuration
location / {
#该句代码是为解决history路由不能跳转的问题,在vue-router官网有介绍
try_files $uri $uri/ /index.html;
}
location ^~/api/ {
#^~/api/表示匹配前缀是api的请求,proxy_pass的结尾有/, 则会把/api/*后面的路径直接拼接到后面,即移除api
proxy_pass http://tomcat_list/;
}
After the modification,
we will repackage the front-end project: npm run build (with Nginx dynamic and static separation)
Note: modify the action.js address, add the path configuration of the api, and
now delete the packaged file
After packaging, start Nginx to test
systemctl restart nginx
front-end access address
5. Upload the dist project of the front-end component number to the cloud server /usr/local/...
Find the /usr/local directory and copy the package from the front end into it
Then modify the default.conf file port:
the location is still the one above
listen 80; #监听80端口,可以改成其他端口
#server_name localhost; #当前服务的域名
server_name www.yuyan.com; #当前服务的域名(虚拟域名也可以)
root /usr/local/mypro/dist; #将要访问的网站的根目录,nginx节点会自动继承父节点的配置;这里放到/usr/local/*,放到其他路径下会有权限相关问题;必要的时候配置Nginx.conf的user为root
Restart the Nginx service to make the configuration take effect
systemctl restart nginx
(There are still some parts that I forgot to back up later...)
What I share today is mainly the knowledge of implementation. There are many contents in it. If you don’t understand virtual machines, you can read it slowly. If you have any questions or don’t understand, you can privately message the blogger. help.