通信人家园

 找回密码
 注册

只需一步,快速开始

短信验证,便捷登录

搜索
查看: 2178|回复: 1

[光纤光缆] CentOS7多IPsk5服务器一键搭建脚本 [复制链接]

军衔等级:

  上等兵

注册:2011-3-52
发表于 2024-6-17 11:25:04 |显示全部楼层
CentOS7多IPsk5服务器一键搭建脚本


#!/bin/bash

PORT_NUM=6666; #端口号

USER_IDX=123456 #用户名的数字起始

START_IP=10 #IIP起始

ADD_COUNT=10 #要添加的数量

IP_PREFIX="192.168.0." #IP的固定部分,记得最后一定要有.

DNS1="100.125.0.250" #主DNS

DNS2="114.114.114.114" #备用DNS

GATEWAY0="192.168.0.1" #网关地址

ACCOUNT_FILE="/root/account.txt" #最后生成的账号文件保存目录

USER_NAME_PREFIX="xx" #用户名的前缀部分,可以为空

creat_password()

{

local x=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234356789

#所有密码的可能性是26+26+10=62(0-61是62个数字)

local pass=''

for i in {1..6}

do

num=$[RANDOM%62]

tmp=${x:num:1}

pass=${pass}$tmp



done



echo $pass

}

function add_ip()

{

local file_path="/etc/sysconfig/network-scripts/ifcfg-eth0";

chmod 777 $file_path;

local line_str=$(sed -n '/BOOTPROTO/=' $file_path);

if [ -z "$line_str" ]; then

line=-1;

else

line=$line_str;

fi

# echo $line;

if (( line > -1 )); then

echo "${line}c BOOTPROTO=dhpc13";

sed -i "${line}c BOOTPROTO=none" $file_path > /dev/null;

# else

# echo "没有";

fi

for ((i=0; i < ${ADD_COUNT}; i++))

do

sed -i '/^IPADDR/d' $file_path > /dev/null;

done

sed -i '/^PREFIX/d' $file_path > /dev/null;

sed -i '/^GATEWAY/d' $file_path > /dev/null;

sed -i '/^DNS/d' $file_path > /dev/null;

sed -i '/^DNS/d' $file_path > /dev/null;

# cat $file_path;

for ((i=0, j=${START_IP}; i < ${ADD_COUNT}; i++, j=j+1))

do

#echo "IPADDR$i=192.168.0.$j";

sed -i '$a'"IPADDR$i=$IP_PREFIX$j" $file_path;

done

sed -i '$aPREFIX0=24' $file_path;

sed -i '$aGATEWAY0='$GATEWAY0 $file_path;

sed -i '$aDNS1='$DNS1 $file_path;

sed -i '$aDNS2='$DNS2 $file_path;

# cat $file_path;

}

function get_internet_ip()

{

local accountfile=${ACCOUNT_FILE}

iptables -t mangle -F OUTPUT

for ((i=${START_IP}, j=${USER_IDX}; i < $[ ${START_IP} + ${ADD_COUNT} ]; i++, j=j+1))

do

iptables -t mangle -A OUTPUT -m owner --uid-owner $j -j MARK --set-mark $j

done

iptables -t nat -F POSTROUTING

for ((i=${START_IP}, j=${USER_IDX}; i < $[ ${START_IP} + ${ADD_COUNT} ] ; i++, j=j+1))

do

iptables -t nat -A POSTROUTING -m mark --mark $j -j SNAT --to $IP_PREFIX$i

done

for ((i=${START_IP}, j=${USER_IDX}; i < $[ ${START_IP} + ${ADD_COUNT} ] ; i++, j=j+1))

do

# echo "$USER_NAME_PREFIX$j"

ip=$(sudo -u $USER_NAME_PREFIX$j curl ifconfig.me)

# echo "$ip"

sed -i "s/$IP_PREFIX$i/$ip/g" $accountfile > /dev/null

done

}

install_bbr(){

local path="https://gitee.com/ddsweoerwrw/ss5/raw/master/bbr.sh"

local filename="/root/bbr.sh"

# [ -z "${filename}" ] && filename="$path"

if [ -n "$path" ] && [ ! -f "${filename}" ]; then

wget -q --no-check-certificate ${path} -O ${filename}

fi

# [ -f "${filename}" ] && chmod +x ${filename} && ./${filename}

}

creat_startSs5_file()

{

local filename="/root/startSs5.sh";

:> ${filename};

echo 'CURPATH=$(cd "$(dirname "$0")"; pwd) && cd $CURPATH' >> ${filename}

echo 'killall -9 ss5' >> ${filename}

echo 'mkdir /var/run/ss5/' >> ${filename}

echo 'chmod 777 /var/run/ss5/' >> ${filename}

echo 'iptables -t mangle -F OUTPUT' >> ${filename}

echo 'for ((i='${START_IP}', j='${USER_IDX}'; i < '$[ ${START_IP} + ${ADD_COUNT} ]'; i++, j=j+1))' >> ${filename}

echo 'do' >> ${filename}

echo ' iptables -t mangle -A OUTPUT -m owner --uid-owner $j -j MARK --set-mark $j' >> ${filename}

echo 'done' >> ${filename}

echo 'iptables -t nat -F POSTROUTING' >> ${filename}

echo 'for ((i='${START_IP}', j='${USER_IDX}'; i < '$[ ${START_IP} + ${ADD_COUNT} ]'; i++, j=j+1))' >> ${filename}

echo 'do' >> ${filename}

echo ' iptables -t nat -A POSTROUTING -m mark --mark $j -j SNAT --to '$IP_PREFIX'$i' >> ${filename}

echo 'done' >> ${filename}

echo 'for ((i='${START_IP}', j='${USER_IDX}'; i < '$[ ${START_IP} + ${ADD_COUNT} ]'; i++, j=j+1))' >> ${filename}

echo 'do' >> ${filename}

echo ' ss5 -t -m -b '${IP_PREFIX}'$i:'${PORT_NUM}' -u '$USER_NAME_PREFIX'$j' >> ${filename}

echo 'done' >> ${filename}

echo 'ulimit -SHn 10240' >> ${filename}

echo 'ulimit -SHs unlimited' >> ${filename}

echo 'echo 500000 >/proc/sys/net/nf_conntrack_max' >> ${filename}

}

creat_user_file()

{

local filename="/etc/opt/ss5/ss5.passwd";

local accountfile=${ACCOUNT_FILE}

chmod 777 ${filename}

:> ${filename};

:> ${accountfile}

for ((i=${START_IP}, j=${USER_IDX}; i < $[ ${START_IP} + ${ADD_COUNT} ]; i++, j=j+1))

do

local pw=$(creat_password)

echo "$USER_NAME_PREFIX$j $pw" >> ${filename}

echo "$IP_PREFIX$i/$PORT_NUM/$USER_NAME_PREFIX$j/$pw" >> ${accountfile}

done

}

update_ss5_conf_file()

{

local filename="/etc/opt/ss5/ss5.conf";

chmod 777 ${filename}

sed -i '/^auth/d' ${filename} > /dev/null;

echo 'auth 0.0.0.0/0 - u' >> ${filename}

sed -i '/^permit/d' ${filename} > /dev/null;

echo 'permit u 0.0.0.0/0 - 0.0.0.0/0 - - - - -' >> ${filename}

}

install_new()

{

install_bbr

creat_startSs5_file

if [ ! -f "/root/ss5-3.8.9-8.tar.gz" ];then

wget -q --no-check https://gitee.com/ddsweoerwrw/ss5/raw/master/ss5-3.8.9-8.tar.gz

fi

chmod 777 /root/bbr.sh && /root/bbr.sh && sysctl net.ipv4.tcp_available_congestion_control && sysctl net.ipv4.tcp_congestion_control

yum -y install gcc openldap-devel pam-devel openssl-devel

yum -y install psmisc

tar -vzx -f ss5-3.8.9-8.tar.gz && cd ss5-3.8.9/ && ./configure && make && make install && chmod a+x /etc/init.d/ss5

add_ip

update_ss5_conf_file

creat_user_file



##添加用户

for ((i=${START_IP}, j=${USER_IDX}; i < $[ ${START_IP} + ${ADD_COUNT} ]; i++, j=j+1))

do

/usr/sbin/useradd $USER_NAME_PREFIX$j -u $j -M -s /dev/null

done

chmod 777 /etc/rc.d/rc.local

chmod 777 /root/startSs5.sh

#写入自启文件

echo "/root/startSs5.sh" >> /etc/rc.d/rc.local

#将公网IP写入account.txt

get_internet_ip

cat "/root/account.txt"

reboot

}

install_new

举报本楼

本帖有 1 个回帖,您需要登录后才能浏览 登录 | 注册
您需要登录后才可以回帖 登录 | 注册 |

手机版|C114 ( 沪ICP备12002291号-1 )|联系我们 |网站地图  

GMT+8, 2024-7-19 06:58 , Processed in 0.228195 second(s), 16 queries , Gzip On.

Copyright © 1999-2023 C114 All Rights Reserved

Discuz Licensed

回顶部