1. 程式人生 > >nginx實現負載均衡例項

nginx實現負載均衡例項

專案規劃圖:
nginx實現負載均衡例項
專案概述:
如上圖所述,部署lnmp環境,實現nginx負載均衡後端的兩個nginx web服務,要求在nginx上搭建wordpress應用。
專案實現

  1. 搭建php-fpm伺服器
    安裝php-fpm包及相關包

    yum install php php-fpm php-mcrypt php-mysql php-mbstring mariadb-server -y

    編輯/etc/php-fpm.d/www.conf的內容
    nginx實現負載均衡例項
    啟動php-fpm服務
    nginx實現負載均衡例項
    安裝mariadb資料庫

    yum install -y mariadb

    編輯/etc/my.conf
    nginx實現負載均衡例項
    啟動mariadb,進入資料庫
    nginx實現負載均衡例項
    在資料庫中建立wordpress的資料庫wpdb
    nginx實現負載均衡例項


    授權wpuser管理賬號
    nginx實現負載均衡例項
    建立資源頁面目錄檔案
    nginx實現負載均衡例項
    下載wordpress應用,並放到資源目錄下
    nginx實現負載均衡例項
    對wordpress做好連結
    nginx實現負載均衡例項
    建立測試頁面
    nginx實現負載均衡例項
    關閉防火牆firewalld和Selinux
    nginx實現負載均衡例項

  2. 搭建nginx-server伺服器
    編輯/etc/nginx/conf.d/vhost檔案
    nginx實現負載均衡例項
    建立頁面資源目錄
    nginx實現負載均衡例項
    下載wordpress應用。並做好連結
    nginx實現負載均衡例項
    啟動服務,並關閉防火牆和Selinux
    nginx實現負載均衡例項
    nginx-server2伺服器的配置同1

3.配置nginx負載均衡伺服器nginx-gw
編輯/etc/ginx/conf.d/vhosts檔案,寫入代理配置
nginx實現負載均衡例項
為驗證負載均衡伺服器是否生效,在nginx-server1與2兩臺伺服器上做測試頁面
nginx-server1:
nginx實現負載均衡例項


nginx-server2:
nginx實現負載均衡例項
啟動負載均衡器nginx服務,並關閉firewall和Selinux
nginx實現負載均衡例項

4.測i是負載均衡和fastcgi代理是否實現
負載均衡測試
nginx實現負載均衡例項
fastcgi代理測試
nginx實現負載均衡例項
由上說明我們的lnmp環境下的負載均衡已實現。

5.安裝wordpress應用
訪問www.lishauyang.com/blog,按照網頁提示進行安裝
填寫資料庫資訊
nginx實現負載均衡例項
安提供的程式碼建立wp-config.php檔案
nginx實現負載均衡例項
nginx實現負載均衡例項
註冊賬號賬號後便建立成功了
nginx實現負載均衡例項