linux 系统没有自带 wget
工具。当用到 wget
如果没有安装就会出现 --bash: wget: command not found
,需要我们自己安装。
CentOS 安装
yum install wget -y
Ubuntu 安装
apt install wget -y
linux 系统没有自带 wget
工具。当用到 wget
如果没有安装就会出现 --bash: wget: command not found
,需要我们自己安装。
yum install wget -y
apt install wget -y
CentOS 7/8 一键安装 shadowsocks-libev, 本教程仅提供学习,请勿用于商业用途和不法行为。
由于 Google BBR 需要内核版本 4.9 以上,如果安装时内核版本低于 4.9 建议先升级内核版本。
提示:CentOS 7 自带内核版本为 3.10,CentOS 8 自带内核版本为 4.18。
查看内核版本命令:
uname -r
一键脚本已集成TCP优化、自动开启Google BBR(限 4.9 或更高版本内核)、自动安装 shadowsocks-libev
wget https://down.24kplus.com/linux/shadowsocks/centos-shadowsocks-libev.sh
chmod +x centos-shadowsocks-libev.sh && ./centos-shadowsocks-libev.sh
1、提示设置SS密码,输入自定义密码后按回车,也可以直接按回车使用默认密码
2、接下来选择SS要使用的服务器端口,输入自己喜欢的端口, 也可以直接按回车使用默认端口
3、 然后选择加密方式(仅保留相对安全的加密方式),如果选择chacha20的话,就输入对应序号3,按回车继续
4、 安装完成后,会有如下图安装成功的提示,记住各项信息,在客户端连接时需要用到
SS服务端安装成功后,就可以在电脑、手机、路由器等设备上的SS客户端上,按照以上设置的各项参数进行连接了。
最后送上Windows 客户端 Shadowsocks-4.1.7.1.zip
CentOS 8 系统没有自带 tar 的压缩解压工具。当用到 tar 如果没有安装就会出现 -bash: tar: Command Not Found
,需要我们自己安装。
执行:
yum install tar -y
wget -O chardet-3.0.4.tar.gz https://github.com/chardet/chardet/archive/3.0.4.tar.gz
tar -zxf chardet-3.0.4.tar.gz
cd chardet-3.0.4
python setup.py install
如果出现 -bash: pip: command not found
错误, 先安装 pip
CentOS / Ubuntu 安装 pip。 解决 -bash: pip: command not found
错误
执行:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python get-pip.py
Successfully installed pip-19.3.1 setuptools-41.4.0 wheel-0.33.6
linux 系统没有自带 zip 的压缩解压工具。当用到 zip 或者 unzip 如果没有安装就会出现 -bash: unzip: Command Not Found
或 -bash: zip: Command Not Found
,需要我们自己安装。
yum install -y unzip zip
sudo apt-get install zip
解决 configure: error: C++ preprocessor "/lib/cpp" fails sanity check
错误,执行以下:
yum install gcc-c++
解压
unzip FileName.zip
压缩
zip FileName.zip DirName
解压
tar zxvf FileName.tar.gz
压缩
tar zcvf FileName.tar.gz DirName
Nginx 利用 IP2Locaion 模块实现地区负载均衡和IP定位。
由于GeoIP2的效率实在是“惊人”,和那“高到爆”的识别精度,真是让人想爆粗口。经过权衡,将IP定位模块更换为 IP2Locaion。
如果还没安装 IP2Location C Library,请先移步到 https://www.24kplus.com/linux/871.html 安装 IP2Location C Library
下载 Nginx IP2Locaion 模块
git clone https://github.com/ip2location/ip2location-nginx.git
查看当前 Nginx 版本信息
nginx -V
可以看到 Nginx 的版本为1.16.0 和 configure 参数,把 configure 参数拷贝保存下来,后面需要用到。
到官网 https://nginx.org/en/download.html 找到对应的版本源码下载并解压。本站以1.16.0为例:
下载并解压
wget https://nginx.org/download/nginx-1.16.0.tar.gz
tar -zxf nginx-1.16.0.tar.gz
cd nginx-1.16.0
备用下载地址: https://down.24kplus.com/linux/nginx-1.16.0.tar.gz
生成新的 nginx
把刚刚复制的 configure 参数粘贴到 ./configure
后面, 在结尾处加入 -–add-module=../ip2location-nginx
./configure \
--prefix=/etc/nginx \
.....
# 在结尾处加入一行
-–add-module=../ip2location-nginx
# 如果想编译为动态模块,则添加
--add-dynamic-module=../ip2location-nginx
make
编译好之后不要安装, 停止 nginx 服务
systemctl stop nginx
复制编译好的新 nginx 文件拷贝到sbin下
cp /usr/sbin/nginx /usr/sbin/nginx.bak
cp objs/nginx /usr/sbin
编辑 nginx.conf 文件,在 http {} 中加入以下代码:
http {
……
#doc https://github.com/ip2location/ip2location-nginx
# on 为启用,off 为禁用
ip2location on;
#/usr/share/IP2Location/IP2LOCATION-LITE-DB3.BIN 替换成你的 IP2Locaion 数据路径。
ip2location_database /usr/share/IP2Location/IP2LOCATION-LITE-DB3.BIN;
# 可选参数 ip2location_access_type file_io|shared_memory|cache_memory
# 默认为 shared_memory
# 建议不要选择 file_io, 否则可能会严重拖慢响应速度。
ip2location_access_type shared_memory
……
}
官方提供免费版BIN文件下载: https://lite.ip2location.com/ip2location-lite ,根据自己的需要下载对应版本。
编辑 fastcgi_params 文件,在结尾加入以下几行代码(可选):
#IP2Location, with ip2location on;
fastcgi_param IP_COUNTRY_CODE $ip2location_country_short;
fastcgi_param IP_COUNTRY_NAME $ip2location_country_long;
fastcgi_param IP_REGION_NAME $ip2location_region;
fastcgi_param IP_CITY_NAME $ip2location_city;
更多参数查考官方文档:https://github.com/ip2location/ip2location-nginx
启动 nginx 服务
systemctl start nginx
在 phpinfo 信息中可以看到:
当然,也可以在 nginx 中直接使用 $ip2location_country_short,$ip2location_region等变量来实现地区负载均衡。