当前位置: 首页 > 知识库问答 >
问题:

在CentOS7.2中通过sysv init脚本重新加载HAagent服务时,HAagent进程意外被杀死

窦成荫
2023-03-14

我从CentOS7.2存储库安装了HAproxy(1.5.14-3.el7)。当我用错误的HAproxy重新加载HAproxy服务时。cfg,重新加载的返回代码不正确。

关于HAproxy、OS、systemd信息,请参见以下内容:

[root@unknown ~]# rpm -qa | egrep haproxy
haproxy-1.5.14-3.el7.x86_64
[root@unknown ~]#

[root@unknown ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@unknown ~]#

[root@unknown ~]# rpm -qa | egrep systemd
systemd-libs-219-19.el7.x86_64
systemd-219-19.el7.x86_64
systemd-sysv-219-19.el7.x86_64
[root@unknown ~]#

重新加载的返回代码不正确。

[root@unknown ~]# service haproxy status
Redirecting to /bin/systemctl status  haproxy.service
●haproxy.service - HAProxy Load Balancer
   Loaded: loaded (/usr/lib/systemd/system/haproxy.service; disabled;     vendor preset: disabled)
   Active: active (running) since Tue 2016-06-07 11:24:41 UTC; 4s ago
[root@unknown ~]#
[root@unknown ~]#
[root@unknown ~]# more /etc/haproxy/haproxy.cfg
XXXX                                                 **--> I added an incorrect keyword into haproxy.cfg**
Global
....
[root@unknown ~]#
[root@unknown ~]#
[root@unknown ~]# service haproxy reload
Redirecting to /bin/systemctl reload  haproxy.service
[root@unknown ~]#
[root@unknown ~]# echo $?
0                                                   **--> It was sucessful !!!**

[root@unknown ~]#
[root@unknown ~]# service haproxy status
Redirecting to /bin/systemctl status  haproxy.service
● haproxy.service - HAProxy Load Balancer
   Loaded: loaded (/usr/lib/systemd/system/haproxy.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2016-06-07 11:24:41 UTC; 21s ago
  Process: 16507 ExecReload=/bin/kill -USR2 $MAINPID (code=exited, status=0/SUCCESS)
     Main PID: 16464 (haproxy-systemd)
   CGroup: /system.slice/haproxy.service
           tq16464 /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
           tq16465 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
           mq16466 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds

Jun 07 11:24:41 unknown systemd[1]: Started HAProxy Load Balancer.
Jun 07 11:24:41 unknown systemd[1]: Starting HAProxy Load Balancer...
Jun 07 11:24:41 unknown haproxy-systemd-wrapper[16464]: haproxy-systemd-wrapper: executing /usr/sbin/haproxy -f /etc/haproxy/haproxy...id -Ds
Jun 07 11:24:57 unknown systemd[1]: Reloaded HAProxy Load Balancer.
Jun 07 11:24:57 unknown haproxy-systemd-wrapper[16464]: haproxy-systemd-wrapper: re-executing
Jun 07 11:24:57 unknown haproxy-systemd-wrapper[16464]: haproxy-systemd-wrapper: executing /usr/sbin/haproxy -f /etc/haproxy/haproxy... 16466
Jun 07 11:24:57 unknown haproxy-systemd-wrapper[16464]: [ALERT] 158/112457 (16508) : parsing [/etc/haproxy/haproxy.cfg:9]: unknown k...ction.  **--> In fact, it was wrong**
Jun 07 11:24:57 unknown haproxy-systemd-wrapper[16464]: [ALERT] 158/112457 (16508) : Error(s) found in configuration file : /etc/hap...xy.cfg
Jun 07 11:24:57 unknown haproxy-systemd-wrapper[16464]: [ALERT] 158/112457 (16508) : Fatal errors found in configuration.

所以我决定使用sysv init. d脚本来启动/重新加载/停止HA代理服务。

sysv初始化。d脚本:

[root@unknown ~]# cat /etc/init.d/haproxy
#!/bin/sh
#
# chkconfig: - 85 15
# description: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited \
#              for high availability environments.
# processname: haproxy
# config: /etc/haproxy/haproxy.cfg
# pidfile: /var/run/haproxy.pid

# Script Author: Simon Matter <simon.matter@invoca.ch>
# Version: 2004060600

### BEGIN INIT INFO
# Provides: HA-Proxy
# Required-Start: $network $syslog sshd
# Required-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: HAProxy
### END INIT INFO

# Source function library.
if [ -f /etc/init.d/functions ]; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 0
fi

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
#[ ${NETWORKING} = "no" ] && exit 0

# This is our service name
BASENAME=`basename $0`
if [ -L $0 ]; then
  BASENAME=`find $0 -name $BASENAME -printf %l`
  BASENAME=`basename $BASENAME`
fi

[ -f /etc/$BASENAME/$BASENAME.cfg ] || exit 1

RETVAL=0

start() {
  /usr/sbin/$BASENAME -c -q -f /etc/$BASENAME/$BASENAME.cfg
  if [ $? -ne 0 ]; then
    echo "Errors found in configuration file, check it with '$BASENAME check'."
    return 1
  fi

  echo -n "Starting $BASENAME: "
  daemon /usr/sbin/$BASENAME -D -f /etc/$BASENAME/$BASENAME.cfg -p /var/run/$BASENAME.pid
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$BASENAME
  return $RETVAL
}

stop() {
  killproc $BASENAME -USR1
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$BASENAME
  [ $RETVAL -eq 0 ] && rm -f /var/run/$BASENAME.pid
  return $RETVAL
}

restart() {
  /usr/sbin/$BASENAME -c -q -f /etc/$BASENAME/$BASENAME.cfg
  if [ $? -ne 0 ]; then
    echo "Errors found in configuration file, check it with '$BASENAME check'."
    return 1
  fi
  stop
  start
}

reload() {
  /usr/sbin/$BASENAME -c -q -f /etc/$BASENAME/$BASENAME.cfg
  if [ $? -ne 0 ]; then
    echo "Errors found in configuration file, check it with '$BASENAME check'."
    return 1
  fi
  /usr/sbin/$BASENAME -D -f /etc/$BASENAME/$BASENAME.cfg -p /var/run/$BASENAME.pid -sf $(cat /var/run/$BASENAME.pid)
}

check() {
  /usr/sbin/$BASENAME -c -q -V -f /etc/$BASENAME/$BASENAME.cfg
}

rhstatus() {
  status $BASENAME
}

    condrestart() {
  [ -e /var/lock/subsys/$BASENAME ] && restart || :
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  reload)
    reload
    ;;
  condrestart)
    condrestart
    ;;
  status)
    rhstatus
    ;;
  check)
    check
    ;;
  *)
    echo $"Usage: $BASENAME {start|stop|restart|reload|condrestart|status|check}"
    exit 1
esac

exit $?

当我用正确的HAproxy重新加载HAproxy serivce时。cfg时,命令(service haproxy reload)返回0,但haproxy的状态变为失败。

[root@unknown ~]# service haproxy status
● haproxy.service - LSB: HAProxy
   Loaded: loaded (/etc/rc.d/init.d/haproxy)
   Active: active (running) since Tue 2016-06-07 11:33:22 UTC; 1h 14min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 16636 ExecStart=/etc/rc.d/init.d/haproxy start (code=exited, status=0/SUCCESS)
 Main PID: 16641 (haproxy)
   CGroup: /system.slice/haproxy.service
           mq16641 /usr/sbin/haproxy -D -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid

Jun 07 11:33:22 unknown systemd[1]: Starting LSB: HAProxy...
Jun 07 11:33:22 unknown haproxy[16636]: Starting haproxy: [  OK  ]
Jun 07 11:33:22 unknown systemd[1]: Started LSB: HAProxy.
[root@unknown ~]#
[root@unknown ~]# service haproxy reload
Reloading haproxy configuration (via systemctl):           [  OK  ]
[root@unknown ~]# echo $?
0                                                      **--> It was sucessful !!!**
[root@unknown ~]#
[root@unknown ~]# service haproxy status
● haproxy.service - LSB: HAProxy
   Loaded: loaded (/etc/rc.d/init.d/haproxy)
   Active: failed (Result: signal) since Tue 2016-06-07 12:48:01 UTC; 1s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 16869 ExecStop=/etc/rc.d/init.d/haproxy stop (code=exited, status=0/SUCCESS)
  Process: 16863 ExecReload=/etc/rc.d/init.d/haproxy reload (code=exited, status=0/SUCCESS)
  Process: 16636 ExecStart=/etc/rc.d/init.d/haproxy start (code=exited, status=0/SUCCESS)
 Main PID: 16868 (code=killed, signal=KILL)

Jun 07 11:33:22 unknown systemd[1]: Starting LSB: HAProxy...
Jun 07 11:33:22 unknown haproxy[16636]: Starting haproxy: [  OK  ]
Jun 07 11:33:22 unknown systemd[1]: Started LSB: HAProxy.
Jun 07 12:48:00 unknown systemd[1]: Reloaded LSB: HAProxy.
Jun 07 12:48:00 unknown systemd[1]: haproxy.service: main process exited, code=killed, status=9/KILL **--> It was killed ,but I don't know which process killed it, Cgroup ?**
Jun 07 12:48:01 unknown haproxy[16869]: [FAILED]
Jun 07 12:48:01 unknown systemd[1]: Unit haproxy.service entered failed state.
Jun 07 12:48:01 unknown systemd[1]: haproxy.service failed.
[root@unknown ~]#

我用了一个更新的系统来获取详细的日志

Jun 07 13:02:59 elb systemd[1]: Starting LSB: HAProxy...
Jun 07 13:02:59 elb systemd[7010]: Executing: /etc/rc.d/init.d/haproxy start
Jun 07 13:02:59 elb haproxy[7010]: Starting haproxy: [  OK  ]
Jun 07 13:02:59 elb systemd[1]: Child 7010 belongs to haproxy.service
Jun 07 13:02:59 elb systemd[1]: haproxy.service: control process exited, code=exited status=0
Jun 07 13:02:59 elb systemd[1]: haproxy.service got final SIGCHLD for state start
Jun 07 13:02:59 elb systemd[1]: Main PID loaded: 7015
Jun 07 13:02:59 elb systemd[1]: haproxy.service changed start -> running
Jun 07 13:02:59 elb systemd[1]: Job haproxy.service/start finished, result=done
Jun 07 13:02:59 elb systemd[1]: Started LSB: HAProxy.          **--> start HAproxy successfully **


Jun 07 13:03:27 elb systemd[1]: Trying to enqueue job haproxy.service/reload/replace
Jun 07 13:03:27 elb systemd[1]: Installed new job haproxy.service/reload as 9504
Jun 07 13:03:27 elb systemd[1]: Enqueued job haproxy.service/reload as 9504


Jun 07 13:03:27 elb systemd[1]: About to execute: /etc/rc.d/init.d/haproxy reload
Jun 07 13:03:27 elb systemd[1]: Forked /etc/rc.d/init.d/haproxy as 7060
Jun 07 13:03:27 elb systemd[1]: haproxy.service changed running -> reload
Jun 07 13:03:27 elb systemd[7060]: Executing: /etc/rc.d/init.d/haproxy reload
Jun 07 13:03:27 elb systemd[1]: Child 7015 belongs to haproxy.service
Jun 07 13:03:27 elb systemd[1]: Main PID changing: 7015 -> 7065
Jun 07 13:03:27 elb systemd[1]: Child 7060 belongs to haproxy.service
Jun 07 13:03:27 elb systemd[1]: haproxy.service: control process exited, code=exited status=0
Jun 07 13:03:27 elb systemd[1]: haproxy.service got final SIGCHLD for state reload
Jun 07 13:03:27 elb systemd[1]: haproxy.service changed reload -> running
Jun 07 13:03:27 elb systemd[1]: Job haproxy.service/reload finished, result=done
Jun 07 13:03:27 elb systemd[1]: Reloaded LSB: HAProxy.   **--> successful to reload HAproxy**

Jun 07 13:03:27 elb systemd[1]: Child 7065 belongs to haproxy.service
Jun 07 13:03:27 elb systemd[1]: haproxy.service: main process exited, code=killed, status=9/KILL **--> process 7065 has been killed unexpectly**
Jun 07 13:03:27 elb systemd[1]: haproxy.service changed running -> failed
Jun 07 13:03:27 elb systemd[1]: Unit haproxy.service entered failed state.
Jun 07 13:03:27 elb systemd[1]: haproxy.service failed.
Jun 07 13:03:27 elb systemd[1]: haproxy.service: cgroup is empty **-->Did cgroup killed process 7065? Is it a bug of systemd? **

在CentOS7.1中,我使用sysv init脚本(请参见上文)重新加载haproxy,并且

我不知道CentOS7.2出了什么问题。我只想得到以下重新加载HA代理的结果。

  • 当haproxy。cfg文件不正确,“service haproxy reload”命令返回1
  • 当haproxy。cfg文件正确,“service haproxy reload”命令返回0

有人能帮我吗?谢谢

共有1个答案

姜淇
2023-03-14

我猜这是一个SELinux问题。您可以尝试更改以下内容::vi/etc/selinux/config

禁用SELINUX

: wq!#保存并退出

 类似资料:
  • 我不确定为什么所有的线程都被阻塞了。我以为类只加载一次,以后就不需要带任何锁了。

  • 问题内容: 我有一个div标签,该标签通过ajax调用填充了脚本,但是脚本未执行。 有没有办法使脚本执行? 问题答案: 如果您使用jQuery的方法,它将解析出脚本标签并对其进行评估: 如果没有jQuery,则可以使用(1)正则表达式或(2)解析DOM树并查找脚本标签来自己编写。(#2是jQuery的执行方式)

  • 我试图执行: 致命错误:中允许的内存大小94371840字节已用尽(尝试分配71字节)phar:///home/xxxxxxx/bin/composer.phar/src/Composer/DependencyResolver/RuleSetGenerator.php 在线123 xxxxxxx是用户。 然后我试着执行: 和: 然后我收到了这个: 哎呀!您的一个进程(php,pid 14331)因

  • 服务人员可能会干扰刷新按钮(按设计)。在桌面Chrome上,您可以按住shift键并单击刷新按钮进行硬重新加载,忽略任何已安装的ServiceWorker。 有没有一种方法可以忽略JavaScript中的SW强制重新加载? (我想要这个,这样我就可以给移动用户一个按钮,如果SW开始行为不端。手机没有移位键。)

  • 我们试图将我们的一个node js应用程序(AngularJS/NodeJS tech stack)部署到生产环境中。随机地,当节点进程被终止时,一些ec2实例就停止了。但是没有记录应用程序/系统级别的错误消息。我们无法在本地/开发/it环境中重现此问题。有人面临过类似的事情吗?非常感谢任何帮助。谢谢!

  • 我有一个实现远程后台服务的应用程序。这个服务是用来下载线程中的文件的(我想说这个服务是作为下载管理器工作的)。 当我想下载一个文件时,我将url发送给服务,服务启动一个线程(我使用的是AsyncTask,但它只在Android4.1中工作)。但下载迟早会停止,我能够知道这一点,因为我显示的通知不再更新。当我单击取消下载的通知时,将向服务发送一个挂起的意图,告诉它取消下载,但当服务重新创建时,将取消