-
Notifications
You must be signed in to change notification settings - Fork 27
/
trojan_install_ubuntu.sh
194 lines (178 loc) · 5.09 KB
/
trojan_install_ubuntu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/bash
function blue(){
echo -e "\033[34m\033[01m $1 \033[0m"
}
function green(){
echo -e "\033[32m\033[01m $1 \033[0m"
}
function red(){
echo -e "\033[31m\033[01m $1 \033[0m"
}
function yellow(){
echo -e "\033[33m\033[01m $1 \033[0m"
}
systemctl stop ufw
systemctl disable ufw
sudo apt-get install -y software-properties-common
sudo add-apt-repository -y ppa:greaterfire/trojan
sudo apt-get -y update
sudo apt-get -y install unzip wget curl trojan
sudo apt-get -y install nginx
mkdir /etc/nginx/ssl
green "======================"
green " 输入解析到此VPS的域名"
green "======================"
read domain
cat > /etc/nginx/nginx.conf <<-EOF
user root;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
'\$status \$body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 120;
client_max_body_size 20m;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
EOF
cat > /etc/nginx/conf.d/default.conf<<-EOF
server {
listen 80;
server_name $domain;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
EOF
systemctl restart nginx.service
curl https://get.acme.sh | sh
~/.acme.sh/acme.sh --register-account -m [email protected] --server zerossl
~/.acme.sh/acme.sh --issue -d $domain --webroot /usr/share/nginx/html/
~/.acme.sh/acme.sh --installcert -d $domain \
--key-file /etc/nginx/ssl/$domain.key \
--fullchain-file /etc/nginx/ssl/fullchain.cer \
--reloadcmd "service nginx force-reload"
cd /etc/trojan/
rm -f /etc/trojan/config.json
cat > /etc/trojan/server.conf <<-EOF
{
"run_type": "server",
"local_addr": "0.0.0.0",
"local_port": 443,
"remote_addr": "127.0.0.1",
"remote_port": 80,
"password": [
"password1"
],
"log_level": 1,
"ssl": {
"cert": "/etc/nginx/ssl/fullchain.cer",
"key": "/etc/nginx/ssl/$domain.key",
"key_password": "",
"cipher": "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256",
"prefer_server_cipher": true,
"alpn": [
"h2",
"http/1.1"
],
"reuse_session": true,
"session_ticket": false,
"session_timeout": 600,
"plain_http_response": "",
"curves": "",
"dhparam": ""
},
"tcp": {
"no_delay": true,
"keep_alive": true,
"fast_open": false,
"fast_open_qlen": 20
},
"mysql": {
"enabled": false,
"server_addr": "127.0.0.1",
"server_port": 3306,
"database": "trojan",
"username": "trojan",
"password": ""
}
}
EOF
cat > /etc/nginx/ssl/config.json <<-EOF
{
"run_type": "client",
"local_addr": "127.0.0.1",
"local_port": 1080,
"remote_addr": "$domain",
"remote_port": 443,
"password": [
"password1"
],
"append_payload": true,
"log_level": 1,
"ssl": {
"verify": true,
"verify_hostname": true,
"cert": "fullchain.cer",
"cipher": "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256",
"sni": "",
"alpn": [
"h2",
"http/1.1"
],
"reuse_session": true,
"session_ticket": false,
"curves": ""
},
"tcp": {
"no_delay": true,
"keep_alive": true,
"fast_open": false,
"fast_open_qlen": 20
}
}
EOF
mypassword=$(cat /dev/urandom | head -1 | md5sum | head -c 4)
sed -i "s/password1/$mypassword/" /etc/trojan/server.conf
sed -i "s/password1/$mypassword/" /etc/nginx/ssl/config.json
rm -f /usr/share/nginx/html/*
cd /usr/share/nginx/html
wget https://github.com/xxxbrian/trojan.sh/raw/main/web.zip
unzip web.zip
systemctl restart nginx.service
systemctl enable nginx.service
sudo cat > /etc/init.d/trojanstart <<-EOF
#! /bin/bash
### BEGIN INIT INFO
# Provides: trojanstart
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: trojanstart
### END INIT INFO
nohup trojan -c /etc/trojan/server.conf > /etc/trojan/info.log 2>&1 &
EOF
sudo chmod +x /etc/init.d/trojanstart
sudo update-rc.d trojanstart defaults
nohup trojan -c /etc/trojan/server.conf > /etc/trojan/info.log 2>&1 &
green "===============安装OK==============="
green " 证书文件:/etc/nginx/ssl/fullchain.cer"
green " 客户端配置:/etc/nginx/ssl/config.json"
green " 将以上两个文件传输到客户端trojan文件夹"