Table of contents
Install Nginx reverse proxy server
First, you have to have a cloud server - just buy one
Explain with Centos image, make a note, all resources
install jdk
Install jdk11 here (resource one)
Create a jdk folder in the usr/local directory
Transfer jdk-11.0.14_linux-x64_bin.tar.gz to the jdk directory and extract it to the current directory
tar -zxvf jdk-11.0.14_linux-x64_bin.tar.gz
Configure environment variables
[root@VM-12-8-centos jdk]# vim /etc/profile
。。。。。
if [ -n "${BASH_VERSION-}" ] ; then
if [ -f /etc/bashrc ] ; then
# Bash login shells run only /etc/profile
# Bash non-login shells run only /etc/bashrc
# Check for double sourcing is done in /etc/bashrc.
. /etc/bashrc
fi
fi
//末尾添加
export JAVA_HOME=/usr/local/jdk/jdk-11.0.14
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
"/etc/profile" 89L, 2211C
:wq保存退出后,让其生效
[root@VM-12-8-centos jdk]# source /etc/profile
Install MySQL
Install mysql8.0.29 here (resource 2)
Create the mysql folder in the usr/local directory
Transfer mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz to the mysql folder and decompress it to the current directory
tar xvf mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz
Modify directory name
mv mysql-8.0.29-linux-glibc2.12-x86_64 mysql8.0.29
Create a data folder in the directory
cd mysql8.0.29/
mkdir data
Create a mysql user and authorize it
groupadd mysql
useradd -g mysql mysql
chown -R mysql.mysql /usr/local/mysql/mysql8.0.29
Enter the bin directory and initialize mysql
cd bin/
./mysqld --user=mysql --basedir=/usr/local/mysql/mysql8.0.29 --datadir=/usr/local/mysql/mysql8.0.29/data/ --initialize
The running result is as follows, there is a password in it, save the password:
[root@VM-12-8-centos bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql/mysql8.0.29 --datadir=/usr/local/mysql/mysql8.0.29/data/ --initialize
2022-05-18T03:17:38.004698Z 0 [System] [MY-013169] [Server] /usr/local/mysql/mysql8.0.29/bin/mysqld (mysqld 8.0.29) initializing of server in progress as process 22024
2022-05-18T03:17:38.021352Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-05-18T03:17:39.300600Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-05-18T03:17:41.163199Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: szhdqpAKo1--
Next, edit the configuration file
vi /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql/mysql8.0.29
datadir=/usr/local/mysql/mysql8.0.29/data/
socket=/tmp/mysql.sock
character-set-server=UTF8MB4
After saving and exiting, return to the previous level to the installation directory, and add mysql to the service
cd ..
cp -a ./support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
service mysql start
service mysql status
ln -sf /usr/local/mysql/mysql8.0.29/bin/mysql /usr/bin
log in to mysql
mysql -u root -p
若出现错误
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
输入
sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
Enter the password, the password is the password at the time of initialization
After entering, reset the password, set the password you want, and let it take effect
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
flush privileges;
Set up remote connection
use mysql;
update user set host='%' where user='root';
flush privileges;
Open port 3306, which allows us to connect to
firewall-cmd --add-port=3306/tcp --permanent
If FirewalID is not running, open your firewall
systemctl start firewalld.service
systemctl enable firewalld.service
Open the port for it to take effect
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload
Then, open this port in your security group or firewall
Use database tools, I use DBeaver, test the connection, and it can be used normally after passing. (resource three)
install tomcat server
Install tomcat9.0.63 here (resource 4)
Create a tomcat folder in the usr/local directory
Transfer apache-tomcat-9.0.63.tar.gz to the tomcat folder and decompress it to the current directory
tar -zxvf apache-tomcat-9.0.63.tar.gz
Modify directory name
mv apache-tomcat-9.0.63 tomcat9.0.63
Configure environment variables
vi /etc/profile
在末尾加上
export CATALINA_HOME=/usr/local/tomcat/tomcat9.0.63
export CATALINA_BASE=/usr/local/tomcat/tomcat9.0.63
export PATH=$PATH:$CATALINA_BASE/bin
export PATH CATALINA_BASE
:wq保存推出
let it take effect
source /etc/profile
Go to the tomcat configuration file and modify the tomcat startup port
cd /usr/loacl/tomcat/tomcat9.0.63/conf/
vi server.xml
Temporarily change the port number to 80
Firewall open port 80
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
Go back to the bin directory and start tomcat
./startup.sh
Open the web page at this time, enter ip to see the tomcat welcome interface
After success, it is best to change the port back to 8080
Install Nginx reverse proxy server
Install nginx1.21.6 here (resource five)
Create nginx1.21.6 folder in usr/local directory
Transfer nginx-1.21.6.tar.gz to the nginx1.21.6 folder and extract it to the current directory
tar zxvf nginx-1.21.6.tar.gz
Enter the directory, use compile and install
cd nginx-1.21.6/
./configure --prefix=/usr/local/nginx
After running, you can see the missing dependencies
Common Missing Installs
yum install -y gcc
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
After the installation is complete, re-execute the compilation and installation
Next execute
make
make install
Enter usr/local and you can see that nginx has been installed successfully
Create a service script for nginx
vi /usr/lib/systemd/system/nginx.service
Script content, pay attention to the directory
[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Use a script to start nginx, kill all processes occupying port 80 before starting
lsof -i :80
kill -9 PID
systemctl start nginx
Open the web page at this time, enter the ip to see the nginx welcome interface
After each modification, nginx needs to be reloaded
systemctl reload nginx
Use nginx to proxy tomcat, the tomcat port has been changed to 8080, the following are common configurations
worker_processes 1;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#upstream httpds {
# server 192.168.83.102:80 weight=8 ;
# server 192.168.83.103:80 weight=2 ;
# server 192.168.83.104:80 weight=1 backup;
#}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:8080;
}
location /public {
root html;
index index.html index.htm;
}
location /static {
root html;
index index.html index.htm;
}
location /logo.ico {
root html;
index index.html index.htm;
}
location /pdf {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
After configuration, reload nginx
systemctl reload nginx
Open the page at this time, it has become the tomcat welcome page