cenots6 8 nginx安裝以及負載均衡

2021-08-06 03:44:48 字數 3548 閱讀 8156

centos-6.8 安裝 nginx

nginx 環境準備:

安裝nginx需要完成以下依賴的安裝

1.gcc 安裝:

yum install gcc-c++

2.pcre pcre-devel 安裝:yum install -y pcre pcre-devel

3.zlib 安裝: yum install -y zlib zlib-devel

4.openssl 安裝:yum install -y openssl openssl-devel

安裝nginx

wget -c

2. 解壓:

tar -zxvf nginx-1.10.1.tar.gz

3. 配置:

cd nginx-1.10.1 進入nginx解壓目錄

./configure

4. 編譯安裝:

make

make install

5. 查詢安裝路徑:

whereis nginx

啟動、停止nginx:

1. 查詢nginx安裝路徑:whereis nginx

2. 進入nginx安裝路徑:cd /usr/local/nginx/sbin

3. 啟動:

1. ./nginx
2. /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

兩種方式都可以

檢視80埠占用情況netstat -tunlp|grep 80

4. 停止:

從容停止:kill -quit 19795(注意:19795是nginx的程序號)

快速停止:kill -term 46968(注意:46968是nginx的程序號)

kill -int 46975(注意:46975是nginx的程序號)

強制停止:pkill -9 nginx

./nginx -s stop:

此方式相當於先查出nginx程序id再使用kill命令強制殺掉程序。

./nginx -s quit:

此方式停止步驟是待nginx程序處理任務完畢進行停止。

先停止再啟動:./nginx -s quit; ./nginx

5. 重啟:

1. 驗證nginx的配置檔案是否正確:

1. cd /usr/local/nginx/sbin 進入nginx的安裝目錄,接著執行 ./nginx -t

如果正確,會有如下的資訊:

[root@localhost sbin]# ./nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

2. /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf

如果正確會有如下資訊:

[root@localhost sbin]# /usr/local/nginx/sbin/nginx

-t -c /usr/local/nginx/conf/nginx.conf

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

2. 如果配置檔案正確,則可以重啟:

1. ./nginx -s reload (需提前進入nginx可執行檔案目錄:cd /usr/local/nginx/sbin)

2. kill -hup 46991(46991是nginx的程序號)

當 ngin x的配置檔案 nginx.conf 修改後,要想讓配置生效需要重啟 nginx, 使用

-s reload

不用先停止 ngin x再啟動 nginx 即可將配置資訊在 nginx 中生效

例如:./nginx -s reload

設定nginx開機自啟動: 即在

rc.local

增加啟動**就可以了

檢視nginx程序:

1. ps -ef |grep nginx 2.

ps aux|grep nginx

兩種方式都可以

二 。負載均衡配置

我就簡單的在乙個伺服器上啟了兩個tomcat 然後做了一下測試 可以輪詢訪問兩個服務

後續我會完善該配置

}nginx server 配置引數詳解

server  

}

Centos6 8 離線安裝nginx

本司要在客戶前置機上安裝nginx做網路對映,首先是解決nginx的安裝問題,以下是我安裝時碰到的問題 1.按照nginx中文站 的步驟安裝 這台機器沒有連線外網,執行yum安裝命令一直出現連線超時問題,最終放棄 2.按照手動方式安裝 a 首先現在了nginx的最新版本nginx 1.10.0.ta...

CentOS6 8 編譯安裝 Nginx

tar vxf nginx 1.6.2.tar.gz3 進入解壓後的目錄 cd nginx 1.6.2 yum install y gc gcc gcc c yum install y pcre devel zlib devel openssl devel libxslt devel geoip d...

離線純淨版redhet6 8安裝nginx

第一步,拷貝iso到 tmp目錄下 cd lscd tmp lsdu sh tmp 上傳rhel server 6.8 x86 64 iso檔案 第二步,建立iso目錄 cd lscd tmp lsdu sh tmp mkdir iso 第三步,掛載iso映象到 iso目錄下 mount o loo...