rhel7/centos6操作系统守护进程配置

本章节主要介绍在rhel6/centos6和rhel7/centos7系统下使用非root用户配置及使用BFT Agent守护进程,其它BFT服务的守护进程和配置用例可以参考本说明,用例详细介绍了基于自定义上传的JRE和系统JDK两种不同JVM配置环境下守护进程的配置。

注意:完全使用root用户注册和使用守护进程服务的方式不在这里详细说明,用户只需保证介质包及包内的文件属于root用户,再用root用户注册守护进程及启动服务即可,即一切操作皆以root用户执行。

使用单独导入的JRE

在实际项目中,客户生产环境中的服务器安装的JDK环境不一定满足BFT Agent服务的运行要求,因此需要在介质包指定路径下上传满足服务运行要求的JRE包。

准备工作

  1. Primeton_BFT_7.5.0_Agent.tar介质包拷贝至/home/bft/BFT75LA/目录

    说明:可以将此介质包拷贝至任意非root用户目录下,本例以bft用户为例
    
  2. 使用bft用户解压介质包至Primeton_BFT_7.5.0_Agent目录

    [root@localhost BFT75LA]# su bft
    [bft@localhost BFT75LA]$ mkdir Primeton_BFT_7.5.0_Agent
    [bft@localhost BFT75LA]$ tar -xvf Primeton_BFT_7.5.0_Agent.tar -C Primeton_BFT_7.5.0_Agent
    
  3. 使用bft用户将JRE包至BFT Agent根目录(本例演示拷贝系统安装的JDK中的JRE,用户可去官网下载或参考本例,从其它已安装的服务器上拷贝)

    注:注意确保BFT Agent目录下的所有文件都是属于bft用户和用户组的

    [root@localhost ~]# cd /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent
    [root@localhost Primeton_BFT_7.5.0_Agent]# su bft
    [bft@localhost Primeton_BFT_7.5.0_Agent]$ cp -r /usr/java/jdk1.8.0_172/jre/ ./
    [bft@localhost Primeton_BFT_7.5.0_Agent]$ ll
    总用量 40
    drwxr-xr-x. 11 bft bft 4096 6月   2 22:11 bftagent
    drwxr-xr-x.  2 bft bft 4096 6月   2 22:11 bftservice
    drwxr-xr-x.  5 bft bft 4096 6月   2 22:52 jre
    -rwxr-xr-x.  1 bft bft 5297 6月   2 18:23 LICENSE
    drwxr-xr-x.  2 bft bft 4096 6月   2 18:24 logs
    -rwxr-xr-x.  1 bft bft  119 6月   2 18:23 startBFTAgent.cmd
    -rwxr-xr-x.  1 bft bft 1230 6月   2 18:23 startBFTAgent.sh
    -rwxr-xr-x.  1 bft bft   33 6月   2 18:23 stopBFTAgent.cmd
    -rwxr-xr-x.  1 bft bft 1242 6月   2 18:23 stopBFTAgent.sh
    

以非root账户运行服务

  1. 使用bft用户启动BFT Agent服务

    [bft@localhost Primeton_BFT_7.5.0_Agent]$ ./startBFTAgent.sh
    [bft@localhost Primeton_BFT_7.5.0_Agent]$ ps -ef | grep bftagent | grep -v "grep"
    bft     3449     1 95 09:16 pts/2    00:00:13 /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/jre/bin/java -Dlog4j2.formatMsgNoLookups=true -classpath /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/enviroment/com.primeton.bft.filetransfer.hotupdate-7.5.0.0.jar -Duser.dir=/home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent com.primeton.bft.filetransfer.LoadMain com.primeton.filetransfer.agent.BFTAgent --logging.config=./config/log4j2.xml
    
  2. 使用root用户执行脚本注册BFT Agent的守护进程服务

    注:确保./bftservice/autostartreg.sh脚本的用户和用户组为bft用户

    [root@localhost Primeton_BFT_7.5.0_Agent]# cd bftservice/
    [root@localhost bftservice]# ll
    总用量 20
    -rwxr-xr-x. 1 bft bft  440 6月   2 18:23 autostartreg.bat
    -rwxr-xr-x. 1 bft bft 1240 6月   2 18:23 autostartreg_oldlinux.sh
    -rwxr-xr-x. 1 bft bft 1308 6月   2 18:23 autostartreg.sh
    -rwxr-xr-x. 1 bft bft  410 6月   2 18:23 installJava.sh
    -rwxr-xr-x. 1 bft bft  265 6月   2 18:23 unautostartreg.bat
    [root@localhost bftservice]# ./autostartreg.sh 
    /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent
    install AgentDaemon
    Created symlink from /etc/systemd/system/multi-user.target.wants/AgentDaemon.service to /usr/lib/systemd/system/AgentDaemon.service.
    install AgentDaemon success
    
  3. 检查守护进程脚本的启动用户(脚本进程的属主为bft用户表示配置成功)

    [root@localhost bftservice]# ps -ef | grep agentDaemon.sh | grep -v "grep"
    bft     3616     1  0 09:18 ?        00:00:00 /bin/bash /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/agentDaemon.sh
    [root@localhost bftservice]#
    
  4. 验证BFT Agent服务的启动用户(自动重启后的BFT Agent进程的属主为bft用户,则表示守护进程配置完全正确)

    手动KILL掉BFT Agent进程

    [root@localhost bftservice]# ps -ef | grep bft | grep -v "grep"
    bft     3449     1 12 09:16 pts/2    00:00:22 /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/jre/bin/java -Dlog4j2.formatMsgNoLookups=true -classpath /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/enviroment/com.primeton.bft.filetransfer.hotupdate-7.5.0.0.jar -Duser.dir=/home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent com.primeton.bft.filetransfer.LoadMain com.primeton.filetransfer.agent.BFTAgent --logging.config=./config/log4j2.xml
    bft     3616     1  0 09:18 ?        00:00:00 /bin/bash /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/agentDaemon.sh
    [root@localhost bftservice]# kill -9 3449
    [root@localhost bftservice]# ps -ef | grep bft | grep -v "grep"
    bft     3616     1  0 09:18 ?        00:00:00 /bin/bash /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/agentDaemon.sh
    bft     3695     1 84 09:20 ?        00:00:04 /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/jre/bin/java -Dlog4j2.formatMsgNoLookups=true -classpath /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/enviroment/com.primeton.bft.filetransfer.hotupdate-7.5.0.0.jar -Duser.dir=/home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent com.primeton.bft.filetransfer.LoadMain com.primeton.filetransfer.agent.BFTAgent --logging.config=./config/log4j2.xml
    

    重启操作系统

    [root@localhost Primeton_BFT_7.5.0_Agent]# reboot
    [root@localhost ~]# 
    [root@localhost ~]# ps -ef | grep bft | grep -v "grep"
    bft     3067     1  0 10:07 ?        00:00:00 /bin/bash /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/agentDaemon.sh
    bft     3130     1 50 10:07 ?        00:00:19 /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/jre/bin/java -Dlog4j2.formatMsgNoLookups=true -classpath /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/enviroment/com.primeton.bft.filetransfer.hotupdate-7.5.0.0.jar -Duser.dir=/home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent com.primeton.bft.filetransfer.LoadMain com.primeton.filetransfer.agent.BFTAgent --logging.config=./config/log4j2.xml
    

非root账户下以root权限运行服务

  1. 使用bft用户将JRE包至BFT Agent根目录(本例演示拷贝系统安装的JDK中的JRE,用户可去官网下载或参考本例,从其它已安装的服务器上拷贝)

    注:注意确保BFT Agent目录下的所有文件都是属于bft用户和用户组的

    [root@localhost ~]# cd /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent
    [root@localhost Primeton_BFT_7.5.0_Agent]# su bft
    [bft@localhost Primeton_BFT_7.5.0_Agent]$ cp -r /usr/java/jdk1.8.0_172/jre/ ./
    [bft@localhost Primeton_BFT_7.5.0_Agent]$ ll
    总用量 40
    drwxr-xr-x. 11 bft bft 4096 6月   2 22:11 bftagent
    drwxr-xr-x.  2 bft bft 4096 6月   2 22:11 bftservice
    drwxr-xr-x.  5 bft bft 4096 6月   2 22:52 jre
    -rwxr-xr-x.  1 bft bft 5297 6月   2 18:23 LICENSE
    drwxr-xr-x.  2 bft bft 4096 6月   2 18:24 logs
    -rwxr-xr-x.  1 bft bft  119 6月   2 18:23 startBFTAgent.cmd
    -rwxr-xr-x.  1 bft bft 1230 6月   2 18:23 startBFTAgent.sh
    -rwxr-xr-x.  1 bft bft   33 6月   2 18:23 stopBFTAgent.cmd
    -rwxr-xr-x.  1 bft bft 1242 6月   2 18:23 stopBFTAgent.sh
    
  2. 使用root账户修改./jre/bin/java的属主和执行权限

    [root@localhost Primeton_BFT_7.5.0_Agent]# chown root jre/bin/java
    [root@localhost Primeton_BFT_7.5.0_Agent]# chmod u+s jre/bin/java
    [root@localhost Primeton_BFT_7.5.0_Agent]# ll jre/bin/
    总用量 456
    lrwxrwxrwx. 1 bft bft      8 6月   2 22:52 ControlPanel -> jcontrol
    -rwsrwxrwx. 1 root  bft   7734 6月   2 22:52 java
    
  3. 使用bft用户启动BFT Agent服务

    [root@localhost Primeton_BFT_7.5.0_Agent]# su bft
    [bft@localhost Primeton_BFT_7.5.0_Agent]$ ./startBFTAgent.sh
    [bft@localhost Primeton_BFT_7.5.0_Agent]$ ps -ef | grep bftagent | grep -v "grep"
    root      3701     1 91 10:14 pts/0    00:00:05 /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/jre/bin/java -Dlog4j2.formatMsgNoLookups=true -classpath /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/enviroment/com.primeton.bft.filetransfer.hotupdate-7.5.0.0.jar -Duser.dir=/home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent com.primeton.bft.filetransfer.LoadMain com.primeton.filetransfer.agent.BFTAgent --logging.config=./config/log4j2.xml
    
  4. 使用root用户执行脚本注册BFT Agent的守护进程服务

    注:确保./bftservice/autostartreg.sh脚本的用户和用户组为bft用户

    [root@localhost Primeton_BFT_7.5.0_Agent]# cd bftservice/
    [root@localhost bftservice]# ll
    总用量 20
    -rwxr-xr-x. 1 bft bft  440 6月   2 18:23 autostartreg.bat
    -rwxr-xr-x. 1 bft bft 1240 6月   2 18:23 autostartreg_oldlinux.sh
    -rwxr-xr-x. 1 bft bft 1308 6月   2 18:23 autostartreg.sh
    -rwxr-xr-x. 1 bft bft  410 6月   2 18:23 installJava.sh
    -rwxr-xr-x. 1 bft bft  265 6月   2 18:23 unautostartreg.bat
    [root@localhost bftservice]# ./autostartreg.sh 
    /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent
    install AgentDaemon
    Created symlink from /etc/systemd/system/multi-user.target.wants/AgentDaemon.service to /usr/lib/systemd/system/AgentDaemon.service.
    install AgentDaemon success
    
  5. 检查守护进程脚本的启动用户(脚本进程的属主为bft用户表示配置成功)

    [root@localhost bftservice]# ps -ef | grep agentDaemon.sh | grep -v "grep"
    bft     3838     1  0 10:16 ?        00:00:00 /bin/bash /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/agentDaemon.sh
    
  6. 验证BFT Agent服务的启动用户(自动重启后的BFT Agent进程的属主为root用户,则表示守护进程配置完全正确)

    手动KILL掉BFT Agent进程

    [root@localhost bftservice]# ps -ef | grep bft | grep -v "grep"
    root      3701     1 14 10:14 pts/0    00:00:20 /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/jre/bin/java -Dlog4j2.formatMsgNoLookups=true -classpath /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/enviroment/com.primeton.bft.filetransfer.hotupdate-7.5.0.0.jar -Duser.dir=/home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent com.primeton.bft.filetransfer.LoadMain com.primeton.filetransfer.agent.BFTAgent --logging.config=./config/log4j2.xml
    bft     3838     1  0 10:16 ?        00:00:00 /bin/bash /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/agentDaemon.sh
    [root@localhost bftservice]# kill -9 3701
    [root@localhost bftservice]# ps -ef | grep bft | grep -v "grep"
    bft     3838     1  0 10:16 ?        00:00:00 /bin/bash /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/agentDaemon.sh
    root      4030     1 99 10:20 ?        00:00:03 /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/jre/bin/java -Dlog4j2.formatMsgNoLookups=true -classpath /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/enviroment/com.primeton.bft.filetransfer.hotupdate-7.5.0.0.jar -Duser.dir=/home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent com.primeton.bft.filetransfer.LoadMain com.primeton.filetransfer.agent.BFTAgent --logging.config=./config/log4j2.xml
    

    重启操作系统

    [root@localhost Primeton_BFT_7.5.0_Agent]# reboot
    [root@localhost ~]# 
    [root@localhost ~]# ps -ef | grep bft | grep -v "grep"
    bft     3083     1  0 10:22 ?        00:00:00 /bin/bash /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/agentDaemon.sh
    root      3146     1 45 10:22 ?        00:00:20 /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/jre/bin/java -Dlog4j2.formatMsgNoLookups=true -classpath /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/enviroment/com.primeton.bft.filetransfer.hotupdate-7.5.0.0.jar -Duser.dir=/home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent com.primeton.bft.filetransfer.LoadMain com.primeton.filetransfer.agent.BFTAgent --logging.config=./config/log4j2.xml
    [root@localhost ~]#
    

使用系统JDK

准备工作

  1. Primeton_BFT_7.5.0_Agent.tar介质包拷贝至/home/bft/BFT75LA/目录

    说明:可以将此介质包拷贝至任意非root用户目录下,本例以bft用户为例
    
  2. 使用bft用户解压介质包至Primeton_BFT_7.5.0_Agent目录

    [root@localhost BFT75LA]# su bft
    [bft@localhost BFT75LA]$ mkdir Primeton_BFT_7.5.0_Agent
    [bft@localhost BFT75LA]$ tar -xvf Primeton_BFT_7.5.0_Agent.tar -C Primeton_BFT_7.5.0_Agent
    

以非root账户运行服务

  1. 使用bft用户启动BFT Agent服务

    [bft@localhost Primeton_BFT_7.5.0_Agent]$ ./startBFTAgent.sh
    [bft@localhost Primeton_BFT_7.5.0_Agent]$ ps -ef | grep bftagent | grep -v "grep"
    bft     4508     1 76 15:32 pts/0    00:00:08 /usr/java/jdk1.8.0_201/bin/java -Dlog4j2.formatMsgNoLookups=true -classpath /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/enviroment/com.primeton.bft.filetransfer.hotupdate-7.5.0.0.jar -Duser.dir=/home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent com.primeton.bft.filetransfer.LoadMain com.primeton.filetransfer.agent.BFTAgent --logging.config=./config/log4j2.xml
    
  2. 使用root用户执行脚本注册BFT Agent的守护进程服务

    注:确保./bftservice/autostartreg_oldlinux.sh脚本的用户和用户组为bft用户

    [root@localhost Primeton_BFT_7.5.0_Agent]# cd bftservice/
    [root@localhost bftservice]# ll
    总用量 20
    -rwxr-xr-x. 1 bft bft  440 6月   2 18:23 autostartreg.bat
    -rwxr-xr-x. 1 bft bft 1240 6月   2 18:23 autostartreg_oldlinux.sh
    -rwxr-xr-x. 1 bft bft 1308 6月   2 18:23 autostartreg.sh
    -rwxr-xr-x. 1 bft bft  410 6月   2 18:23 installJava.sh
    -rwxr-xr-x. 1 bft bft  265 6月   2 18:23 unautostartreg.bat
    [root@localhost bftservice]# ./autostartreg.sh 
    /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent
    install AgentDaemon
    Created symlink from /etc/systemd/system/multi-user.target.wants/AgentDaemon.service to /usr/lib/systemd/system/AgentDaemon.service.
    install AgentDaemon success
    
  3. 检查守护进程脚本的启动用户(脚本进程的属主为bft用户表示配置成功)

    [root@localhost bftservice]# ps -ef | grep agentDaemon.sh | grep -v "grep"
    bft     4665     1  0 15:34 ?        00:00:00 /bin/bash /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/agentDaemon.sh
    
  4. 验证BFT Agent服务的启动用户(自动重启后的BFT Agent进程的属主为bft用户,则表示守护进程配置完全正确)

    手动KILL掉BFT Agent进程

    [root@localhost bftservice]# ps -ef | grep bft | grep -v "grep"
    bft     4508     1 12 15:32 pts/0    00:00:24 /usr/java/jdk1.8.0_201/bin/java -Dlog4j2.formatMsgNoLookups=true -classpath /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/enviroment/com.primeton.bft.filetransfer.hotupdate-7.5.0.0.jar -Duser.dir=/home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent com.primeton.bft.filetransfer.LoadMain com.primeton.filetransfer.agent.BFTAgent --logging.config=./config/log4j2.xml
    bft     4665     1  0 15:34 ?        00:00:00 /bin/bash /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/agentDaemon.sh
    [root@localhost bftservice]# kill -9 4508
    [root@localhost bftservice]# ps -ef | grep bft | grep -v "grep"
    bft     4665     1  0 16:26 ?        00:00:00 /bin/bash /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/agentDaemon.sh
    bft     4649     1 89 16:29 ?        00:00:12 /usr/java/jdk1.8.0_201/bin/java -Dlog4j2.formatMsgNoLookups=true -classpath /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/enviroment/com.primeton.bft.filetransfer.hotupdate-7.5.0.0.jar -Duser.dir=/home/nexus/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent com.primeton.bft.filetransfer.LoadMain com.primeton.filetransfer.agent.BFTAgent --logging.config=./config/log4j2.xml
    

    重启操作系统

    [root@localhost Primeton_BFT_7.5.0_Agent]# reboot
    [root@localhost ~]# 
    [root@localhost ~]# ps -ef | grep bft | grep -v "grep"
    bft     3344     1  0 16:26 ?        00:00:00 /bin/bash /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/agentDaemon.sh
    bft     3478     1 24 16:26 ?        00:00:18 /usr/java/jdk1.8.0_201/bin/java -Dlog4j2.formatMsgNoLookups=true -classpath /home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent/enviroment/com.primeton.bft.filetransfer.hotupdate-7.5.0.0.jar -Duser.dir=/home/bft/BFT75LA/Primeton_BFT_7.5.0_Agent/bftagent com.primeton.bft.filetransfer.LoadMain com.primeton.filetransfer.agent.BFTAgent --logging.config=./config/log4j2.xml
    

非root账户下以root权限运行服务

系统JDK下%JAVA_HOME%/bin/java文件的用户和用户组都为root,且执行权限为755,即允许其它用户执行,所以在守护进程为非root用户启动时,BFT的服务也都为非root用户启动。

部署两个Agent实例

# 在执行autostartreg.sh或autostartreg_oldlinux.sh时加上参数
# [root@localhost bftservice]# ./autostartreg.sh "" NewName
# 参数说明:$1为平台类型(uname),$2为守护进程名称
[root@localhost bftservice]# ./autostartreg.sh "" OfficeAgentDaemon
[root@localhost bftservice]# ./autostartreg.sh "" PayAgentDaemon

守护进程服务相关命令

启动:systemctl start AgentDaemon
停止:systemctl stop AgentDaemon
状态:systemctl status AgentDaemon
禁止开机自启动:systemctl disable AgentDaemon
启用开机自启动:systemctl enable AgentDaemon

守护进程说明

守护进程不会重启Agent情况(目录中存在norestart文件)

1:执行stopBFTAgent.sh后停止agent,守护进程不会重新启动agent

2:Agent登录失败情况,守护进程不会重新启动agent

(1)agent连接超过最大连接数

(2)系统中存在同名的Agent节点

3:Agent安装后没有启动过,守护进程不会启动agent

守护进程重启Agent需满足条件

1:没有norestart文件

2:pid文件中pid号进程不存在

3:“ps –ef|grpe *”进程查询无结果

results matching ""

    No results matching ""