nginx高可用

Nginx Web高可用实战:
1、基于shell脚本实现高可用

2、基于Keepalived软件实现高可用

3、基于Heartbeat软件实现高可用

1)生产环境至少两台硬件服务器
2)都要部署Web服务
wget http://nginx.org/download/nginx-1.12.2.tar.gz
解压
sed -i -e 's/1.12.1//g' -e 's/nginx\//JWS\//g' -e 's/"NGINX"/"JWS"/g' src/core/nginx.h
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
./configure --user=app --group=app --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-pcre
监控模块:--with-http_stub_status_module
ssl模块:--with-http_ssl_module
stream模块:--with-stream
make -j4 ##多线程编译

make install -j4 #多线程安装

./nginx
netstat -tnlp|grep "\<80\>"

C:\Windows\System32\drivers\etc

./configure --prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-pcre=/lib64/libpcre.so.0 \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_image_filter_module \
--with-http_slice_module \
--with-mail \
--with-threads \
--with-file-aio \
--with-stream \
--with-mail_ssl_module \
--with-stream_ssl_module

nginx常用命令:

nginx的启动和关闭
nginx -h 查看帮助信息
nginx -v 查看Nginx的版本号
nginx -V 显示Nginx的版本号和编译信息
start nginx 启动Nginx
nginx -s stop 快速停止和关闭Nginx
nginx -s quit 正常停止或关闭Nginx
nginx -s reload 配置文件修改重新加载
nginx -t 测试Nginx配置文件的正确性及配置文件的详细信息
task /fi "imagename eq nginx.exe" windows命令框下查看nginx的进程命令

自动部署脚本:

!/bin/bash
#2020.3.28
#auto install nginx web
#by author biyulin
#############################
NGX_VER=$1
NGX_SOFT=nginx-${NGX_VER}.tar.gz
NGX_DIR=/usr/local/nginx
NGX_YUM="yum install -y"
NGX_SRC=$(echo $NGX_SOFT|sed 's/.tar.*//g')
NGX_ARGS="--user=www --group=www"
NGX_URL="http://nginx.org/download"
if [ $# -eq 0 ];then
echo -e "\033[32m---------------------\033[0m"
echo -e "\033[32mUsage:{/bin/bash $0 1.2.3|1.12.2|1help}\033[0m"
exit 0
fi
if [[ ! -d $NGX_DIR ]];then
$NGX_YUM wget gzip tar make gcc >>/dev/null 2>&1
$NGX_YUM pcre pcre-devel zlib zlib-devel >>/dev/null 2>&1
wget $NGX_URL/$NGX_SOFT
tar -xvf $NGX_SOFT
cd $NGX_SRC
useradd -s /sbin/nologin www -M
./configure --prefix=$NGX_DIR $NGX_ARGS
make
make install
$NGX_DIR/sbin/nginx
ps -ef | grep nginx
netstat -tnlp | grep -w 80
setenforce 0
firewall-cmd --add-port=80/tcp --permanent
systemctl reload firwalld.service
else
read -p "Please Enter yes or no,Retry Install Nginx WEB:" INPUT
if [ $INPUT == "yes" -o $INPUT == "y" -o $INPUT == "Y" ];then
$NGX_YUM wget gzip tar make gcc >>/dev/null 2>&1
$NGX_YUM pcre pcre-devel zlib zlib-devel >>/dev/null 2>&1
wget $NGX_URL/$NGX_SOFT
tar -xvf $NGX_SOFT
cd $NGX_SRC
useradd -s /sbin/nologin www -M
./configure --prefix=$NGX_DIR $NGX_ARGS
make
make install
$NGX_DIR/sbin/nginx
ps -ef | grep nginx
netstat -tnlp|grep -w 80
setenforce 0
firewall-cmd --add-port=80/tcp --permanent
systemctl reload firwalld.service
fi
fi

 

posted @   房东家的猫  阅读(263)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示