shell脚本管理服务

本地检查端口方法

netstat -lntup ss -lntup lsof i:port

远程检查端口方法

telnet ip port /nc ip port /nmap

进程检查

ps -ef/ ps aux

测试连接

 ping -c1 -i1 -W1 ip|url /curl /wget -q --spider ip|url

centos6

mv rsyncd.sh /etc/init.d/
chmod +x /etc/init.d/rsyncd.sh
chkconfig --add rsyncd.sh
cat rsyncd.sh
#!/bin/bash
# chkconfig: 2345 99 98运行级别 开机运行顺序 关机运行顺序

choice=$1
path=/var/run/rsyncd.pid
case "$choice" in
        start)
                [ -f $path ] || rsync --daemon
        ;;
        stop)
                [ -f $path ] && kill `cat $path`
        ;;
        restart)
                [ -f $path ] && kill `cat $path`
                sleep 1
                rsync --daemon
        ;;
        *)
                echo error
esac
可以使用 chkconfig 服务名称 off/on 进行管理

centos7

[root@manager ~]# cat /usr/lib/systemd/system/rsyncd-new.service 
[Unit]
After=network.target remote-fs.target依赖服务
Description=fast remote file copy program daemon注释
ConditionPathExists=/etc/rsyncd.conf

[Service]
Type=forking服务模式守护进程
ExecStart=/root/rsyncd.sh start加执行权限
ExecStop=/root/rsyncd.sh stop
ExecRestart=/root/rsyncd.sh restart

[Install]
WantedBy=multi-user.target运行级别
可以使用systemctl 文件名称进行管理
发布了35 篇原创文章 · 获赞 0 · 访问量 971

猜你喜欢

转载自blog.csdn.net/weixin_45446068/article/details/103977601
今日推荐