feat(重构): 新脚本
parent
948b979b4b
commit
04e27adcff
118
install_new.sh
118
install_new.sh
|
@ -40,9 +40,9 @@ echoContent(){
|
|||
|
||||
# 安装工具包
|
||||
installTools(){
|
||||
echo "export LC_ALL=en_US.UTF-8" >> /etc/profile
|
||||
source /etc/profile
|
||||
echoContent skyBlue "删除Nginx、V2Ray、TLS"
|
||||
# echo "export LC_ALL=en_US.UTF-8" >> /etc/profile
|
||||
# source /etc/profile
|
||||
echoContent skyBlue "删除Nginx、V2Ray、acme"
|
||||
if [[ ! -z `find /usr/sbin/ -name nginx` ]]
|
||||
then
|
||||
if [[ ! -z `ps -ef|grep nginx|grep -v grep` ]]
|
||||
|
@ -51,6 +51,17 @@ installTools(){
|
|||
fi
|
||||
removeLog=`yum remove nginx -y`
|
||||
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` ]]
|
||||
then
|
||||
acmeBashrcLine=`cat /root/.bashrc|grep -n acme|awk -F "[:]" '{print $1}'|head -1`
|
||||
|
@ -127,6 +138,10 @@ installNginx(){
|
|||
}
|
||||
# 安装TLS
|
||||
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 " 安装acme--->"
|
||||
curl -s https://get.acme.sh | sh
|
||||
|
@ -143,30 +158,83 @@ installTLS(){
|
|||
exit 0
|
||||
fi
|
||||
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
|
||||
installV2Ray(){
|
||||
if [[ -z `find /tmp/v2ray -name "v2ray"` ]]
|
||||
then
|
||||
if [[ -z `find /usr/bin/v2ray/ -name "v2ray"` ]]
|
||||
then
|
||||
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(){
|
||||
echoContent skyBlue " 配置V2Ray开机自启--->"
|
||||
touch /etc/systemd/system/v2ray.sevice
|
||||
|
||||
Description=V2Ray - A unified platform for anti-censorship
|
||||
Documentation=https://v2ray.com https://guide.v2fly.org
|
||||
After=network.target nss-lookup.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_NET_RAW
|
||||
NoNewPrivileges=yes
|
||||
ExecStart=/usr/bin/v2ray/v2ray -config /etc/v2ray/config.json
|
||||
Restart=on-failure
|
||||
RestartPreventExitStatus=23
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
echo 'Description=V2Ray - A unified platform for anti-censorship' >> /etc/systemd/system/v2ray.sevice
|
||||
echo 'Documentation=https://v2ray.com https://guide.v2fly.org' >> /etc/systemd/system/v2ray.sevice
|
||||
echo 'After=network.target nss-lookup.target' >> /etc/systemd/system/v2ray.sevice
|
||||
echo 'Wants=network-online.target' >> /etc/systemd/system/v2ray.sevice
|
||||
echo '' >> /etc/systemd/system/v2ray.sevice
|
||||
echo '[Service]' >> /etc/systemd/system/v2ray.sevice
|
||||
echo 'Type=simple' >> /etc/systemd/system/v2ray.sevice
|
||||
echo 'User=root' >> /etc/systemd/system/v2ray.sevice
|
||||
echo 'CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_NET_RAW' >> /etc/systemd/system/v2ray.sevice
|
||||
echo 'NoNewPrivileges=yes' >> /etc/systemd/system/v2ray.sevice
|
||||
echo 'ExecStart=/usr/bin/v2ray/v2ray -config /etc/v2ray/config.json' >> /etc/systemd/system/v2ray.sevice
|
||||
echo 'Restart=on-failure' >> /etc/systemd/system/v2ray.sevice
|
||||
echo 'RestartPreventExitStatus=23' >> /etc/systemd/system/v2ray.sevice
|
||||
echo '' >> /etc/systemd/system/v2ray.sevice
|
||||
echo '' >> /etc/systemd/system/v2ray.sevice
|
||||
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
|
||||
checkDNS(){
|
||||
|
@ -211,12 +279,14 @@ init(){
|
|||
echoContent skyBlue "==============================="
|
||||
echoContent skyBlue "欢迎使用v2ray-agent,Cloudflare+WS+TLS+Nginx自动化脚本,如有使用问题欢迎加入TG群【https://t.me/v2rayAgent】,Github【https://github.com/mack-a/v2ray-agent】"
|
||||
echoContent skyBlue "注意事项:"
|
||||
echoContent skyBlue " 1.脚本适合新机器,会删除、卸载已经安装的应用,包括V2Ray、Nginx、TLS证书"
|
||||
echoContent skyBlue " 2.脚本会检查并安装工具包"
|
||||
echoContent skyBlue " 3.会自动关闭防火墙"
|
||||
echoContent skyBlue " 1.脚本适合新机器,会删除、卸载已经安装的应用,包括V2Ray、Nginx"
|
||||
echoContent skyBlue " 2.如果有使用此脚本生成过TLS证书、V2Ray,会继续使用旧的。"
|
||||
echoContent skyBlue " 3.脚本会检查并安装工具包"
|
||||
echoContent skyBlue " 4.会自动关闭防火墙"
|
||||
echoContent skyBlue "==============================="
|
||||
installTools
|
||||
installNginx
|
||||
installV2Ray
|
||||
}
|
||||
checkSystem(){
|
||||
if [ -f /etc/redhat-release ]; then
|
||||
|
@ -260,3 +330,5 @@ checkSystem(){
|
|||
#[ ${release} != "debian" ] && [ ${release} != "ubuntu" ] && [ ${release} != "centos" ] && ${echoType} "${Error} 本脚本不支持当前系统 ${release} !" && exit 1
|
||||
init
|
||||
#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;}}
|
||||
|
|
Loading…
Reference in New Issue