keepalived+nginx离线安装
Keepalived nginx 安装
把keepalived-1.2.23.tar.gz发送到/opt下
cd /opt/
tar -zxvf keepalived-1.2.23.tar.gz
cd keepalived-1.2.23
./configure --prefix=/usr/local/keepalived
make && make install
cd /etc
mkdir keepalived
cd /usr/local/keepalived/etc/keepalived
cp keepalived.conf /etc/keepalived/
复制keepalived专用内的文件
cd /usr/local/keepalived/etc/rc.d/init.d/
cp keepalived /etc/init.d/
cp keepalived.conf /etc/sysconfig/
cp keepalived /etc/sysconfig/
vim /etc/keepalived/keepalived.conf
主Keepalived 配置MASTER ,备配置BACKUP
vim /etc/init.d/keepalived
PATH="$PATH:/usr/local/keepalived/sbin"
export PATH
为Keepalived的路径
service keepalived start
service keepalived status
把tengine-2.1.2.tar.gz复制到/opt
yum -y install openssl openssl-devel pcre pcre-devel
cd /opt
tar -zxvf tengine-2.1.2.tar.gz
cd tengine-2.1.2
./configure --prefix=/usr/local/nginx
make && make install
cd /etc
mkdir nginx
cd /usr/local/nginx/
cp -r conf /etc/nginx/
把nginx专用内的文件发送到
cp nginx /etc/init.d
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
cp nginx.conf /etc/nginx/conf/
service keepalived restart
service nginx start
测试keepalived 重启服务IP能否自动飘
关闭nginx 关闭,是否自动开启。
#-----------------nginx发布静态文件-------------
有一个A网站,访问的话会重定向跳转到B网站上,在A网站的nginx配置文件中配置的有如下:
location / {
rewrite ^/(.*) http://B/$1 redirect;
}
现在有一个需求,就是在小程序中需要给A网站验证一个txt文件,正常做法是要把这个文件上传到B网站才行,但是B网站无法进行操作,只能是在A上面操作,所以考虑直接使用写死的方式进行:
location /EJyhBr8IAO.txt{
alias /opt/verify/EJyhBr8IAO.txt;
}
示例:
location /WW_verify_IPbZZJDkYw0tKQ7m.txt{
alias /usr/local/nginx/html/WW_verify_IPbZZJDkYw0tKQ7m.txt;
}
把txt文件上传到指定目录,完美解决。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了