feat(重构): 新脚本

pull/534/merge
mack-a 2020-05-22 17:36:27 +08:00
parent 948b979b4b
commit 04e27adcff
1 changed files with 110 additions and 38 deletions

View File

@ -40,9 +40,9 @@ echoContent(){
# 安装工具包 # 安装工具包
installTools(){ installTools(){
echo "export LC_ALL=en_US.UTF-8" >> /etc/profile # echo "export LC_ALL=en_US.UTF-8" >> /etc/profile
source /etc/profile # source /etc/profile
echoContent skyBlue "删除Nginx、V2Ray、TLS" echoContent skyBlue "删除Nginx、V2Ray、acme"
if [[ ! -z `find /usr/sbin/ -name nginx` ]] if [[ ! -z `find /usr/sbin/ -name nginx` ]]
then then
if [[ ! -z `ps -ef|grep nginx|grep -v grep` ]] if [[ ! -z `ps -ef|grep nginx|grep -v grep` ]]
@ -51,6 +51,17 @@ installTools(){
fi fi
removeLog=`yum remove nginx -y` removeLog=`yum remove nginx -y`
fi fi
if [[ ! -z `find /usr/bin/v2ray/ -name v2ray` ]]
then
if [[ ! -z `ps -ef|grep v2ray|grep -v grep` ]]
then
ps -ef|grep v2ray|grep -v grep|awk '{print $2}'|xargs kill -9
fi
rm -rf /usr/bin/v2ray/v2ray
rm -rf /usr/bin/v2ray/v2ctl
fi
if [[ ! -z `cat /root/.bashrc|grep -n acme` ]] if [[ ! -z `cat /root/.bashrc|grep -n acme` ]]
then then
acmeBashrcLine=`cat /root/.bashrc|grep -n acme|awk -F "[:]" '{print $1}'|head -1` acmeBashrcLine=`cat /root/.bashrc|grep -n acme|awk -F "[:]" '{print $1}'|head -1`
@ -127,6 +138,10 @@ installNginx(){
} }
# 安装TLS # 安装TLS
installTLS(){ installTLS(){
if [[ -z `find /tmp/tls/$1` ]] || [[ -z `cat /tmp/tls/$1.crt` ]] || [[ -z `cat /tmp/tls/$1.key` ]]
then
rm -rf /tmp/tls
echoContent skyBlue " 生成TLS证书--->" echoContent skyBlue " 生成TLS证书--->"
echoContent skyBlue " 安装acme--->" echoContent skyBlue " 安装acme--->"
curl -s https://get.acme.sh | sh curl -s https://get.acme.sh | sh
@ -143,30 +158,83 @@ installTLS(){
exit 0 exit 0
fi fi
echoContent skyBlue " TLS安装成功--->" echoContent skyBlue " TLS安装成功--->"
mkdir -p /tmp/tls
cp -R /etc/nginx/$1.crt /tmp/tls/$1.crt
cp -R /etc/nginx/$1.key /tmp/tls/$1.key
echoContent skyBlue " TLS证书备份成功证书位置/tmp/tls--->"
else
echoContent skyBlue " 检测到备份证书,如需重新生成,请执行 【rm -rf /tmp/tls】然后重新执行脚本--->"
cp -R /tmp/tls/$1.crt /etc/nginx/$1.crt
cp -R /tmp/tls/$1.key /etc/nginx/$1.key
fi
nginxInstallLine=`cat /etc/nginx/nginx.conf|grep -n "}"|awk -F "[:]" 'END{print $1-1}'`
sed -i "${installLine}i server {listen 443 ssl;server_name $1;root /usr/share/nginx/html;ssl_certificate /etc/nginx/$1.crt;ssl_certificate_key /etc/nginx/$1.key;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_prefer_server_ciphers on;location / {}location /mmtest { proxy_redirect off;proxy_pass http://127.0.0.1:31299;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_set_header X-Real-IP $remote_addr;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}}" /etc/nginx/nginx.conf
nginx
if [[ -z `ps -ef|grep -v grep|grep nginx` ]]
then
echoContent skyBlue " Nginx启动失败请检查日志--->"
fi
echoContent skyBlue " Nginx启动成功TLS配置成功--->"
} }
# V2Ray # V2Ray
installV2Ray(){ installV2Ray(){
if [[ -z `find /tmp/v2ray -name "v2ray"` ]]
then
if [[ -z `find /usr/bin/v2ray/ -name "v2ray"` ]]
then
echoContent skyBlue " 安装V2Ray--->" echoContent skyBlue " 安装V2Ray--->"
version=`curl -s https://github.com/v2ray/v2ray-core/releases|grep /v2ray/v2ray-core/releases/tag/|head -1|awk -F "[/]" '{print $6}'|awk -F "[V]" '{print $2}'|awk -F "[<]" '{print $1}'`
wget -P /tmp/v2ray https://github.com/v2ray/v2ray-core/releases/download/v${version}/v2ray-linux-64.zip
unzip /tmp/v2ray/v2ray-linux-64.zip -d /tmp/v2ray
cp /tmp/v2ray/v2ray /usr/bin/v2ray/ && cp /tmp/v2ray/v2ctl /usr/bin/v2ray/
rm -rf /tmp/v2ray/v2ray-linux-64.zip
fi
echoContent skyBlue " V2Ray安装成功--->"
else
echoContent skyBlue " 检测到V2Ray安装程序如需安装新版本请执行【rm -rf /tmp/v2ray】,然后重新执行脚本--->"
cp /tmp/v2ray/v2ray /usr/bin/v2ray/ && cp /tmp/v2ray/v2ctl /usr/bin/v2ray/
fi
installV2RayService
initV2RayConfig
systemctl enable v2ray
systemctl start v2ray
if [[ -z `ps -ef|grep v2ray|grep -v grep` ]]
then
echoContent skyBlue " V2Ray启动失败请检查日志后重新执行脚本--->"
fi
echoContent skyBlue " V2Ray启动成功--->"
} }
# 开机自启
installV2RayService(){ installV2RayService(){
echoContent skyBlue " 配置V2Ray开机自启--->"
touch /etc/systemd/system/v2ray.sevice
Description=V2Ray - A unified platform for anti-censorship echo 'Description=V2Ray - A unified platform for anti-censorship' >> /etc/systemd/system/v2ray.sevice
Documentation=https://v2ray.com https://guide.v2fly.org echo 'Documentation=https://v2ray.com https://guide.v2fly.org' >> /etc/systemd/system/v2ray.sevice
After=network.target nss-lookup.target echo 'After=network.target nss-lookup.target' >> /etc/systemd/system/v2ray.sevice
Wants=network-online.target echo 'Wants=network-online.target' >> /etc/systemd/system/v2ray.sevice
echo '' >> /etc/systemd/system/v2ray.sevice
[Service] echo '[Service]' >> /etc/systemd/system/v2ray.sevice
Type=simple echo 'Type=simple' >> /etc/systemd/system/v2ray.sevice
User=root echo 'User=root' >> /etc/systemd/system/v2ray.sevice
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_NET_RAW echo 'CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_NET_RAW' >> /etc/systemd/system/v2ray.sevice
NoNewPrivileges=yes echo 'NoNewPrivileges=yes' >> /etc/systemd/system/v2ray.sevice
ExecStart=/usr/bin/v2ray/v2ray -config /etc/v2ray/config.json echo 'ExecStart=/usr/bin/v2ray/v2ray -config /etc/v2ray/config.json' >> /etc/systemd/system/v2ray.sevice
Restart=on-failure echo 'Restart=on-failure' >> /etc/systemd/system/v2ray.sevice
RestartPreventExitStatus=23 echo 'RestartPreventExitStatus=23' >> /etc/systemd/system/v2ray.sevice
echo '' >> /etc/systemd/system/v2ray.sevice
[Install] echo '' >> /etc/systemd/system/v2ray.sevice
WantedBy=multi-user.target echo '[Install]' >> /etc/systemd/system/v2ray.sevice
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/v2ray.sevice
echoContent skyBlue " 配置V2Ray开机自启成功--->"
}
# 初始化V2Ray 配置文件
initV2RayConfig(){
touch /etc/v2ray/config.json
uuid=`/usr/bin/v2ray/v2ctl uuid`
echo '{"log":{"access":"/usr/src/v2ray/v2ray_access_ws_tls.log","error":"/usr/src/v2ray/v2ray_error_ws_tls.log","loglevel":"debug"},"stats":{},"api":{"services":["StatsService"],"tag":"api"},"policy":{"levels":{"1":{"handshake":4,"connIdle":300,"uplinkOnly":2,"downlinkOnly":5,"statsUserUplink":false,"statsUserDownlink":false}},"system":{"statsInboundUplink":true,"statsInboundDownlink":true}},"allocate":{"strategy":"always","refresh":5,"concurrency":3},"inbounds":[{"port":31299,"protocol":"vmess","settings":{"clients":[{"id":"654765fe-5fb1-271f-7c3f-18ed82827f72","alterId":64,"level":1,"email":"test@v2ray.com"}]},"streamSettings":{"network":"ws","wsSettings":{"path":"/alone"}}}],"outbounds":[{"protocol":"freedom","settings":{"OutboundConfigurationObject":{"domainStrategy":"AsIs","userLevel":0}}}],"routing":{"settings":{"rules":[{"inboundTag":["api"],"outboundTag":"api","type":"field"}]},"strategy":"rules"},"dns":{"servers":["8.8.8.8","8.8.4.4"],"tag":"dns_inbound"}}' > /etc/v2ray/config.json
sed -i "s/654765fe-5fb1-271f-7c3f-18ed82827f72/${uuid}/g" `grep 654765fe-5fb1-271f-7c3f-18ed82827f72 -rl /etc/v2ray/config.json`
} }
# 查看dns解析ip # 查看dns解析ip
checkDNS(){ checkDNS(){
@ -211,12 +279,14 @@ init(){
echoContent skyBlue "===============================" echoContent skyBlue "==============================="
echoContent skyBlue "欢迎使用v2ray-agentCloudflare+WS+TLS+Nginx自动化脚本如有使用问题欢迎加入TG群【https://t.me/v2rayAgent】Github【https://github.com/mack-a/v2ray-agent】" echoContent skyBlue "欢迎使用v2ray-agentCloudflare+WS+TLS+Nginx自动化脚本如有使用问题欢迎加入TG群【https://t.me/v2rayAgent】Github【https://github.com/mack-a/v2ray-agent】"
echoContent skyBlue "注意事项:" echoContent skyBlue "注意事项:"
echoContent skyBlue " 1.脚本适合新机器会删除、卸载已经安装的应用包括V2Ray、Nginx、TLS证书" echoContent skyBlue " 1.脚本适合新机器会删除、卸载已经安装的应用包括V2Ray、Nginx"
echoContent skyBlue " 2.脚本会检查并安装工具包" echoContent skyBlue " 2.如果有使用此脚本生成过TLS证书、V2Ray会继续使用旧的。"
echoContent skyBlue " 3.会自动关闭防火墙" echoContent skyBlue " 3.脚本会检查并安装工具包"
echoContent skyBlue " 4.会自动关闭防火墙"
echoContent skyBlue "===============================" echoContent skyBlue "==============================="
installTools installTools
installNginx installNginx
installV2Ray
} }
checkSystem(){ checkSystem(){
if [ -f /etc/redhat-release ]; then if [ -f /etc/redhat-release ]; then
@ -260,3 +330,5 @@ checkSystem(){
#[ ${release} != "debian" ] && [ ${release} != "ubuntu" ] && [ ${release} != "centos" ] && ${echoType} "${Error} 本脚本不支持当前系统 ${release} !" && exit 1 #[ ${release} != "debian" ] && [ ${release} != "ubuntu" ] && [ ${release} != "centos" ] && ${echoType} "${Error} 本脚本不支持当前系统 ${release} !" && exit 1
init init
#progressTool #progressTool
# server {listen 443 ssl;server_name $1;root /usr/share/nginx/html;ssl_certificate /etc/nginx/$1.crt;ssl_certificate_key /etc/nginx/$1.key;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_prefer_server_ciphers on;location / {}location /mmtest { proxy_redirect off;proxy_pass http://127.0.0.1:31299;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_set_header X-Real-IP $remote_addr;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}}