centos 7创建ss服务(方式一)

一:安装PIP,由于安装的是python 版本的ss,所以需要先安装PIP;

$ curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
$ python get-pip.py
View Code

二:安装ss

$ pip install --upgrade pip
$ pip install s
View Code

三:创建配置文件,创建文件所在目录:/etc

#创建文件命令,
$ vi /etc/s.json
#若进入了etc目录
$ vi s.json
View Code

  配置文件内容:

单端口:
 {
 "server":"0.0.0.0",            --服务器IP,直接用0.0.0.0也可【如果阿里云服务器是香港服务器,配置文件中IP地址需要填写内网IP,其它地区不用】
 "server_port":8888,            --端口端口
 "local_address": "127.0.0.1",  --本地地址,可省略
 "local_port":1080,             --本地端口,可省略
 "password":"password",         --密码
 "timeout":300,                 --超时时间,可省略
 "method":"aes-256-cfb",        --加密策略,有多重策略,具体自查
}
多端口:
{
    "server":"0.0.0.0",
    "local_address":"127.0.0.1",
    "local_port":1080,
    "port_password":{           --每个端口对应一个密码
        "1111":"password1",
        "1112":"password2",
        "1113":"password3"
    },
    "timeout":300,
    "method":"aes-256-cfb",
    "fast_open":false
}
View Code

四:启动ss

#启动
ssserver -c /etc/s.json -d start
#停止
ssserver -c /etc/s.json -d stop
#重启
ssserver -c /etc/s.json -d restart

#查看是否成功启动
ps -ef | grep shad
View Code

五:配置自动启动服务,新建启动脚本文件vi /etc/systemd/system/s.service,内容如下:

[Unit]
Description=***

[Service]
TimeoutStartSec=0
ExecStart=/usr/bin/ssserver -c /etc/s.json

[Install]
WantedBy=multi-user.target
View Code

  通过以下命令注册,启动服务

$ systemctl enable s
$ systemctl start s
View Code

  启动后可以查看服务状态

$ systemctl status s -l
View Code

  若是成功启动

● s.service - ***
   Loaded: loaded (/etc/systemd/system/s.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2017-08-13 18:03:41 CST; 1h 29min ago
 Main PID: 9567 (ssserver)
   CGroup: /system.slice/s.service
           └─9567 /usr/bin/python2 /usr/bin/ssserver -c /etc/s.json
View Code

六:firewalld防火墙

centos7用的firewalld,若不进行设置,可能会导致SS无法使用,如果是阿里云服务器,则可以在阿里云管理后台设置安全组;

# 开放端口
$ firewall-cmd --permanent --add-port=18381-18385/tcp 
# 修改规则后需要重启
$ firewall-cmd --reload 
View Code

  

 

转载于:https://www.cnblogs.com/Rawls/p/9935847.html

你可能感兴趣的:(centos 7创建ss服务(方式一))