一、环境介绍:
1、服务器:
CentOS6.5_x86_64
2、Windows客户端
Windows 10
centos7 安装非常简单 就前面3条命令
二、安装部署:
1、Shadowsocks是什么?
Shadowsocks是一个安全的Socks代理,用于保护网络流量不被干扰,也是开源的项目;主要特性包括:
a、快速(异步I/O和事件驱动程序)。
b、安全(所有的流量都经过加密算法加密,支持自定义算法)。
c、支持移动客户端(专为移动设备和无线网络优化)。
d、跨平台(可运行于包括PC,Mac,手机(Android和iOS)和路由器(OpenWrt)在内的多种平台上)。
e、使用Socks5协议和可自定义密码的工业级算法加密,流量在网络传输过程中不易被他人读取。
f、开源。
g、易于维护。
2、安装Shadowsocks服务端:
# yum update
# yum install python-setuptools && easy_install pip
# pip install shadowsocks
python2.6 get-pip.py 报错下面的错误
_blocking_errnos = {errno.EAGAIN, errno.EWOULDBLOCK} pip
解决方案:
# 1, 从官方github获取具体版本的pip
wget https://raw.githubusercontent.com/pypa/get-pip/master/2.6/get-pip.py
# 2,运行刚才获取的pip文件
python2.6 get-pip.py
CentOS7 自带pip
报错
File "/usr/local/bin/pip", line 7, in <module>
1 wget https://bootstrap.pypa.io/get-pip.py 2 python get-pip.py
vi /usr/bin/pip
from pip import __main__ if __name__ == '__main__': sys.exit(__main__._main())
3、配置Shadowsocks:
此文件默认不存在,需要创建:
# vim /etc/shadowsocks.json { "server":"your_server_ip", "server_port":8388, "password":"yourpassword", "timeout":300, "method":"aes-256-cfb", "fast_open":false, "workers": 1 }
注:
代码中各字段的含义:
server:服务器 IP地址 (IPv4/IPv6)
server_port:服务器监听的端口,一般设为80,443等,注意不要设为使用中的端口
password:设置密码,自定义
timeout:超时时间(秒)
method:加密方法,可选择 “aes-256-cfb”, “rc4-md5”等等。推荐使用 “rc4-md5”
fast_open:true 或 false。如果你的服务器 Linux 内核在3.7+,可以开启 fast_open 以降低延迟。
workers:workers数量,默认为 1
如要你需要分享SS服务给朋友或家人,可以配置多个SS账户,具体可以参考下面的代码。
{ "server":"your_server_ip", "port_password":{ "8381":"pass1", "8382":"pass2", "8383":"pass3", "8384":"pass4" }, "timeout":60, "method":"rc4-md5", "fast_open":false, "workers":1 }
注意:特别注意json的格式,注意空格和Tab的用法要一致!
4、启动Shadowsocks:
# ssserver -c /etc/shadowsocks.json -d start INFO: loading config from /etc/shadowsocks.json 2017-01-10 22:38:12 WARNING warning: your timeout 60 seems too short 2017-01-10 22:38:12 INFO loading libcrypto from libcrypto.so.10 started
报错信息:
# ssserver -c /etc/shadowsocks.json -d start INFO: loading config from /etc/shadowsocks.json /usr/lib/python2.6/site-packages/shadowsocks/shell.py:154: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6e.message) ERROR: found an error in config.json: Expecting property name: line 5 column 5 (char 86)
解决方法:
# vim /etc/shadowsocks.json
{ "server":"your_server_ip", "port_password":{ "8381":"pass1", "8382":"pass2", "8383":"pass3", "8384":"pass4" #注意:json的最后一行是没有“,”(逗号) }, "timeout":60, "method":"rc4-md5", "fast_open":false, "workers":1 }
5、加入开机自启:
# echo "ssserver -c /etc/shadowsocks.json -d start" >> /etc/rc.d/rc.local
1、基本操作
# 查看防火墙状态
service iptables status
# 停止防火墙
service iptables stop
# 启动防火墙
service iptables start
# 重启防火墙
service iptables restart
# 永久关闭防火墙
chkconfig iptables off
# 永久关闭后重启
chkconfig iptables on
centos7
1、开放端口
firewall-cmd --zone=public --add-port=5672/tcp --permanent # 开放5672端口
firewall-cmd --zone=public --remove-port=5672/tcp --permanent #关闭5672端口
firewall-cmd --reload # 配置立即生效
2、查看防火墙所有开放的端口
firewall-cmd --zone=public --list-ports
3.、关闭防火墙
如果要开放的端口太多,嫌麻烦,可以关闭防火墙,安全性自行评估
systemctl stop firewalld.service
4、查看防火墙状态
firewall-cmd --state
5、查看监听的端口
netstat -lnpt
一、CentOS 7快速开放端口:
CentOS升级到7之后,发现无法使用iptables控制Linuxs的端口,baidu之后发现Centos 7使用firewalld代替了原来的iptables。下面记录如何使用firewalld开放Linux端口:
开启端口
[root@centos7 ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent
查询端口号80 是否开启:
[root@centos7 ~]# firewall-cmd --query-port=80/tcp
重启防火墙:
[root@centos7 ~]# firewall-cmd --reload
查询有哪些端口是开启的:
[root@centos7 ~]# firewall-cmd --list-port
命令含义:
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
1、开启防火墙 systemctl start firewalld
(1)可以通过下面这个命令查看可以打开的服务有哪些
firewall-cmd --get-services
查看当前开了哪些端口其实一个服务对应一个端口,每个服务对应/usr/lib/firewalld/services
下面一个xml
文件。
firewall-cmd --list-services
(2)可以通过下面的命令添加一个服务到firewalld
firewall-cmd --add-service=http //http换成想要开放的service
1
这样添加的service当前立刻生效,但系统下次启动就失效,可以测试使用。要永久开发一个service,加上 --permanent
firewall-cmd --permanent --add-service=http
1
然后通过systemctl restart firewalld.service重启防火墙就生效了