0%

使用systemd启动stunnel,并设置自动重启的方法

操作步骤

运行环境: Centos7

  1. 安装stunnel

    1
    yum install stunnel
  2. 编写systemd配置文件,放到/usr/lib/systemd/system

1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=Stunnel Proxy Server
After=network.target

[Service]
Type=forking
User=root
ExecStart=/usr/bin/stunnel /etc/stunnel/stunnel.conf
Restart=always

[Install]
WantedBy=multi-user.target

参数解释:

  • Restart=always 只要不是通过systemctl stop来停止服务,任何情况下都必须要重启服务,默认值为no
  1. 启动stunnel
    1
    2
    systemctl daemon-reload
    systemctl start stunnel

手动启动和停止stunnel的方法

启动stunnel

1
stunnel /etc/stunnel/stunnel.conf

停止stunnel

1
kill `cat /var/run/stunnel.pid`

参考

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/security_guide/sect-starting_stopping_restarting_stunnel