centos 搭建Nginx 负载均衡

作者: print("") 分类: linux,nginx 发布时间: 2017-05-22 09:20

一、安装如下环境
yum -y install make gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap lsof
编译pcre的包
tar zxf pcre-8.31.tar.gz
cd pcre-8.31
./configure
make && make install
useradd -s /sbin/nologno -g nginx -M nginx
tar zxf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure –prefix=/usr/local/nginx –sbin-path=/usr/local/nginx/bin/nginx –conf-path=/usr/local/nginx/conf/nginx.conf –error-log-path=/var/log/nginx/error.log –http-log-path=/var/log/nginx/access.log –pid-path=/var/run/nginx/nginx.pid  –lock-path=/var/lock/nginx.lock –user=nginx –group=nginx –with-http_ssl_module –with-http_flv_module –with-http_stub_status_module –with-http_gzip_static_module –http-client-body-temp-path=/var/tmp/nginx/client/ –http-proxy-temp-path=/var/tmp/nginx/proxy/ –http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ –http-uwsgi-temp-path=/var/tmp/nginx/uwsgi –http-scgi-temp-path=/var/tmp/nginx/scgi –with-pcre
make
make install
/usr/local/nginx/bin/nginx –t
./nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory 解决prce的问题 #find / -name libpcre.so*
/usr/local/lib/libpcre.so.1.0.1
/usr/local/lib/libpcre.so
/usr/local/lib/libpcre.so.1
/lib64/libpcre.so.0.0.1
/lib64/libpcre.so.0
出现了这么多结果。我们安装的PCRE库的位置在/usr/local/pcre中,我们就用这个位置
vim /etc/ld.so.conf
在尾行加入/usr/local/bin
root@mail2 bin]# ldconfig
#/usr/local/nginx/bin/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
 
 
这就正常了
启动nginx
/usr/local/nginx/bin/nginx
vim /usr/local/nginx/conf/nginx.conf
在最后面的大括号前面添加一行
include  /usr/local/nginx/conf.d/*.conf;
建立这个目录
mkdir /usr/local/nginx/conf.d
vim /usr/local/nginx/conf.d/lkq.conf
upstream backend
{
server 192.168.236.150:80  weight=1;
server 192.168.236.151:80  weight=2;
#ip_hash;
}
server
{
listen      80;
server_name  www.lkq.com;
location ~ ^/*
{
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
proxy_pass http://backend;
}
}
客户端测试一下
记得在客户端添加本地hosts

 

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

说点什么

avatar
  Subscribe  
提醒