1.Nginx 安装和负载均衡配置
Nginx 安装
注意:以下操作均使用root用户。
- 安装PCRE
- 下载PCRE安装包
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz - 解压安装包
tar zxvf pcre-8.35.tar.gz - 进入安装包目录
cd pcre-8.35 - 编译安装
./configure
如果编译过程中报错:error: You need a C++ compiler for C++ support,这是由于没有安装gcc,输入以下指令进行安装:
yum install -y gcc gcc-c++
安装pcre:
make && make install - 查看pcre版本
pcregrep -V
- 安装Nginx
- 解压安装包
tar -zxvf nginx-1.12.2.tar.gz - 进入安装包目录
cd nginx-1.12.2 - 编译安装
./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
make && make install
如果报出以下错误,需要安装OpenSSL
./configure: error: SSL modules require the OpenSSL library.
安装指令如下:
yum -y install openssl openssl-devel
4) 查看Nginx版本
/usr/local/webserver/nginx/sbin/nginx -v
负载均衡配置
nginx配置中增加:
#服务器的集群
upstream netitcast.com {
#服务器集群名字
#服务器配置 weight是权重的意思,权重越大,分配的概率越大。
#server 127.0.0.1:18080;
#server 127.0.0.1:28080;
server 192.168.10.200:18080; (第一台tomcat的地址+端口)
server 192.168.10.200:28080; (第二台tomcat的地址+端口)
}
location / {
proxy_pass http://netitcast.com;
proxy_redirect default;
}