Linux Web server deployment LNMT (Linux + Ngnix + MySQL / Mariadb + Tomcat)
OS: Kylin server operating system (similar manner Cenos)
table of Contents
2.tomcat application deployment
4. The same project started two tomcat
The load balancing configuration Nginx
6.MySQL / Mariadb installation
1. Install tomcat
Official website to download
Download tomcat 8
Select Distributions- Binary> Core-> tar.gz
the Apache-Tomcat-8.5.53.tar.gz
After the download is good
root$ cp apache-tomcat-8.5.53.tar.gz /opt/
root$ cd /opt
root$ tar xf apache-tomcat-8.5.53.tar.gz
root$ rm apache-tomcat-8.5.53.tar.gz
root$ cd apache-tomcat-8.5.53/bin
root$ ./catalina.sh run
After running a successful start to see the following information Description
23-Mar-2020 17:27:43.021 信息 [main] org.apache.catalina.startup.Catalina.start
Server startup in 3181 ms
2.tomcat application deployment
root$ cd /opt/apache-tomcat-8.5.53/webapps/
root$ cp docs/appdev/sample/sample.war ./
root$ cd ../bin/
root$ ./shutdown.sh
root$ ./catalina.sh run
// server ip address:: We can go to http: 8080 visit, the remote can be http: // localhost 8080
If the remote access error, it may be a firewall, the firewall access to port 8080 open
firewall-cmd --zone=public --add-port=8080/tcp --permanent
systemctl restart firewalld
3. Install Nginx
yum install nginx -y
Before starting nginx, apache must ensure that the service is turned off, otherwise nginx will fail to start, because apache and nginx default port 80
systemctl stop httpd
systemctl start ngnix
We can at http: // localhost access
Nginx configuration to achieve reverse proxy and load balancing
4. The same project started two tomcat
Then copy tomcat, and modify the port number, etc., to boot
cd /opt
cp -r apache-tomcat-8.5.53 apache-tomcat-8.5.53-copy2
Modify apache-tomcat-8.5.53-copy2 / conf / server.xml, modify the port number three
The Foreign port to 8081, and to ensure the external port apache-tomcat-8.5.53 does not conflict,
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8081
-->
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
The 8005 change 8006
<Server port="8006" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
The 8009 change 8010
<!-- Define an AJP 1.3 Connector on port 8010 -->
<!--
<Connector protocol="AJP/1.3"
address="::1"
port="8010"
redirectPort="8443" />
-->
The load balancing configuration Nginx
vi /etc/nginx/nginx.conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;events {
worker_connections 1024;
}http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;include /etc/nginx/mime.types;
default_type application/octet-stream;# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
upstream tomcat_server{
#ip_hash;
server 127.0.0.1:8080 weight=1;
server 127.0.0.1:8081 weight=1;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;location / {
}error_page 404 /404.html;
location = /40x.html {
}error_page 500 502 503 504 /50x.html;
location = /50x.html {
}location ~*/sample{
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://tomcat_server;
}}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }}
Add the red part of the configuration file
systemctl restart nginx
To see by looking at the log browser requests a number of times
tail -f /opt/apache-tomcat-8.5.53/logs/localhost_access_log.2020-03-23.txt
6.MySQL / Mariadb installation
See https://blog.csdn.net/rong11417/article/details/105044750