三台主机搭建LNMT

版权声明:未经本人允许严禁转载 https://blog.csdn.net/WanJiaBaoBao/article/details/83477974

搭建环境

安装项目 地址
nginx 192.168.91.132/24
mysql 192.168.91.128/24
tomcat 192.168.91.129/24

搭建环境

  • 配置网络源
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# sed -i 's/$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
  • 下载安装包,并进行解压编译
[root@localhost ~]# tar -xf nginx-1.12.2.tar.gz
[root@localhost ~]# tar -xf apache-tomcat-9.0.12.tar.gz -C /usr/local/

tomcat配置

  • 安装tomcat所需依赖
[root@localhost ~]# yum -y install java-1.8.0-openjdk-devel
[root@localhost ~]# java -version
  • 设置环境变量
[root@localhost ~]# ln -s /usr/local/apache-tomcat-9.0.12 /usr/local/tomcat
[root@localhost ~]# echo "export PATH=/usr/local/tomcat/bin/:$PATH" > /etc/profile.d/tomcat.sh
[root@localhost ~]# source /etc/profile.d/tomcat.sh
  • 启动tomcat
[root@localhost ~]# catalina.sh start
  • 在浏览器中输入Tomcat服务器IP地址+8080端口进行访问默认页面
    在这里插入图片描述

nginx配置

  • 安装编译所需的依赖包
[root@localhost ~]# yum -y install openssl-devel gd-devel
  • 创建用户和组
[root@localhost ~]# groupadd -r nginx
[root@localhost ~]# useradd -r -M -s /sbin/nologin -g nginx nginx
  • 进入解压目录进行编译安装
[root@localhost ~]# cd nginx-1.12.2
[root@localhost nginx-1.12.2]# ./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@localhost nginx-1.12.2]# make -j 2 && make install
  • 编译好后,进入编译后的目录,添加环境变量
[root@localhost nginx-1.12.2]# cd /usr/local/nginx
[root@localhost nginx]# echo "export PATH=/usr/local/nginx/sbin:$PATH" > /etc/profile.d/nginx.sh
[root@localhost nginx]# source /etc/profile.d/nginx.sh
  • 修改/usr/local/nginx/conf/nginx.server配置文件
[root@localhost nginx]# vim conf/nginx.conf
http {
	upstream 192.168.91.129:8080 {
    	server 192.168.91.129:8080;
    }
    server {
		location / {
            root   html;
            index  index.html index.htm;
        }
        location ~ /.*(\.jsp|\.do) {      ##实现动静分离,静态网页用nginx提供,动态网页tomcat提供
        	proxy_pass   http://192.168.91.129:8080;
		}
	}
}
  • 检查配置文件是否生效
[root@localhost nginx]# nginx -t
  • 启动或重启nginx
[root@localhost nginx]# nginx
  • 在浏览器中进行访问(静态)
    在这里插入图片描述
  • 在浏览器中进行访问(动态)
    在这里插入图片描述

mysql配置

注:mysql数据库是运行在tomcat上的程序去连接mysql数据库。

猜你喜欢

转载自blog.csdn.net/WanJiaBaoBao/article/details/83477974
今日推荐