专注于 JetBrains IDEA 全家桶,永久激活,教程
持续更新 PyCharm,IDEA,WebStorm,PhpStorm,DataGrip,RubyMine,CLion,AppCode 永久激活教程

004.HAProxy的管理与维护

一 安装

[root@haproxy_master ~]# yum -y install gcc gcc-c++ make openssl-devel wget openssh-clients #安装编译工具

[root@haproxy_master ~]# service iptables stop

[root@haproxy_master ~]# chkconfig iptables off

[root@haproxy_master ~]# vi /etc/selinux/config

SELINUX=disabled

1.1 yum安装

[root@HAProxy ~]# yum -y install haproxy

二 常见参数

[root@haproxy_master ~]# haproxy -h

68_1.png

参数
说明
-v
显示当前版本信息:“-vv”显示已知的创建选项
-d
表示让警察运行在debug模式;-db表示禁用后台模式,让程序在前台运行。
-D
让程序以daemon模式启动,此选项也可以在HAProxy匹配文件中设置。
-q
表示无提示模式,程序运行不输出任何信息。
-c
对HAProxy配置文件进行语法检查,若配置文件错误,会输出对应的错误位置和错误信息。
-n
设置最大并发连接总数。
-m
限制可用的内存大小,以MB为单位。
-N
设置默认的连接数。
-p
设置HAProxy的PID文件路径。
-de
不是用epoll模型。
-ds
不是用speculative epoll。
-dp
不是用poll模型。
-sf
程序启动后向PID文件里的进程发送FINISH信号,此参数需要放在命令行最后。
-st
程序启动后向PID文件里的进程发送TERMINATE信号,此参数需要放在命令行最后。

三 HAProxy启动脚本

Usage: /etc/init.d/haproxy {start|stop|status|restart|try-restart|reload|force-reload}”

 #!/bin/sh
 #
 # haproxy
 #
 # chkconfig:   - 85 15
 # description:  HAProxy is a free, very fast and reliable solution \
 #               offering high availability, load balancing, and \
 #               proxying for TCP and  HTTP-based applications
 # processname: haproxy
 # config:      /etc/haproxy/haproxy.cfg
 # pidfile:     /var/run/haproxy.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

 exec="/usr/sbin/haproxy"
 prog=$(basename $exec)

 [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

 cfgfile=/etc/haproxy/haproxy.cfg
 pidfile=/var/run/haproxy.pid
 lockfile=/var/lock/subsys/haproxy

 check() {
     $exec -c -V -f $cfgfile $OPTIONS
 }

 start() {
     $exec -c -q -f $cfgfile $OPTIONS
     if [ $? -ne 0 ]; then
         echo "Errors in configuration file, check with $prog check."
         return 1
     fi

     echo -n $"Starting $prog: "
     # start it up here, usually something like "daemon $exec"
     daemon $exec -D -f $cfgfile -p $pidfile $OPTIONS
     retval=$?
     echo
     [ $retval -eq 0 ] && touch $lockfile
     return $retval
 }

 stop() {
     echo -n $"Stopping $prog: "
     # stop it here, often "killproc $prog"
     killproc $prog
     retval=$?
     echo
     [ $retval -eq 0 ] && rm -f $lockfile
     return $retval
 }

 restart() {
     $exec -c -q -f $cfgfile $OPTIONS
     if [ $? -ne 0 ]; then
         echo "Errors in configuration file, check with $prog check."
         return 1
     fi
     stop
     start
 }

 reload() {
     $exec -c -q -f $cfgfile $OPTIONS
     if [ $? -ne 0 ]; then
         echo "Errors in configuration file, check with $prog check."
         return 1
     fi
     echo -n $"Reloading $prog: "
     $exec -D -f $cfgfile -p $pidfile $OPTIONS -sf $(cat $pidfile)
     retval=$?
     echo
     return $retval
 }

 force_reload() {
     restart
 }

 fdr_status() {
     status $prog
 }

 case "$1" in
     start|stop|restart|reload)
         $1
         ;;
     force-reload)
         force_reload
         ;;
     check)
         check
         ;;
     status)
         fdr_status
         ;;
     condrestart|try-restart)
    [ ! -f $lockfile ] || restart
    ;;
     *)
         echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}"
         exit 2
 esac

文章永久链接:https://tech.souyunku.com/20468

未经允许不得转载:搜云库技术团队 » 004.HAProxy的管理与维护

JetBrains 全家桶,激活、破解、教程

提供 JetBrains 全家桶激活码、注册码、破解补丁下载及详细激活教程,支持 IntelliJ IDEA、PyCharm、WebStorm 等工具的永久激活。无论是破解教程,还是最新激活码,均可免费获得,帮助开发者解决常见激活问题,确保轻松破解并快速使用 JetBrains 软件。获取免费的破解补丁和激活码,快速解决激活难题,全面覆盖 2024/2025 版本!

联系我们联系我们