1, 创建服务需要执行的脚本
- cd /sb/scripts
- vi td-agent-testlog
- #!/bin/bash
- #
- # /etc/rc.d/init.d/td-agent-DC01
- #
- # chkconfig: - 80 20
- # description: td-agent-DC01
- # processname: td-agent-DC01
- # pidfile: /var/run/td-agent/td-agent-DC01.pid
- #
- ### BEGIN INIT INFO
- # Provides: td-agent-DC01
- # Default-Stop: 0 1 6
- # Required-Start: $local_fs
- # Required-Stop: $local_fs
- # Short-Description: td-agent's init script
- # Description: td-agent is a data collector
- ### END INIT INFO
- /etc/init.d/td-agent-main td-agent-24240 root $*
2, 修改脚本执行权限
chmod 755 td-agent-testlog
3, 创建文件链接
- cd /etc/init.d
- ln -s /sb/scripts/swlog/td-agent-testlog sb_td-agent-testlog
4, 添加服务
- chkconfig --add sb_td-agent-testlog
- chkconfig sb_td-agent-testlog on
- chkconfig --list | grep sb
- sb_td-agent-testlog 0:off 1:off 2:on 3:on 4:on 5:on 6:off
5, 开启服务
- service sb_td-agent-testlog start
- Starting td-agent: td-agent-testlog: [OK]
- ps -ef | grep td-agent
- root 22863 1 0 14:04 ? 00:00:00 /opt/td-agent/embedded/bin/ruby /usr/sbin/td-agent -v --group root --log /var/log/td-agent/td-agent-testlog.log --config /etc/td-agent/td-agent-24240.conf --daemon /var/run/td-agent/td-agent-24240.pid
- root 22866 22863 0 14:04 ? 00:00:00 /opt/td-agent/embedded/bin/ruby /usr/sbin/td-agent -v --group root --log /var/log/td-agent/td-agent-testlog.log --config /etc/td-agent/td-agent-24240.conf --daemon /var/run/td-agent/td-agent-24240.pid
来源: http://www.bubuko.com/infodetail-2770156.html