yum安装前置代理
前置代理trojan依赖epel
源
1 2 3 4
| yum install trojan
/etc/trojan/config.json
|
编辑配置文件
如果提示: SSL handshake failed
您需要将配置文件中的 “verify”:true,”verify_hostname”:true, 修改为 false
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
| { "run_type": "client", "local_addr": "127.0.0.1", "local_port": 1080, "remote_addr": "pac.ibm.com", "remote_port": 443, "password": [ "ibm123" ], "log_level": 1, "ssl": { "verify": false, "verify_hostname": false, "cert": "", "cipher": "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:AES128-SHA:AES256-SHA:DES-CBC3-SHA", "cipher_tls13": "TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384", "sni": "", "alpn": [ "h2", "http/1.1" ], "reuse_session": true, "session_ticket": false, "curves": "" }, "tcp": { "no_delay": true, "keep_alive": true, "reuse_port": false, "fast_open": false, "fast_open_qlen": 20 } }
|
ansible安装trojan剧本
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
| --- - hosts: all tasks: - name: install trojan telnet proxychains-ng yum: name: [trojan,telnet,proxychains-ng] state: latest
- name: 拷贝trojan配置文件 template: src: /root/ansible/trojan.json.j2 dest: /etc/trojan/config.json notify: restat trojan
- name: 配置proxychains.conf为127.0.0.1 1080 lineinfile: path: /etc/proxychains.conf regexp: 'socks4 127.0.0.1 9050' line: 'socks5 127.0.0.1 1080'
- name: 启动并开机自启trojan务 service: name: trojan enabled: yes state: started
handlers: - name: restat trojan service: name: trojan state: restarted
|
源码安装前置代理
项目地址: https://github.com/trojan-gfw/trojan/releases
下载安装trojan
1 2 3 4 5 6 7 8
| wget https://ghproxy.com/https://github.com/trojan-gfw/trojan/releases/download/v1.16.0/trojan-1.16.0-linux-amd64.tar.xz
tar xvf trojan-1.16.0-linux-amd64.tar.xz
cd trojan/trojan /usr/bin/
|
创建配置文件
1 2 3
| mkdir -p /etc/trojan && touch /etc/trojan/config.json
|
开机自启service文件
将下列内容写入/usr/lib/systemd/system/trojan.service
文件中
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
| [Unit]
Description=trojan Documentation=man:trojan(1) https://trojan-gfw.github.io/trojan/config https://trojan-gfw.github.io/trojan/
After=network.target network-online.target nss-lookup.target
[Service]
Type=simple StandardError=journal
User=nobody AmbientCapabilities=CAP_NET_BIND_SERVICE
ExecStart=/usr/bin/trojan /etc/trojan/config.json
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=1s
[Install]
WantedBy=multi-user.target
|
配置开机自启动
参考: https://blog.csdn.net/omaidb/article/details/120519191
安装supervisor
1 2 3 4 5 6 7
| wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install -y supervisor
sudo systemctl enable --now supervisord
|
配置trojan开机自启
在/etc/supervisord.d
中创建trojan.ini
文件.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| [program:trojan]
command = /opt/trojan/trojan -c /opt/trojan/trojan/config.json
directory = /opt/trojan/
user = root
stopsignal = INT
autostart = true
autorestart = true
startsecs = 1
stderr_logfile = /var/log/trojan.err.log
stdout_logfile = /var/log/trojan.out.log
|
启动trojan
1 2 3 4 5 6 7
| supervisorctl reread
supervisorctl update
supervisorctl status
|
测试trojan
ansible源码安装trojan剧本
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
| --- - hosts: all tasks: - name: wget tojan get_url: url: https://ghproxy.com/https://github.com/trojan-gfw/trojan/releases/download/v1.16.0/trojan-1.16.0-linux-amd64.tar.xz dest: /root/ - name: mkdir -p /opt file: path: /opt state: directory
- name: 解压文件 shell: tar xvf trojan-1.16.0-linux-amd64.tar.xz -C /opt/ - name: 创建json配置文件 file: path: /opt/trojan/config.json state: file - name: 添加json配置 copy: content: '{{ 从官网复制配置内容 }}' dest: /opt/trojan/config.json
- name: 安装supervisor yum: name: supervisor - name: 启动并开机自启supervisor服务 service: name: supervisord enabled: yes state: started - name: 配置trojan开机自启 copy: src: /root/ansible/trojan.ini dest: /etc/supervisord.d/ - name: 启动trojan shell: 'supervisorctl reread && supervisorctl update'
|
设置临时全局代理
https://zhuanlan.zhihu.com/p/46973701
1 2
| export ALL_PROXY=socks5://127.0.0.1:1080
|