Skip to content

Commit fc1cab5

Browse files
committed
Update.
1 parent 21d0402 commit fc1cab5

File tree

1 file changed

+54
-14
lines changed

1 file changed

+54
-14
lines changed

Snell.sh

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ export PATH
66
# System Required: CentOS/Debian/Ubuntu
77
# Description: Snell Server 管理脚本
88
# Author: 翠花
9-
# WebSite: https://about.nange.cn
9+
# WebSite: https://about.aapls.com
1010
#=================================================
1111

12-
sh_ver="1.8.4"
12+
sh_ver="1.8.5"
1313
snell_v2_version="2.0.6"
1414
snell_v3_version="3.0.1"
1515
snell_v4_version="4.1.1"
16-
snell_v5_version="5.0.0"
16+
snell_v5_version="5.0.1"
1717
script_dir=$(cd "$(dirname "$0")"; pwd)
1818
script_path=$(echo -e "${script_dir}"|awk -F "$0" '{print $1}')
1919
snell_dir="/etc/snell/"
2020
snell_bin="/usr/local/bin/snell-server"
2121
snell_conf="/etc/snell/config.conf"
2222
snell_version_file="/etc/snell/ver.txt"
23-
sysctl_conf="/etc/sysctl.d/local.conf"
23+
sysctl_conf="/etc/sysctl.d/99-snell.conf"
2424

2525
Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m" && Yellow_font_prefix="\033[0;33m"
2626
Info="${Green_font_prefix}[信息]${Font_color_suffix}"
@@ -104,13 +104,19 @@ enableTCPFastOpen() {
104104
kernel=$(uname -r | awk -F . '{print $1}')
105105
if [ "$kernel" -ge 3 ]; then
106106
echo 3 >/proc/sys/net/ipv4/tcp_fastopen
107-
[[ ! -e $sysctl_conf ]] && echo "fs.file-max = 51200
107+
# 创建或覆盖 Snell 专用的 sysctl 配置文件
108+
cat > "$sysctl_conf" << EOF
109+
# Snell Server 网络优化配置
110+
# 由 Snell 管理脚本自动生成
111+
112+
fs.file-max = 51200
108113
net.core.rmem_max = 67108864
109114
net.core.wmem_max = 67108864
110115
net.core.rmem_default = 65536
111116
net.core.wmem_default = 65536
112117
net.core.netdev_max_backlog = 4096
113118
net.core.somaxconn = 4096
119+
114120
net.ipv4.tcp_syncookies = 1
115121
net.ipv4.tcp_tw_reuse = 1
116122
net.ipv4.tcp_tw_recycle = 0
@@ -123,11 +129,17 @@ net.ipv4.tcp_fastopen = 3
123129
net.ipv4.tcp_rmem = 4096 87380 67108864
124130
net.ipv4.tcp_wmem = 4096 65536 67108864
125131
net.ipv4.tcp_mtu_probing = 1
126-
net.ipv4.tcp_ecn=1
127-
net.core.default_qdisc=fq
128-
net.ipv4.tcp_congestion_control = bbr" >>/etc/sysctl.d/local.conf && sysctl --system >/dev/null 2>&1
132+
net.ipv4.tcp_ecn = 1
133+
134+
# BBR 拥塞控制
135+
net.core.default_qdisc = fq
136+
net.ipv4.tcp_congestion_control = bbr
137+
EOF
138+
# 应用配置
139+
sysctl --system >/dev/null 2>&1
140+
echo -e "${Info} TCP Fast Open 和网络优化配置已启用!"
129141
else
130-
echo -e "$Error 系统内核版本过低,无法支持 TCP Fast Open!"
142+
echo -e "${Error} 系统内核版本过低,无法支持 TCP Fast Open!"
131143
fi
132144
}
133145

@@ -438,8 +450,7 @@ setupService(){
438450
echo '
439451
[Unit]
440452
Description=Snell Service
441-
After=network-online.target
442-
Wants=network-online.target systemd-networkd-wait-online.service
453+
After=network.target
443454
[Service]
444455
LimitNOFILE=32767
445456
Type=simple
@@ -450,7 +461,8 @@ ExecStartPre=/bin/sh -c 'ulimit -n 51200'
450461
ExecStart=/usr/local/bin/snell-server -c /etc/snell/config.conf
451462
[Install]
452463
WantedBy=multi-user.target' > /etc/systemd/system/snell-server.service
453-
systemctl enable --now snell-server
464+
systemctl daemon-reload
465+
systemctl enable snell-server
454466
echo -e "${Info} Snell Server 服务配置完成!"
455467
}
456468

@@ -825,12 +837,30 @@ startSnell(){
825837
if [[ "$status" == "running" ]]; then
826838
echo -e "${Info} Snell Server 已在运行!"
827839
else
840+
echo -e "${Info} 正在启动 Snell Server..."
828841
systemctl start snell-server
842+
843+
# 等待启动完成,最多等待5秒
844+
local timeout=5
845+
local elapsed=0
846+
while [[ $elapsed -lt $timeout ]]; do
847+
sleep 1
848+
checkStatus
849+
if [[ "$status" == "running" ]]; then
850+
echo -e "${Info} Snell Server 启动成功!"
851+
return 0
852+
fi
853+
((elapsed++))
854+
done
855+
856+
# 如果5秒后仍未启动,检查状态并报错
829857
checkStatus
830858
if [[ "$status" == "running" ]]; then
831859
echo -e "${Info} Snell Server 启动成功!"
832860
else
833861
echo -e "${Error} Snell Server 启动失败!"
862+
echo -e "${Error} 请使用 'systemctl status snell-server' 查看详细错误信息"
863+
journalctl -u snell-server -n 20 --no-pager
834864
exit 1
835865
fi
836866
fi
@@ -1263,11 +1293,21 @@ uninstallSnell(){
12631293
read -e -p "(默认: n):" unyn
12641294
[[ -z ${unyn} ]] && unyn="n"
12651295
if [[ ${unyn} == [Yy] ]]; then
1296+
echo -e "${Info} 停止并禁用服务..."
12661297
systemctl stop snell-server
1267-
systemctl disable snell-server
1298+
systemctl disable snell-server
1299+
12681300
echo -e "${Info} 移除主程序..."
12691301
rm -rf "${snell_bin}"
1270-
echo -e "${Info} 配置文件暂保留..."
1302+
1303+
echo -e "${Info} 移除 systemd 服务文件..."
1304+
rm -f /etc/systemd/system/snell-server.service
1305+
systemctl daemon-reload
1306+
1307+
echo -e "${Info} 移除网络优化配置..."
1308+
rm -f "${sysctl_conf}"
1309+
1310+
echo -e "${Info} 配置文件保留在 ${snell_conf},如需完全删除请手动执行: rm -rf /etc/snell"
12711311
echo && echo "Snell Server 卸载完成!" && echo
12721312
else
12731313
echo && echo "卸载已取消..." && echo

0 commit comments

Comments
 (0)