ubuntu下搭建ss服务

最近都在学着捣鼓linux,感觉还是挺好玩的,起码已经从ubuntu desktop进化到了server
因为感觉ubuntu1404的desktop有毒,在shell里面根本设置不了静态ip,只能在图形界面下弄
就是因为这个傻逼的问题,所以我也决定换成server版了,事实证明server下就没事的

弄了也是有差不多一周了,但是都在学的基础东西,所以觉得没啥必要记下来
但是昨天弄的ss服务器搭建我就觉得很有必要记下来,因为自己弄了一半不成功,然后又找大神帮我弄了,大神是弄好了,但是然而大神一下也说不清我的配置是哪里错了,所以我觉得有必要将配置都记下来

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#更新python版本
sudo apt-get update
sudo apt-get upgrade python
#安装python的pip
#其实我根本不懂python,看来也是要入门这个才行
apt-get install python-gevent python-pip
#安装ss服务端
pip install shadowsocks
#设置ss的脚本
#脚本作用是自动运行ss
vim /etc/init.d/shadowsocks
#脚本内容,下面开始连带注释到esac都是脚本内容
#!/bin/sh
### BEGIN INIT INFO
# Provides:          shadowsocks
# Required-Start:    $network $local_fs $remote_fs
# Required-Stop:     $network $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Fast tunnel proxy that helps you bypass firewalls
# Description:       A secure socks5 proxy, designed to protect your Internet traffic.
### END INIT INFO
 
# Author: Teddysun <i@teddysun.com>
 
name=shadowsocks
BIN=/usr/local/bin/ssserver
conf=/etc/shadowsocks.json
#pid=/var/run/shadowsocks.pid
 
start(){
    $BIN -c $conf -d start
    RETVAL=$?
    if [ "$RETVAL" = "0" ]; then
        echo "$name start success"
    else
        echo "$name start failed"
    fi
}
 
stop(){
    pid=`ps -ef | grep -v grep | grep -v ps | grep -i "/usr/bin/python ${BIN}" | awk '{print $2}'`
    if [ ! -z $pid ]; then
        $BIN -c $conf -d stop
        RETVAL=$?
        if [ "$RETVAL" = "0" ]; then
            echo "$name stop success"
        else
            echo "$name stop failed"
        fi
    else
        echo "$name is not running"
        RETVAL=1
    fi
}
 
status(){
    pid=`ps -ef | grep -v grep | grep -v ps | grep -i "/usr/bin/python ${BIN}" | awk '{print $2}'`
    if [ -z $pid ]; then
        echo "$name is not running"
        RETVAL=1
    else
        echo "$name is running with PID $pid"
        RETVAL=0
    fi
}
 
case "$1" in
'start')
    start
    ;;
'stop')
    stop
    ;;
'status')
    status
    ;;
'restart')
    stop
    start
    RETVAL=$?
    ;;
*)
    echo "Usage: $0 { start | stop | restart | status }"
    RETVAL=1
    ;;
esac
exit $RETVAL
#给执行权限
chmod +x /etc/init.d/shadowsocks
#配置ss的账户信息
vim /etc/shadowsocks.json
#内容
{
    "server":"0.0.0.0",
    "local_address": "127.0.0.1",
    "local_port":1080,
    "port_password":{
         "996":"ctnmb"
    },
    "timeout":300,
    "method":"rc4-md5",
    "fast_open":false
} 
#配置信息解释
{
    "server":"0.0.0.0",
    "local_address": "127.0.0.1",
    "local_port":1080,
    "port_password":{
         "客户端端口":"客户端密码"
    },
    "timeout":300,
    "method":"ss加密方式",
    "fast_open":false
} 
#最后开启服务
sudo service shadowsocks start
#添加自启动
update-rc.d shadowsocks defaults

添加评论