linux 安装ss

来源:互联网 发布:常用mysql语句面试题 编辑:程序博客网 时间:2024/05/16 08:15

脚本快速安装

脚本功能

  • 自定义端口号密码
  • 全过程静默安装,不会打扰用户
  • 一次只允许运行一个ss进程,脚本会自动检测原来已经运行的进程并杀死
  • 安装防火墙并开放需要的端口

操作步骤

# 下载脚本wget -O ss.sh http://45.32.195.77/file/ss.sh# 执行脚本bash ss.sh# 设置端口号并回车,直接回车是设置为1225Please enter PORT(1225 default):# 设置密码并回车,直接回车是设置为123456Please enter PASSWORD(123456 default):# 等待一会……就完成了(初次执行约2-5min)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12


脚本源码

#! /bin/bash# log路径export log_path=/etc/ss.log# 设置端口号echo -n -e '\033[36mPlease enter PORT(1225 default): \033[0m'# echo -n "please enter port(1225 default):"read portif [ ! -n "$port" ];then        echo "port will be set to 1225"        port=1225else        echo "port will be set to $port"fi# 设置密码echo -n -e '\033[36mPlease enter PASSWORD(123456 default): \033[0m'# echo -n "please enter password(123456 default):"read pwdif [ ! -n "$pwd" ];then        echo "password will be set to 123456"        pwd=123456else        echo "password will be set to $pwd"fi# 写shadowsocks.json配置文件cat>/etc/shadowsocks.json<<EOF{    "server":"0.0.0.0",    "server_port":$port,    "local_address": "127.0.0.1",    "local_port":1080,    "password":"$pwd",    "timeout":300,    "method":"aes-256-cfb",    "fast_open": false}EOF# 安装 shadowsocks 防火墙等ret=`yum install -y m2crypto python-setuptools >> ${log_path} 2>&1`ret=`easy_install pip >> ${log_path} 2>&1`ret=`pip install shadowsocks >> ${log_path} 2>&1`ret=`yum install -y firewalld >> ${log_path} 2>&1`ret=`systemctl start firewalld >> ${log_path} 2>&1`# 开启端口ret=`firewall-cmd --permanent --zone=public --add-port=22/tcp >> ${log_path} 2>&1`ret=`firewall-cmd --permanent --zone=public --add-port=$port/tcp >> ${log_path} 2>&1`ret=`firewall-cmd --reload >> ${log_path} 2>&1`# 如果有相同功能的进程则杀死ps -ef|grep ssserver|grep shadowsocks|awk '{ print $2 }'|xargs kill -9nohup /usr/bin/ssserver -c /etc/shadowsocks.json &# 成功if [ $? -eq 0 ];thenclearcat<<EOF***************Congratulation!*************Shadowsocks installed successfully!PORT: $portPASSWORD: $pwdMETHOD: aes-256-cfb***************JUST ENJOY IT!**************EOF# 失败elseclearcat<<EOF************Failed,retry please!***********cat /etc/ss.log to get something you need…************Failed,retry please!***********EOFfi
  • 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

独立动手搭建

搭建 ss 服务

安装组件

$ yum install m2crypto python-setuptools$ easy_install pip$ pip install shadowsocks
  • 1
  • 2
  • 3
  • 4

安装完成后配置服务器参数

$ vi  /etc/shadowsocks.json
  • 1
  • 2

写入如下配置:

{    "server":"45.76.222.180",    "local_address": "127.0.0.1",    "local_port":8838,    "port_password": "xxxxxxxx",    "timeout":300,    "method":"aes-256-cfb",    "fast_open": false}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

多端口的如下:

{    "server":"0.0.0.0",    "local_address": "127.0.0.1",    "local_port":1080,    "port_password": {         "443": "443",         "8888": "8888"     },    "timeout":300,    "method":"aes-256-cfb",    "fast_open": false}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

其中server字段填写之前的IP Address。password是自己用于连接这个shadow socks的密码,自定义就好。 
其他的不需要更改。

然后保存退出。

vi 的命令: 按 “i” 进入编辑模式,编辑后按 “esc” 退出编辑模式, 输入 “:wq” 保存退出vi。

配置防火墙

# 安装防火墙$ yum install firewalld# 启动防火墙$ systemctl start firewalld
  • 1
  • 2
  • 3
  • 4
  • 5

开启防火墙相应的端口

方法一(推荐)
# 端口号是你自己设置的端口$ firewall-cmd --permanent --zone=public --add-port=443/tcp$ firewall-cmd --reload
  • 1
  • 2
  • 3
  • 4
方法二(麻烦,没必要)

新建文件ss.xml

$ vi /usr/lib/firewalld/services/ss.xml
  • 1
  • 2

粘贴下面的代码

<?xml version="1.0" encoding="utf-8"?><service>  <short>SS</short>  <description>Shadowsocks port  </description>  <port protocol="tcp" port="443"/></service>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

保存退出。

开启端口,重启firewalld 服务,下面的ss是上述的文件的名字,区分大小写

$ firewall-cmd --permanent --add-service=ss$ firewall-cmd --reload
  • 1
  • 2
  • 3

启动 ss 服务

$ ssserver -c /etc/shadowsocks.json
  • 1
  • 2

如果想干点其他的实现后台运行,使用

$ nohup ssserver -c /etc/shadowsocks.json &
原创粉丝点击