備忘錄:做個筆記,即可。
記錄:NO.217
本例環境:
操作系統:CentOS-7-x86_64-DVD-1908
nginx版本:nginx-1.18.0.tar
遠程連接工具:SecureCRT 8.0
虛擬機:vmware 12
下載地址:http://nginx.org/en/download.html
官網介紹:
nginx [engine x] is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server.
名詞:
gcc: The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Ada, Go, and D, as well as libraries for these languages (libstdc++,...).
pcre: The Perl Compatible Regular Expressions (PCRE) library is a set of functions that implement regular expression pattern matching using the same syntax and semantics as Perl 5. PCRE has its own native API, in addition to a set of POSIX compatible wrapper functions. PCRE(Perl Compatible Regular Expressions)是一個Perl庫,包括 perl 兼容的正則表達式庫。
zlib:A Massively Spiffy Yet Delicately Unobtrusive Compression Library.
openssl:Open Secure Sockets Layer.OpenSSL是一個開放源代碼的軟件庫包,應用程序可以使用這個包來進行安全通信,避免竊聽,同時確認另一端連接者的身份。這個包廣泛被應用在互聯網的網頁服務器上。Cryptography and SSL/TLS Toolkit.
nginx安裝部署
1.安裝nginx的依賴
主要包括:gcc,pcre,pcre-devel,zlib,zlib-devel,openssl,openssl-devel
命令:
yum gcc
yum install pcre pcre-devel
yum install zlib zlib-devel
yum install openssl openssl-devel
2.查看依賴是否安裝
命令:
gcc -v
openssl version -a
rpm -qa pcre
rpm -qa zlib
3.解壓
在/home/app解壓nginx-1.18.0.tar.gz
命令:tar -zxvf nginx-1.18.0.tar.gz
把nginx-1.18.0重名爲nginx
命令:mv nginx-1.18.0 nginx
4.安裝
在/home/app/nginx目錄下執行命令
./configure
make && make install
5.安裝後nginx的目錄(本例是默認安裝)
安裝後所在目錄:/usr/local/
6.啓動
在/usr/local/nginx/sbin啓動
命令:
./nginx
7.查看啓動進程和端口
進程:
ps -aux | grep nginx
端口
netstat -tlnp | grep nginx
8.關閉防火牆
命令:
service firewalld stop
9.測試
訪問地址:http://192.168.110.130:80
訪問頁面:
10.關閉nginx
找到進程並kill
ps -aux | grep nginx
kill -9 進程號
負載均衡搭建
1.修改配置文件
進入/usr/local/nginx/conf修改nginx.conf配置文件在相應模塊修改
http {
upstream zbzserver{
server 192.168.110.130:18080 weight=1;
server 192.168.110.130:18081 weight=2;
}
server {
listen 17000;
server_name 192.168.110.130;
location / {
proxy_pass http://zbzserver;
}
}
}
2.啓動nginx
./nginx
3.啓動tomcat
本例使用apache-tomcat-8.5.53,需要jdk 1.8環境
配置兩個tomcat分別是:在/home/apps/apache-tomcat-18080和/home/apps/apache-tomcat-18081
apache-tomcat-18080
apache-tomcat-18081
4.爲了分區負載起作用
分別修改/home/apps/apache-tomcat-18080/webapps/ROOT和/home/apps/apache-tomcat-18081/webapps/ROOT的index.jsp文件。
把/home/apps/apache-tomcat-18080/webapps/ROOT/index.jsp的導航標籤nav-home的Home改成Home-18080
把/home/apps/apache-tomcat-18081/webapps/ROOT/index.jsp的導航標籤nav-home的Home改成Home-18081
比如:
分別在/home/apps/apache-tomcat-18080/bin和/home/apps/apache-tomcat-18081/bin啓動tomcat
命令:
./startup.sh
5.分別調用apache-tomcat-18080和apache-tomcat-18081
apache-tomcat-18080地址 http://192.168.110.130:18080 如下:
apache-tomcat-18081地址 http://192.168.110.130:18081如下
6.使用nginx地址調用
地址:http://192.168.110.130:17000
調用到18080端口
調用到18081端口
以上,感謝。