LNMT架构部署:Linux+Nginx+Mysql+Tomcat
LNMT架构图:
环境描述:
虚拟机准备两台,一台作为nginx服务器+mysql服务器,IP为:192.168.228.23;另外一台作为2台Tomcat服务器,IP为:192.168.228.30。客户端发来请求,首先由nginx处理,如果为静态内容直接由nginx响应,将结果直接给客户端;如果为动态内容,则由nginx反代至后端的Tomcat服务器。
在IP为192.168.228.23的服务器上安装和配置nginx(这里我使用源码安装nginx)
关闭防火墙和selinux
[root@yxr ~]# systemctl stop firewalld
[root@yxr ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@yxr ~]# setenforce 0
[root@yxr ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
创建系统用户nginx
[root@yxr ~]# useradd -r -M -s /sbin/nologin nginx
安装依赖环境
[root@yxr ~]# yum -y install pcre-devel openssl openssl-devel gd-devel
[root@yxr ~]# yum -y groups mark install 'Development Tools'
创建日志存放目录
[root@yxr ~]# mkdir -p /var/log/nginx
[root@yxr ~]# chown -R nginx.nginx /var/log/nginx/
下载nginx
[root@yxr ~]# cd /usr/src/
[root@yxr src]# wget http://nginx.org/download/nginx-1.12.0.tar.gz
编译安装
[root@yxr src]# ls
debug kernels nginx-1.12.0.tar.gz
[root@yxr src]# tar xf nginx-1.12.0.tar.gz
[root@yxr src]# cd nginx-1.12.0/
[root@yxr nginx-1.12.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
[root@yxr nginx-1.12.0]# make -j 2 && make install
nginx安装后配置
配置环境变量
[root@yxr nginx-1.12.0]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@yxr nginx-1.12.0]# . /etc/profile.d/nginx.sh
启动nginx
[root@yxr nginx-1.12.0]# nginx
[root@yxr nginx-1.12.0]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
在IP为192.168.228.23上安装mysql(这里我使用二进制安装)
安装依赖包
[root@yxr ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
创建用户和组
[root@yxr ~]# groupadd -r -g 306 mysql
[root@yxr ~]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql
下载二进制格式的mysql软件包
[root@yxr ~]# cd /usr/src/
[root@yxr src]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
解压软件至/usr/local
[root@yxr src]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@yxr src]# cd /usr/local/
[root@yxr local]# ls
bin games lib libexec nginx share
etc include lib64 mysql-5.7.22-linux-glibc2.