1. 程式人生 > >三臺主機搭建LNMT

三臺主機搭建LNMT

搭建環境

安裝專案 地址
nginx 192.168.91.132/24
mysql 192.168.91.128/24
tomcat 192.168.91.129/24

搭建環境

  • 配置網路源
[[email protected] ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[
[email protected]
~]# sed -i 's/$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
  • 下載安裝包,並進行解壓編譯
[[email protected] ~]# tar -xf nginx-1.12.2.tar.gz
[[email protected] ~]# tar -xf apache-tomcat-9.0.12.tar.gz -C /usr/local/

tomcat配置

  • 安裝tomcat所需依賴
[[email protected] ~]# yum -y install java-1.8.0-openjdk-devel
[
[email protected]
~]# java -version
  • 設定環境變數
[[email protected] ~]# ln -s /usr/local/apache-tomcat-9.0.12 /usr/local/tomcat
[[email protected] ~]# echo "export PATH=/usr/local/tomcat/bin/:$PATH" > /etc/profile.d/tomcat.sh
[[email protected] ~]# source /etc/profile.d/tomcat.sh
  • 啟動tomcat
[[email protected] ~]# catalina.sh start
  • 在瀏覽器中輸入Tomcat伺服器IP地址+8080埠進行訪問預設頁面
    在這裡插入圖片描述

nginx配置

  • 安裝編譯所需的依賴包
[[email protected] ~]# yum -y install openssl-devel gd-devel
  • 建立使用者和組
[[email protected] ~]# groupadd -r nginx
[[email protected] ~]# useradd -r -M -s /sbin/nologin -g nginx nginx
  • 進入解壓目錄進行編譯安裝
[[email protected] ~]# cd nginx-1.12.2
[[email protected] 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
[[email protected] nginx-1.12.2]# make -j 2 && make install
  • 編譯好後,進入編譯後的目錄,新增環境變數
[[email protected] nginx-1.12.2]# cd /usr/local/nginx
[[email protected] nginx]# echo "export PATH=/usr/local/nginx/sbin:$PATH" > /etc/profile.d/nginx.sh
[[email protected] nginx]# source /etc/profile.d/nginx.sh
  • 修改/usr/local/nginx/conf/nginx.server配置檔案
[[email protected] 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;
		}
	}
}
  • 檢查配置檔案是否生效
[[email protected] nginx]# nginx -t
  • 啟動或重啟nginx
[[email protected] nginx]# nginx
  • 在瀏覽器中進行訪問(靜態)
    在這裡插入圖片描述
  • 在瀏覽器中進行訪問(動態)
    在這裡插入圖片描述

mysql配置

注:mysql資料庫是執行在tomcat上的程式去連線mysql資料庫。