1、安装nginx并搭建nginx负载均衡
操作系统:CentOS 7
服务器IP:(代理)192.168.139.151
(web)192.168.139.152 192.168.139.153
安装nginx过程:安装在代理服务器上
第一步:下载、上传到服务器后
第二步:安装依赖包:
yum install pcre-devel automake make zlib-devel gcc-c++ libtool openssl openssl-devel -y
第三步:解压到指定位置:
tar -zxvf nginx-1.20.2.tar.gz -C /usr/local/
第四步:新建用户名:useradd nginx -s /sbin/nologin -M
第五步:开始编译:
./configure \
> --user=nginx \ #指定程序运行的用户
> --group=nginx \ #指定程序运行的用户组
> --prefix=/usr/local/nginx \ #指定安装目录
> --with-http_ssl_module \ #启用nginx-http_ssl_module的支持(使其支持https请求)
> --with-http_sub_module \ #启用nginx-http_sub_module的支持(允许用一些其他文本代替nginx)
> --with-http_stub_status_module \ #启用ngx_http_stub_status_module支持
> --with-http_gzip_static_module \#启用ngx_http_gzip_static_module支持
> --with-pcre #启用pcre库
make && make install
六:启动nginx
1、检查语法 /usr/local/nginx/sbin/nginx -t
2、启动nginx /usr/local/nginx/sbin/nginx
3、查看端口 lsof -i :80
修改配置文件
vim /usr/local/nginx/conf/nginx.conf
启动nginx
/usr/local/nginx/sbin/nginx
2、配置两台web服务器
yum -y install httpd 注:用nginx也是相同操作只是发布目录不一样
vim /var/www/html/index.html
重启httpd
systemctl restart httpd.service
访问IP