Skip to content

Instantly share code, notes, and snippets.

@crazyscar
Last active March 28, 2018 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazyscar/d0d328cfe42a675803f5c8d617578c3e to your computer and use it in GitHub Desktop.
Save crazyscar/d0d328cfe42a675803f5c8d617578c3e to your computer and use it in GitHub Desktop.
install ss libev 参考 https://gist.github.com/tianjianchn/888a610036c743c4aba2ea1e82f4a216 用Federo库编译的shadowsocks-libev会碰到.so版本不对的问题。所以Centos需要自己编译
#!/bin/bash
# Install Shadowsocks-libev on CentOS 7
# run as root
echo "Installing Shadowsocks..."
random-string()
{
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1
}
SS_IP=`ip route get 1 | awk '{print $NF;exit}'`
SS_PORT=8050
SS_PASSWORD=$(random-string 32)
SS_METHOD=aes-256-gcm
# Install deps
echo "Installing Dependencies"
yum install epel-release -y
yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto c-ares-devel libev-devel libsodium-devel mbedtls-devel -y
# Install git
yum install git -y
## build shadowsocks-libev from source
git clone https://github.com/shadowsocks/shadowsocks-libev.git
cd shadowsocks-libev
git submodule update --init --recursive
./autogen.sh && ./configure && make
make install
# Create shadowsocks config file
echo "Creating shadowsocks config file"
cat <<EOF > /etc/shadowsocks.json
{
"server": "0.0.0.0",
"server_port": ${SS_PORT},
"password": "${SS_PASSWORD}",
"method": "${SS_METHOD}",
"local_address": "127.0.0.1",
"local_port":1080,
"timeout":300,
"fast_open": false,
"workers": 1
}
EOF
## Add system service on CentOS7
echo "Creating system service"
cat <<EOF > /etc/systemd/system/shadowsocks.service
[Unit]
Description=Shadowsocks Server Service
After=syslog.target network.target auditd.service
[Service]
Type=simple
User=nobody
TimeoutStartSec=0
ExecStart=/usr/bin/ss-server -c /etc/shadowsocks.json
[Install]
WantedBy=multi-user.target
EOF
systemctl enable shadowsocks
## Start service
echo "Starting shadowsock system service"
systemctl stop shadowsocks
systemctl start shadowsocks
# View service status
echo "\hecking shadowsock system service status"
sleep 5
systemctl status shadowsocks -l
## Add service on CentOS7 firewall
echo "Creating shadowsock firewalld service"
cat <<EOF > /etc/firewalld/services/shadowsocks.xml
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>shadowsocks</short>
<description>Enable Shadowsocks on ${SS_PORT}/tcp.</description>
<port protocol="tcp" port="${SS_PORT}"/>
</service>
EOF
firewall-cmd --permanent --zone=public --add-service=shadowsocks
# or if you don't want to use service, try:
# firewall-cmd --zone=public --add-port=${SS_PORT}/tcp --permanent
## Reload firewall to apply
firewall-cmd --reload
echo "================================"
echo ""
echo "Congratulations! Shadowsocks has been installed on your system."
echo "Your shadowsocks connection info:"
echo "--------------------------------"
echo "server: ${SS_IP}"
echo "server_port: ${SS_PORT}"
echo "password: ${SS_PASSWORD}"
echo "method: ${SS_METHOD}"
echo "--------------------------------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment