配置Nginx+Tomcat负载均衡集群
# service iptables stop //关闭防火墙# yum -y install pcre-devel zlib-devel openssl-devel //安装相关软件包
# useradd -M -s /sbin/nologin nginx //创建运行nginx服务的程序用户
# tar zxf nginx-1.6.0.tar.gz -C /usr/src/
# cd /usr/src/nginx-1.6.0/
# ./configure --prefix=/usr/local/nginx //指定安装
--user=nginx --group=nginx //指定运行的用户和组
--with-file-aio //启用文件修改支持
--with-http_stub_status_module //启用状态统计
--with-http_gzip_static_module //启用gzip静态压缩
--with-http_flv_module //启用flv模块,提供寻求内存使用基于时间的偏移量文件
--with-http_ssl_module //启用SSL模块
# make && make install
# vim /usr/local/nginx/conf/nginx.conf //修改配置文件
upstream tomcat_server { //在http{…}内添加以下代码,设定负载均衡的服务器列表
server 192.168.1.2:8080 weight=1; //weight参数代表权值,权值越高被分配到的越大
server 192.168.1.3:8080 weight=1;
}
……省略部分内容
location / { //在server{…}的location/{…}加入一行
root html;
indexindex.html index.htm;
proxy_pass //加入此行,代理前面设定的列表中服务器
}
# /usr/local/nginx/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
# /usr/local/nginx/sbin/nginx //开启nginx服务
# netstat -anpt | grep nginx //查看nginx服务的端口号及PID进程号
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4619/nginx
页:
[1]