nginx+keepalived安裝經歷
一、安裝Nginx
1、前期準備的依賴素材(安裝時有可能有許可權報錯,建議用root使用者操作),安裝順序:
- SSL功能需要openssl庫,下載地址:http://www.openssl.org/
- gzip模組需要zlib庫,下載地址:http://www.zlib.net/
- rewrite模組需要pcre庫,下載地址:http://www.pcre.org/
- Nginx的安裝包:下載地址為:http://nginx.org/en/download.html
2、安裝openssl庫
安裝思路:
解壓:tar –zxvf …/openssl-1.1.1b.tar.gz
跳轉到解壓後文件夾: cd openssl-1.1.1b/
編譯檢查,生成makefile檔案: ./configure
執行編譯與安裝命令: make && make install
如果發生報錯:
則在安裝目錄下執行:
cp libssl.so.1.1 /usr/lib64
Cp libcrypto.so.1.1 /usr/lib64.
3、安裝gzip模組需要zlib庫的安裝方法 安裝思路與和openssl安裝的方法一模一樣
安裝思路:
解壓:tar –zxvf …/zlib-1.2.11.tar.gz
跳轉到解壓後文件夾: cd zlib-1.2.11/
編譯檢查,生成makefile檔案: ./configure
執行編譯與安裝命令: make && make install
4、安裝 rewrite模組需要pcre庫的安裝方法和openssl安裝的方法一模一樣.
安裝思路:
- 解壓:tar –zxvf …/pcre-8.42.tar.gz
- 跳轉到解壓後文件夾: cd pcre-8.42/
- 編譯檢查,生成makefile檔案: ./configure
- 執行編譯與安裝命令: make && make install
5、安裝 Nginx
安裝思路:
解壓:tar –zxvf …/nginx-1.15.12.tar.gz
跳轉到解壓後文件夾: cd nginx-1.15.12/
編譯檢查,生成makefile檔案: ./configure --with-pcre=../pcre-8.42/ --with-zlib=../zlib-1.2.11/ --with-openssl=../openssl-1.1.1b/ --prefix=/opt/yonyou/nginx
(prefix指定安裝路徑。如果無指定,將安裝到user.Local.nginx中)
- 執行編譯與安裝命令: make && make install
6、啟動Nginx
Nginx常用命令:
必須到安裝目錄下的sbin資料夾下,例:cd/home/yyjcpt/Nginx/sbin
啟動
啟動命令:./nginx
修改配置後重新載入生效:nginx -s reload
重新開啟日誌檔案:nginx -s reopen
測試nginx配置檔案是否正確:nginx -t -c /path/to/nginx.conf
關閉
nginx:nginx -s stop:快速停止nginx
nginx –s quit :完整有序的停止nginx
二、開放防火牆埠
1. 檢視開放埠:firewall-cmd --list-all
2、設定開放埠
firewall-cmd --add-service=http --permanent
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload #重啟防火牆
3、防火牆出站入站
firewall-cmd --direct --permanent --add-rule ipv4 filter INPUT 0 \ --in-interface enp0s8 --destination 虛擬IP --protocol vrrp -j ACCEPT
firewall-cmd --direct --permanent --add-rule ipv4 filter OUTPUT 0 \ --out-interface enp0s8 --destination 虛擬IP --protocol vrrp -j ACCEPT
安裝keepalived
1、安裝思路:
- 解壓:tar –zxvf …/keepalived1.8.tar.gz
- 跳轉到解壓後文件夾: cd keepalived1.8/
- 編譯檢查,生成makefile檔案: ./configure
- 執行編譯與安裝命令: make && make install
2、啟動keepalived:
啟動:systemctl start keepalived.service
關閉: systemctl stop keepalived.service
狀態檢視:systemctl status keepalived.service
常見問題
訪問Nginx時報403錯誤
檢視程序:ps-aux | grep nginx
Work工程是nobody使用者,無訪問許可權
**修改配置檔案:vi Nginx\conf\nginx.conf **
將user改成啟動的使用者名稱。
keepalivedd啟動報錯
1、 根據提示 輸入“ systemctl status keepalived.service” 和“journalctl -xe”檢視詳情
2、可以看到詳細資訊“Jan 13 14:00:23 VM_110_5_centos Keepalived[22474]: Unable to find configuration file /etc/keepalived/keepalived.conf (glob returned 3)” ,也就是說找不到配置檔案了,因為這是keepalive.conf的預設位置,而實際的配置檔案位置已經是“/usr/local/etc/keepalived/keepalived.conf”,所以,這裡的位置要修改下。
說明:
Keepalived預設的配置檔案路徑在/etc/keepalived/keepalived.conf
Keepalived預設的日誌檔案儲存在/var/log/messages,使用cat命令
3、 找到修改檔案路徑的地方,vim /usr/local/etc/sysconfig/keepalived。