LNMT Architecture Deployment: linux+nginx+mysql+tomcat (load balancing, static and dynamic separation)

Source: Internet
Author: User
Tags mysql download openssl nginx server tomcat server

Environment Description: Virtual machine prepared two, one as Nginx server +mysql server, IP: 192.168.55.129; Another as 2 tomcat servers, IP: 192.168.55.130. The client sends the request, first by nginx processing, if the static content directly from the Nginx response, the result is directly to the client, if it is dynamic content, then from Nginx back to the back end of the Tomcat server.

Install and configure Nginx shutdown firewall and selinux[[email protected on servers with IP 192.168.55.129] ~]# systemctl stop firewalld[[email  Protected] ~]# systemctl disable firewalld[[email protected] ~]# setenforce 0[[email protected] ~]# Sed-ri ' s/ ^ (selinux=). */\1disabled/g '/etc/selinux/config Create System user nginx[[email protected] ~]# useradd-r-m-s/sbin/nologin Nginx installation dependent environment [[email protected] ~]# yum-y install pcre-devel OpenSSL openssl-devel gd-devel[[email protected] ~]# yum-y Groups install ' development Tools ' create log storage directory [[email protected] ~]# mkdir-p/var/log/nginx[[email  Protected] ~]# chown-r nginx.nginx/var/log/nginx/download nginx[[email protected] ~]# cd/usr/src/[[email  Protected] src]# wget http://nginx.org/download/nginx-1.12.0.tar.gz compile and install [[email protected] ~]# cd/usr/src/[[ Email protected] src]# lsdebug kernels nginx-1.14.0.tar.gz[[email protected] src]# tar XF Nginx-1.14.0.tar.gz[[email protected] src]# CD nginx-1.14.0[[email protected] nginx-1.14.0]# lsauto changes.ru Configure HTML man srcchanges conf contrib LICENSE Readme[[ema Il protected] nginx-1.14.0]#./configure >--prefix=/usr/local/nginx >--user=nginx >--group=nginx >- -with-debug >--with-http_ssl_module >--with-http_realip_module >--with-http_image_filter_module >-- With-http_gunzip_module >--with-http_gzip_static_module >--with-http_stub_status_module >--http-log-path =/var/log/nginx/access.log >--error-log-path=/var/log/nginx/error.log[[email protected] nginx-1.12.0]# Make-j 2 && make Installnginx Configure environment variables after installation [[email protected] nginx-1.14.0]# echo ' Export path=/usr/local/ Nginx/sbin: $PATH ' >/etc/profile.d/nginx.sh[[email protected] nginx-1.14.0]#. /etc/profile.d/nginx.sh start nginx[[email protected] nginx-1.14.0]# nginx[[email protected] nginx-1.14.0]#             Ss-antlstate recv-q send-q Local address:port Peer address:port LISTEN 0 *:80 *:* LISTEN 0 128 *:22 *:    * LISTEN 0 127.0.0.1:25 *:* LISTEN 0 128 ::: Max:::* LISTEN 0:: 1:25:::* on IP for Install MySQL install dependency package on 192.168.55.129 [[email protected] ~]# yum-y install ncurses-devel openssl-devel OpenSSL cmake Mariadb-devel creating users and Groups [[email protected] ~]# groupadd-r-G 306 mysql[[email protected] ~]# useradd-m-s/sbin/no login-g 306-u 306 mysql download binary format mysql package [[email protected] ~]# cd/usr/src/[[email protected] src]# wget HTTPS ://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz decompression software to/usr/local[[email  protected] src]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz-c/usr/local/[[email protected] src]# Cd/usr/local/[[email protected] local]# Lsbin inClude libexec sbinetc Lib mysql-5.7.22-linux-glibc2.12-x86_64 sharegames lib64 Nginx src[[email protected] local]# ln-sv mysql-5.7.22-linux-glibc2.12-x86_64/mysql "  MySQL "--" mysql-5.7.22-linux-glibc2.12-x86_64/"[[email protected] local]# ll total dosage 0drwxr-xr-x.  2 root root 6 November 5 bindrwxr-xr-x.  2 root root 6 November 5 etcdrwxr-xr-x.  2 root root 6 November 5 gamesdrwxr-xr-x.  2 root root 6 November 5 includedrwxr-xr-x.  2 root root 6 November 5 libdrwxr-xr-x.  2 root root 6 November 5 lib64drwxr-xr-x.  2 root root 6 November 5 libexeclrwxrwxrwx.  1 root root 36 September 6 17:30 mysql-mysql-5.7.22-linux-glibc2.12-x86_64/drwxr-xr-x. 9 root root 129 September 6 17:28 mysql-5.7.22-linux-glibc2.12-x86_64drwxr-xr-x.  Root root 151 September 6 17:08 nginxdrwxr-xr-x.  2 root root 6 November 5 sbindrwxr-xr-x.  5 root root 49 September 3 23:02 sharedrwxr-xr-x. 2 root root 6 November 5 2016 Src Modify the genus/usr/local/mysql of the directory [[email protected] local]# chown-r mysql.mysql/usr/local/mysql[[email  Protected] local]# ll/usr/local/mysql-dlrwxrwxrwx. 1 MySQL MySQL 36 September 6 17:30/usr/local/mysql-mysql-5.7.22-linux-glibc2.12-x86_64/Add environment variable [[email protected] Loc al]# Echo ' export path=/usr/local/mysql/bin: $PATH ' >/etc/profile.d/mysql.sh[[email protected] local]#. /etc/profile.d/mysql.sh[[email protected] local]# echo $PATH/usr/local/mysql/bin:/usr/local/nginx/sbin:/usr/ Local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin set up data storage directory [[email protected] local]# mkdir/opt/data[[ Email protected] local]# chown-r mysql.mysql/opt/data/[[email protected] local]# ll/opt/total usage 0drwxr-xr-x. 2 MySQL MySQL 6 September 6 17:34 data Initialization database [[email protected] local]#/usr/local/mysql/bin/mysqld--initialize--user=mys QL--datadir=/opt/data/configuration mysql[[email protected] local]# ln-sv/usr/local/mysql/include//usr/local/include/ MySQL "/usr/local/inclUde/mysql "/usr/local/mysql/include/" [[email protected] local]# echo '/usr/local/mysql/lib ' >/etc/ Ld.so.conf.d/mysql.conf[[email protected] local]# ldconfig-v Generate configuration file [[email protected] local]# cat > etc /MY.CNF <<EOF> [mysqld]> basedir =/usr/local/mysql> DataDir =/opt/data> socket =/tmp/mysql.sock> Port = 3306> Pid-file =/opt/data/mysql.pid> user = mysql> skip-name-resolve> EOF Config service startup script [[email  Protected] local]# cp-a/usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld[[email protected] Local ]# Sed-ri ' s#^ (basedir=). *#\1/usr/local/mysql#g '/etc/init.d/mysqld[[email protected] local]# Sed-ri ' s#^ ( datadir=). *#\1/opt/data#g '/etc/init.d/mysqld start mysql[email protected] local]# service mysqld startstarting mysql.logging to '/opt/data/yanyinglai.err ' .... success! [[email protected] local]# Ps-ef | grep mysqlroot 42077 1 0 17:57 pts/2 00:00:00/bin/sh/usr/local/mysql/bin/mysqlD_safe--datadir=/opt/data--pid-file=/opt/data/mysql.pidmysql 42255 42077-17:57 pts/2 00:00:02/usr/local/mysq L/bin/mysqld--basedir=/usr/local/mysql--datadir=/opt/data--plugin-dir=/usr/local/mysql/lib/plugin--user=mysql- -log-error=yanyinglai.err--pid-file=/opt/data/mysql.pid--socket=/tmp/mysql.sock--port=3306root 42291 4672 0 17: PTS/2 00:00:00 grep--color=auto mysql[[email protected] local]# ss-antlstate recv-q Send-Q Local Addres                  S:port Peer address:port LISTEN 0 *:80 *:*                  LISTEN 0 *:22 *:* LISTEN 0 100 127.0.0.1:25       *:* LISTEN 0::: +:::* LISTEN 0 100 :: 1:25:::* LISTEN 0::: 3306:::* Change Password, Login with temporary password [[email protected] local]# mysql-uroot-penter password:mysql> Set password = password (' yanyinglai123 '); Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> Exitbye Configure two Tomcat project deployments on 192.168.55.130 this virtual machine to shut down the firewall and selinux[[email& Nbsp;protected] ~]#[[email protected] ~]# systemctl stop firewalld[[email protected] ~]# systemctl Disable Firewalld[[email protected] ~]# setenforce 0[[email protected] ~]# sed-ri ' s/^ (SELINUX=). */\1disabled/g '/ Etc/selinux/configjava Environment Installation//installation JDK environment [[email protected] ~]# yum-y Install JAVA-1.8.0-OPENJDK Java-1.8.0-openjdk-devel[[email protected] ~]# java-versionopenjdk version "1.8.0_131" OpenJDK Runtime Environment (build 1.8.0_131-b12) OpenJDK 64-bit Server VM (build 25.131-b12, Mixed Mode) Tomcat deployment//Download tomcat[[email  Protected] ~]# cd/usr/src/[[email protected] src]# wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.8 /bin/apache-tomcat-9.0.8.tar.gz//creating a Tomcat storage directory [[email protected] src]# cd/usr/local/[[email protected]local]# mkdir tomacat{1,2}[[email protected] local]# lsbin games lib libexec sbin src tomacat2etc in Clude lib64 Nginx Share tomacat1//to extract tomcat storage directory [[email protected] local]# cd/usr/src/[[email protected] s rc]# lsapache-tomcat-9.0.8.tar.gz Debug kernels[[email protected] src]# tar XF apache-tomcat-9.0.8.tar.gz-c/usr/ Local/tomacat1[[email protected] src]# tar XF apache-tomcat-9.0.8.tar.gz-c/usr/local/tomacat2//Create a soft connection [[email  protected] src]# cd/usr/local/tomacat1[[email protected] tomacat1]# ln-s apache-tomcat-9.0.8/tomcat1[[ Email protected] tomacat1]# ll total dosage 0drwxr-xr-x. 9 root root 160 September 5 21:52 apache-tomcat-9.0.8lrwxrwxrwx. 1 root root 20 September 5 21:54 tomcat1-apache-tomcat-9.0.8/[[email protected] tomacat1]# cd/usr/local/tomacat2[[ Email protected] tomacat2]# ln-s apache-tomcat-9.0.8/tomcat2[[email protected] tomacat2]# ll Total dosage 0drwxr-xr-x. 9 root root 160 September 5 21:52 APACHE-TOMCAT-9.0.8LRWxrwxrwx. 1 root root 20 September 5 21:55 tomcat2-> apache-tomcat-9.0.8/Create test directory and create test file [[email protected] ~]# mkdir/usr/local/t Omacat1/tomcat1/webapps/test[[email protected] ~]# Mkdir/usr/local/tomacat2/tomcat2/webapps/test[[email  protected] ~]# cd/usr/local/tomacat1/tomcat1/webapps/test[[email protected] test]# VI index.jsp[[email  protected] test]# cat index.jsp

Enter 192.168.55.130:8080 access

Enter 192.168.55.130:8080/test access

Second Tomcat
Enter 192.168.55.130:8081 access

//在主机192.168.55.129上搭建nginx使用nginx实现负载均衡,修改配置文件配置nginx实现动静分离[[email protected] ~]# vim /usr/local/nginx/conf/nginx.confupstream web { server 192.168.55.130:8080; server 192.168.55.130:8081;}定义好upstream后,需要在server段内添加如下内容 location ~* \.(do|jsp)$ { proxy_pass http://web; } location ~* tomcat\.(png|css)$ { proxy_pass http://web; } location / { root html; index index.html index.htm; }修改完配置文件检查语法错误,并重启服务[[email protected] ~]# nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[[email protected] ~]# nginx -s reload

Static resource access Nginx
Enter 192.168.56.129 access

Dynamic resource access Tomcat


Refresh

LNMT Architecture Deployment: linux+nginx+mysql+tomcat (load balancing, static and dynamic separation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.