Skip to content

Commit

Permalink
Nginx 逻辑修改bug处理
Browse files Browse the repository at this point in the history
  • Loading branch information
wulabing committed Nov 24, 2019
1 parent 8b67458 commit 7167b69
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 87 deletions.
31 changes: 6 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,12 @@
> telegram 交流群:https://t.me/wulabing_v2ray
#### 如果你遇到 PC 端可用,手机不可用的情况,请将手机调至飞行模式后再取消飞行模式,然后尝试连接
### 2019-10-17

> 建议遇到问题的用户重置系统后重新安装

* 变更 添加 Nginx systemd serverfile
* 修复 又双叒叕尝试修复 Nginx 开机自启动问题

### 2019-10-16

* 适配 Centos8 Debian10 Ubuntu19.04
* 修复 部分系统下 计划任务不生效的问题
* 修复 时间同步服务 在 Centos8 下无法安装的错误
* 修复 部分系统下 证书不会自动更新的问题
* 修复 部分系统下 Nginx 开机自启配置失效的问题
* 变更 重复安装时,将不对相同的域名进行重复的证书申请,防止出现 Let's encrypt API 次数限制
* 变更 默认 alterID 64 -> 4 ,减少资源占用
* 变更 nginx 安装方式从源获取 变更为 编译安装,并使用新版Openssl,支持tls1.3
* 变更 nginx 配置文件 ssl_protocols ssl_ciphers,适配 tls1.3
* 变更 取消对Debian8 Ubuntu 16.04 的适配工作(本版本可能依旧可用)
* 变更 默认页面伪装为 html5 小游戏
* 新增 安装完成,节点配置信息留档
* 新增 使用自定义证书
* 新增 链接方式导入导入
* 新增 二维码方式导入
### 2019-11-24

* 更新 伪装页面从小游戏变更为3D元素周期表
* 更新 主版本代码合并至h2版本
* 优化 重复安装不会再次编译Nginx


### 使用自定义证书
将crt和key文件命名为v2ray.crt v2ray.key 放在 /data 目录下(若目录不存在请先建目录)
Expand Down
28 changes: 14 additions & 14 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ domain_check(){
echo -e "本机IP: ${local_ip}"
sleep 2
if [[ $(echo ${local_ip}|tr '.' '+'|bc) -eq $(echo ${domain_ip}|tr '.' '+'|bc) ]];then
echo -e "${OK} ${GreenBG} 域名dns解析IP 与 本机IP 匹配 ${Font}"
echo -e "${OK} ${GreenBG} 域名dns解析IP 与 本机IP 匹配 ${Font}"
sleep 2
else
echo -e "${Error} ${RedBG} 请确保域名添加了正确的 A 记录,否则将无法正常使用 V2ray"
Expand Down Expand Up @@ -441,19 +441,19 @@ acme_cron_update(){

vmess_qr_config(){
cat >/etc/v2ray/vmess_qr.json <<-EOF
{
"v": "2",
"ps": "wulabing_${domain}",
"add": "${domain}",
"port": "${port}",
"id": "${UUID}",
"aid": "${alterID}",
"net": "ws",
"type": "none",
"host": "${domain}",
"path": "/${camouflage}/",
"tls": "tls"
}
{
"v": "2",
"ps": "wulabing_${domain}",
"add": "${domain}",
"port": "${port}",
"id": "${UUID}",
"aid": "${alterID}",
"net": "ws",
"type": "none",
"host": "${domain}",
"path": "/${camouflage}/",
"tls": "tls"
}
EOF

vmess_link="vmess://$(cat /etc/v2ray/vmess_qr.json | base64 -w 0)"
Expand Down
197 changes: 149 additions & 48 deletions install_h2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,27 @@ source /etc/os-release
VERSION=`echo ${VERSION} | awk -F "[()]" '{print $2}'`

check_system(){

if [[ "${ID}" == "centos" && ${VERSION_ID} -ge 7 ]];then
echo -e "${OK} ${GreenBG} 当前系统为 Centos ${VERSION_ID} ${VERSION} ${Font} "
echo -e "${OK} ${GreenBG} 当前系统为 Centos ${VERSION_ID} ${VERSION} ${Font}"
INS="yum"
elif [[ "${ID}" == "debian" && ${VERSION_ID} -ge 8 ]];then
echo -e "${OK} ${GreenBG} 当前系统为 Debian ${VERSION_ID} ${VERSION} ${Font} "
echo -e "${OK} ${GreenBG} 当前系统为 Debian ${VERSION_ID} ${VERSION} ${Font}"
INS="apt"
$INS update
## 添加 Nginx apt源
elif [[ "${ID}" == "ubuntu" && `echo "${VERSION_ID}" | cut -d '.' -f1` -ge 16 ]];then
echo -e "${OK} ${GreenBG} 当前系统为 Ubuntu ${VERSION_ID} ${VERSION_CODENAME} ${Font} "
echo -e "${OK} ${GreenBG} 当前系统为 Ubuntu ${VERSION_ID} ${UBUNTU_CODENAME} ${Font}"
INS="apt"
$INS update
else
echo -e "${Error} ${RedBG} 当前系统为 ${ID} ${VERSION_ID} 不在支持的系统列表内,安装中断 ${Font} "
echo -e "${Error} ${RedBG} 当前系统为 ${ID} ${VERSION_ID} 不在支持的系统列表内,安装中断 ${Font}"
exit 1
fi

systemctl stop firewalld && systemctl disable firewalld
echo -e "${OK} ${GreenBG} firewalld 已关闭 ${Font}"
}

is_root(){
if [ `id -u` == 0 ]
then echo -e "${OK} ${GreenBG} 当前用户是root用户,进入安装流程 ${Font} "
Expand All @@ -69,51 +74,106 @@ judge(){
exit 1
fi
}
ntpdate_install(){

# 旧版本遗弃代码

#ntpdate_install(){
# if [[ "${ID}" == "centos" ]];then
# ${INS} install ntpdate -y
# else
# ${INS} update
# ${INS} install ntpdate -y
# fi
# judge "安装 NTPdate 时间同步服务 "
#}
#time_modify(){
#
# ntpdate_install
#
# systemctl stop ntp &>/dev/null
#
# echo -e "${Info} ${GreenBG} 正在进行时间同步 ${Font}"
# ntpdate time.nist.gov
#
# if [[ $? -eq 0 ]];then
# echo -e "${OK} ${GreenBG} 时间同步成功 ${Font}"
# echo -e "${OK} ${GreenBG} 当前系统时间 `date -R`(请注意时区间时间换算,换算后时间误差应为三分钟以内)${Font}"
# sleep 1
# else
# echo -e "${Error} ${RedBG} 时间同步失败,请检查ntpdate服务是否正常工作 ${Font}"
# fi
#}

chrony_install(){
${INS} -y install chrony
judge "安装 chrony 时间同步服务 "

timedatectl set-ntp true

if [[ "${ID}" == "centos" ]];then
${INS} install ntpdate -y
systemctl enable chronyd && systemctl restart chronyd
else
${INS} update
${INS} install ntpdate -y
systemctl enable chrony && systemctl restart chrony
fi
judge "安装 NTPdate 时间同步服务 "
}
time_modify(){

ntpdate_install
judge "chronyd 启动 "

systemctl stop ntp &>/dev/null
timedatectl set-timezone Asia/Shanghai

echo -e "${Info} ${GreenBG} 正在进行时间同步 ${Font}"
ntpdate time.nist.gov
echo -e "${OK} ${GreenBG} 等待时间同步 ${Font}"
sleep 10

if [[ $? -eq 0 ]];then
echo -e "${OK} ${GreenBG} 时间同步成功 ${Font}"
echo -e "${OK} ${GreenBG} 当前系统时间 `date -R`(请注意时区间时间换算,换算后时间误差应为三分钟以内)${Font}"
sleep 1
else
echo -e "${Error} ${RedBG} 时间同步失败,请检查ntpdate服务是否正常工作 ${Font}"
fi
chronyc sourcestats -v
chronyc tracking -v
date
read -p "请确认时间是否准确,误差范围±3分钟(Y/N): " chrony_install
[[ -z ${chrony_install} ]] && chrony_install="Y"
case $chrony_install in
[yY][eE][sS]|[yY])
echo -e "${GreenBG} 继续安装 ${Font}"
sleep 2
;;
*)
echo -e "${RedBG} 安装终止 ${Font}"
exit 2
;;
esac
}

dependency_install(){
${INS} install wget lsof -y
${INS} install wget git lsof -y

if [[ "${ID}" == "centos" ]];then
${INS} -y install crontabs
else
${INS} install cron
${INS} -y install cron
fi
judge "安装 crontab"

# 新版的IP判定不需要使用net-tools
# ${INS} install net-tools -y
# judge "安装 net-tools"
if [[ "${ID}" == "centos" ]];then
touch /var/spool/cron/root && chmod 600 /var/spool/cron/root
systemctl start crond && systemctl enable crond
else
touch /var/spool/cron/crontabs/root && chmod 600 /var/spool/cron/crontabs/root
systemctl start cron && systemctl enable cron

${INS} install bc -y
fi
judge "crontab 自启动配置 "



${INS} -y install bc
judge "安装 bc"

${INS} install unzip -y
${INS} -y install unzip
judge "安装 unzip"

${INS} -y install qrencode
judge "安装 qrencode"

${INS} -y install dbus
judge "安装 dbus"

}
port_alterid_set(){
stty erase '^H' && read -p "请输入连接端口(default:443):" port
Expand Down Expand Up @@ -173,7 +233,7 @@ domain_check(){
echo -e "本机IP: ${local_ip}"
sleep 2
if [[ $(echo ${local_ip}|tr '.' '+'|bc) -eq $(echo ${domain_ip}|tr '.' '+'|bc) ]];then
echo -e "${OK} ${GreenBG} 域名dns解析IP 与 本机IP 匹配 ${Font}"
echo -e "${OK} ${GreenBG} 域名dns解析IP 与 本机IP 匹配 ${Font}"
sleep 2
else
echo -e "${Error} ${RedBG} 域名dns解析IP 与 本机IP 不匹配 是否继续安装?(y/n)${Font}" && read install
Expand Down Expand Up @@ -220,8 +280,11 @@ acme(){
fi
}
start_process_systemd(){
systemctl start v2ray
systemctl restart v2ray
judge "V2ray 启动"

systemctl enable v2ray
judge "设置 v2ray 开机自启"
}

v2ray_conf_add(){
Expand All @@ -240,29 +303,67 @@ v2ray_conf_add(){
json_addr=`curl --upload-file ${client_conf} https://transfer.sh/wulabing_${camouflage}_${UUID}.json`
}

vmess_qr_config(){
cat >/etc/v2ray/vmess_qr.json <<-EOF
{
"v": "2",
"ps": "wulabing_${domain}",
"add": "${domain}",
"port": "${port}",
"id": "${UUID}",
"aid": "${alterID}",
"net": "h2",
"type": "none",
"tls": "tls"
}
EOF

vmess_link="vmess://$(cat /etc/v2ray/vmess_qr.json | base64 -w 0)"
echo -e "${Red} URL导入链接:${vmess_link} ${Font}" >>./v2ray_info.txt
echo -e "${Red} 二维码: ${Font}" >>./v2ray_info.txt
echo "${vmess_link}"| qrencode -o - -t utf8 >>./v2ray_info.txt
}

show_information(){
clear

echo -e "${OK} ${Green} V2ray http2 over tls 安装成功 "
echo -e "${Red} V2ray 配置信息 ${Font}"
echo -e "${Red} 地址(address):${Font} ${domain} "
echo -e "${Red} 端口(port):${Font} ${port} "
echo -e "${Red} 用户id(UUID):${Font} ${UUID}"
echo -e "${Red} 额外id(alterId):${Font} ${alterID}"
echo -e "${Red} 加密方式(security):${Font} 自适应 "
echo -e "${Red} 传输协议(network):${Font} h2 "
echo -e "${Red} 伪装类型(type):${Font} none "
echo -e "${Red} 伪装域名(不要落下/):${Font} /${camouflage}/ "
echo -e "${Red} 底层传输安全:${Font} tls "
echo -e "${OK} ${GreenBG} 请注意,目前的GUI客户端(V2rayN)已经支持H2手动添加配置,当然您也可以通过 添加自定义配置 添加节点信息 ${Font}"
echo -e "${OK} ${GreenBG} 配置地址(方便下载): ${json_addr} ${Font}"
echo -e "${OK} ${GreenBG} 配置地址(服务器本地备份):/etc/v2ray/client.json ${Font}"
echo -e "${OK} ${Green} V2ray http2 over tls 安装成功 " >./v2ray_info.txt
echo -e "${Red} V2ray 配置信息 ${Font}" >>./v2ray_info.txt
echo -e "${Red} 地址(address):${Font} ${domain} " >>./v2ray_info.txt
echo -e "${Red} 端口(port):${Font} ${port} " >>./v2ray_info.txt
echo -e "${Red} 用户id(UUID):${Font} ${UUID}" >>./v2ray_info.txt
echo -e "${Red} 额外id(alterId):${Font} ${alterID}" >>./v2ray_info.txt
echo -e "${Red} 加密方式(security):${Font} 自适应 " >>./v2ray_info.txt
echo -e "${Red} 传输协议(network):${Font} h2 " >>./v2ray_info.txt
echo -e "${Red} 伪装类型(type):${Font} none " >>./v2ray_info.txt
echo -e "${Red} 伪装域名(不要落下/):${Font} /${camouflage}/ " >>./v2ray_info.txt
echo -e "${Red} 底层传输安全:${Font} tls " >>./v2ray_info.txt
echo -e "${OK} ${GreenBG} 配置地址(方便下载): ${json_addr} ${Font}" >>./v2ray_info.txt
echo -e "${OK} ${GreenBG} 配置地址(服务器本地备份):/etc/v2ray/client.json ${Font}" >>./v2ray_info.txt
vmess_qr_config
cat ./v2ray_info.txt

}



ssl_judge_and_install(){
if [[ -f "/data/v2ray.key" && -f "/data/v2ray.crt" ]];then
echo "证书文件已存在"
elif [[ -f "~/.acme.sh/${domain}_ecc/${domain}.key" && -f "~/.acme.sh/${domain}_ecc/${domain}.cer" ]];then
echo "证书文件已存在"
~/.acme.sh/acme.sh --installcert -d ${domain} --fullchainpath /data/v2ray.crt --keypath /data/v2ray.key --ecc
judge "证书应用"
else
ssl_install
acme
fi
}

main(){
is_root
check_system
time_modify
chrony_install
dependency_install
domain_check
port_alterid_set
Expand All @@ -271,7 +372,7 @@ main(){
v2ray_conf_add

#将证书生成放在最后,尽量避免多次尝试脚本从而造成的多次证书申请
ssl_install
ssl_judge_and_install
acme

show_information
Expand Down

0 comments on commit 7167b69

Please sign in to comment.