Linux deployment project

1. Install JDK

1.1 working directory: / user/local/src

1.2 upload installation package

1.3 extracting files

Command 1: decompression instruction

tar -xvf jdk-8u51-linux-x64.tar.gz

Command 2: delete installation files

 rm -f jdk-8u51-linux-x64.tar.gz

Command 3: modify file name

mv jdk1.8xxxxxx jdk1.8

1.4 JDK environment commissioning

Command 1: vim /etc/profile

#Set jdk environment
export JAVA_HOME=/usr/local/src/jdk1.8
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib

Command 2: make JDK environment variable take effect immediately source /etc/profile
Or restart the Linux system

2. Install MariaDB database

2.1 installation command:

1.[root@localhost src]# Install mariadb database using Yum install mariadb server
2.[root@localhost src]# Empty installed files using Yum clean all if the download fails

2.2 database startup

	1.   Start command    [root@localhost src]# systemctl  start  mariadb
	2.   Restart command    [root@localhost src]# systemctl  restart  mariadb
	3.   close command    [root@localhost src]# systemctl  stop  mariadb
	4.   Set startup from [root@localhost src]# systemctl  enable mariadb 
	5.   Turn off from Startup [root@localhost src]# systemctl  disable mariadb 

2.3 database initialization

Command:

mysql_secure_installation

Set password, all the way y

2.4 test whether the database user name and password are valid

mysql -uroot -p

2.5 Mysql database remote access configuration

Instructions on connecting to the database

explain:
1. If you need to connect to the database remotely, you must go through the firewall
2. If the database is connected remotely, the remote access permission must be enabled for the database, otherwise the connection is refused

2.5. 1. Configure firewall policy

1 . Check firewall status

firewall-cmd --state

2 . Manually turn off the firewall

1. systemctl stop firewalld.service
2. systemctl start firewalld.service

3 . Firewall configuration

1.systemctl disable firewalld.service	#Turn off startup and self startup
2.systemctl enable firewalld.service	#Start up and self start

4 . After configuring the firewall, restart the firewall

firewall-cmd --reload

2.5. 2. Configure Linux database access permissions

1 . Switch database mysql

1. show databases;
2. use mysql;

2 . Change host = "localhost" in the user table to "%"

update user set host="%" where host="localhost";

3 . Refresh database permissions

flush privileges;

2.6 importing database files

1 . Visual client import
2 . Command line import

source /xxx/xxxx/xxxx/jt.sql;

3. tomcat cluster deployment

Description: create the tomcats directory in / usr/local/src /

3.0 port occupancy

1 . Query java process command: jps
2 . Close process item
Note: if you need to close the process in the Linux system, you need the following commands
Syntax: kill PID number
Command:

1. kill PID No. 1 General shutdown process
2. kil -15 PID No. is strictly closed. (The current process is referenced by other processes and cannot be closed)
3. kill -9 PID Forced shutdown process

3.1 preparing 8091 / 8092 servers

Note: after modifying the port number of the background server, install generates 8091 / 8092 and passes it into the Linux system

3.2 foreground start command

Command:

java -jar 8091.jar & java -jar 8092.jar &

After successful startup, enter and jump into the Linux system
Disadvantages: bind to the current Session If the Session is closed, all servers will stop

3.3 background startup project

Command:

nohup java -jar 8091.jar => 8091.log &

Note: background startup can be realized through the above command, and will not be bound to session

3.3. 1 browse files

cat output file all the contents of the file, and the scene with less contents
more output all the contents of the document, page output, space browse to the next screen, q exit
The usage of less is the same as that of more, but it is controlled by PgUp and PgOn keys
tail is used to display the last number of the file, which is frequently used
tail -10 nginx.conf view nginx Last 10 lines of conf
tail –f nginx.conf dynamically view the log to facilitate viewing the newly added information in the log
ctrl+c ends viewing

3.3. 2 script startup

Description: shell script is provided in Linux system Batch processing mechanism can be provided
Note: identifier XXX SH note the header
Edit script:

vim start.sh

Script content

#!/bin/sh
nohup java -jar 8091.jar => 8091.log &
nohup java -jar 8092.jar => 8092.log &

Run script:

 sh start.sh

3.4 editing hosts file

Path: C:\Windows\System32\drivers\etc
Modify file content

127.0.0.1       localhost
::1             localhost
#Picture server domain name
#127.0.0.1       image.jt.com
#Front end domain name address
#127.0.0.1       web.jt.com
#Backend domain name address
#127.0.0.1       manage.jt.com

#Linux system configuration is only valid for native testing
192.168.126.129       image.jt.com
192.168.126.129       web.jt.com
192.168.126.129       manage.jt.com

4. Nginx installation

Software installation

5. Front end project release

5.1 nginx configuration file description

http {
	#Each service is a server
    server {
    	#Default listening port 80
        listen       80;
        #Monitor domain name information
        server_name  localhost;
		#Specific reverse proxy service / default writing method
        location / {
        	#The root agent is a directory
            root   html;
            #Default access page
            index  index.html index.htm;
        }
	}
}

5.2 preparations for front-end release

5.2. 1. Modify the front end main js

set up axios The requested directory is remote linux Domain name
axios.defaults.baseURL = 'http://manage.jt.com/'

5.2. 2. Modify addItem The Vue file points to a remote server

Access remote server
uploadUrl: "http://manage.jt.com/file/upload"

5.3 front end project packaging and uploading

1 . Package the project and generate dist file directory
2. Upload the front-end packaged directory dist to the specified location / usr/local/nginx directory

6. Configure nginx configuration file nginx conf

6.1 configuring front-end reverse proxy

Requirements: through http://web.jt.com:80 Access the static resource file of the front end
To modify the nginx configuration file:

#Configure front-end server
	server {
		listen 80;
		server_name web.jt.com;

		location / {
			root dist;
			index index.html;
		}
	}

6.2 configuring the back-end tomcat cluster

Description: front end project web jt. Com to the back-end server manage jt. Com send request
Problem: there are 8091 / 8092 backend servers that can provide services to users
Difficulty: a server provides data support for users through domain name load balancing

Configure tomcat cluster
#Once requested, access the configured load balancing mechanism of a server cluster
	# Keywords for upstream clusters
	# tomcats is the name of the cluster and can be any xxxx
	# server address of each service
	# By default, the polling policy is adopted to access the server in turn
	upstream tomcats {
		server   192.168.126.129:8091;
		server   192.168.126.129:8092;
	}

	
	#Configure backend servers 8091 / 8092
	#Backend domain name: manage jt. com
	server {
		listen 80;
		server_name manage.jt.com;

		location / {
			#proxy_ The pass reverse proxy server initiates an http request
			proxy_pass  http://tomcats;
		}
	}

6.3 configure the reverse proxy for image upload

Description: user request URL http://image.jt.com Request proxy to / usr/local/src/images

    #Configure picture reverse proxy image jt. com 
	server {
		listen 80;
		server_name image.jt.com;
		location / {
			root /usr/local/src/images;
		} 
	}

6.4 nginx complete configuration file

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    
	#Each service is a server
    server {
    	#Default listening port 80
        listen       80;
        #Monitor domain name information
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
		#Specific reverse proxy service / default writing method
        location / {
        	#The root agent is a directory
            root   html;
            #Default access page
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

	#Configure front-end server
	server {
		listen 80;
		server_name web.jt.com;

		location / {
			root dist;
			index index.html;
		}
	}

	#Once requested, access the configured load balancing mechanism of a server cluster
	# Keywords for upstream clusters
	# tomcats is the name of the cluster and can be any xxxx
	# server address of each service
	# By default, the polling policy is adopted to access the server in turn
	upstream tomcats {
		server   192.168.126.129:8091;
		server   192.168.126.129:8092;
	}

	
	#Configure backend servers 8091 / 8092
	#Backend domain name: manage jt. com
	server {
		listen 80;
		server_name manage.jt.com;

		location / {
			#proxy_ The pass reverse proxy server initiates an http request
			proxy_pass  http://tomcats;
		}
	}

	#Configure picture reverse proxy image jt. com 
	server {
		listen 80;
		server_name image.jt.com;
		location / {
			root /usr/local/src/images;
		} 
	}
	
}

6.5 after the modification is successful, upload nginx Conf file, and then restart the nginx server

Path: nginx/sbin

Command:

./nginx -s reload

7. Normal access after project release

Browser access website: http: / / Web jt. com

Added by windjohn on Fri, 24 Dec 2021 21:19:27 +0200