Commit d2753c88 authored by nanahira's avatar nanahira

update

parent eb7ce07d
[defaults] [defaults]
host_key_checking = False host_key_checking = False
strategy_plugins = mitogen-0.2.9/ansible_mitogen/plugins/strategy strategy_plugins = mitogen-0.2.9/ansible_mitogen/plugins/strategy
strategy = mitogen_linear strategy = mitogen_free
\ No newline at end of file
...@@ -13,11 +13,18 @@ ...@@ -13,11 +13,18 @@
dest: '/etc/wireguard/predown.sh' dest: '/etc/wireguard/predown.sh'
mode: a+x mode: a+x
# 为了提高测试时候的性能,不改动wg的时候注释掉这段 # 为了提高测试时候的性能,不改动wg的时候注释掉这段
#- name: 'clean up null connections first'
# include_tasks: 'protocols/{{item.protocol}}/configure.yaml'
# vars:
# conn: '{{item}}'
# with_items: '{{ connections }}'
# when: "item.protocol == 'null'"
- name: 'loop through list from a variable' - name: 'loop through list from a variable'
include_tasks: 'protocols/{{item.protocol}}/configure.yaml' include_tasks: 'protocols/{{item.protocol}}/configure.yaml'
vars: vars:
conn: '{{item}}' conn: '{{item}}'
with_items: '{{ connections }}' with_items: '{{ connections }}'
# when: "item.protocol != 'null'"
- name: 'frps' - name: 'frps'
include_tasks: 'protocols/wgfrp/frps.yaml' include_tasks: 'protocols/wgfrp/frps.yaml'
when: 'frps_needed is defined' when: 'frps_needed is defined'
......
- name: stop - name: '{{conn.name}}: stop frpc'
ignore_errors: true
systemd: systemd:
name: '{{item}}@{{conn.name}}' name: 'frpc@{{conn.name}}'
state: stopped state: stopped
enabled: no enabled: no
with_items: - name: '{{conn.name}}: stop wireguard'
- wg-quick ignore_errors: true
- frpc systemd:
- name: remove config files name: 'wg-quick@{{conn.name}}'
state: stopped
enabled: no
- name: '{{conn.name}}: remove wg config files'
file:
path: '/etc/wireguard/{{conn.name}}.conf'
state: absent
- name: '{{conn.name}}: remove frpc config files'
file: file:
path: '/etc/{{item}}/{{conn.name}}.conf' path: '/etc/frpc/{{conn.name}}.conf'
state: absent state: absent
with_items:
- wireguard
- frp
# 因为测试期间频繁改动参数,这里手动down掉 # 因为测试期间频繁改动参数,这里手动down掉
# 调试wg的时候开这个,调试别的的时候注释掉 # 调试wg的时候开这个,调试别的的时候注释掉
- name: clean frp service - name: '{{conn.name}}: clean frp service'
ignore_errors: true
systemd: systemd:
name: '{{item}}@{{conn.name}}' name: 'frpc@{{conn.name}}'
state: stopped state: stopped
enabled: no enabled: no
with_items: - name: '{{conn.name}}: clean frp'
- frpc
- name: clean frp
file: file:
path: '/etc/{{item}}/{{conn.name}}.conf' path: '/etc/frp/{{conn.name}}.conf'
state: absent state: absent
with_items: - name: '{{conn.name}}: wg conf'
- frp
- name: conf
template: template:
src: wg.conf.j2 src: wg.conf.j2
dest: '/etc/wireguard/{{conn.name}}.conf' dest: '/etc/wireguard/{{conn.name}}.conf'
- name: enable - name: '{{conn.name}}: enable wg'
systemd: systemd:
name: 'wg-quick@{{conn.name}}' name: 'wg-quick@{{conn.name}}'
state: started state: started
enabled: yes enabled: yes
#ignore_errors: true
register: 'wg_enable_result' register: 'wg_enable_result'
- name: config for setconf - name: '{{conn.name}}: config for setconf'
template: template:
src: wg-setconf.conf.j2 src: wg-setconf.conf.j2
dest: '/tmp/{{conn.name}}-setconf.conf' dest: '/tmp/{{conn.name}}-setconf.conf'
register: 'wg_setconf_result' register: 'wg_setconf_result'
when: 'not wg_enable_result.changed' when: 'not wg_enable_result.changed'
- name: setconf - name: '{{conn.name}}: wg setconf'
shell: 'wg setconf {{conn.name}} /tmp/{{conn.name}}-setconf.conf' shell: 'wg setconf {{conn.name}} /tmp/{{conn.name}}-setconf.conf'
when: 'not wg_enable_result.changed and wg_setconf_result.changed' when: 'not wg_enable_result.changed and wg_setconf_result.changed'
...@@ -5,9 +5,14 @@ ListenPort = {{conn.localPort}} ...@@ -5,9 +5,14 @@ ListenPort = {{conn.localPort}}
{% if gwmark is defined %} {% if gwmark is defined %}
FwMark = {{conn.localGatewayMark}} FwMark = {{conn.localGatewayMark}}
{% endif %} {% endif %}
{% if conn.mtu is defined %}
MTU = {{conn.mtu}}
{% endif %}
Table = off Table = off
PostUp = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remoteMark={{conn.remoteMark}} inbound={{conn.inbound}} outbound={{conn.outbound}} {% if conn.mtu is defined %}mtu={{conn.mtu}}{% endif %} /etc/wireguard/postup.sh PostUp = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remoteMark={{conn.remoteMark}} inbound={{conn.inbound}} outbound={{conn.outbound}} {% if conn.mtu is defined %}mtu={{conn.mtu}}{% endif %} /etc/wireguard/postup.sh
PreDown = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remoteMark={{conn.remoteMark}} inbound={{conn.inbound}} outbound={{conn.outbound}} {% if conn.mtu is defined %}mtu={{conn.mtu}}{% endif %} /etc/wireguard/predown.sh PreDown = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remoteMark={{conn.remoteMark}} inbound={{conn.inbound}} outbound={{conn.outbound}} {% if conn.mtu is defined %}mtu={{conn.mtu}}{% endif %} /etc/wireguard/predown.sh
[Peer] [Peer]
PublicKey = {{conn.wgPublicKey}} PublicKey = {{conn.wgPublicKey}}
AllowedIPs = 0.0.0.0/0, ::/0 AllowedIPs = 0.0.0.0/0, ::/0
......
# frpc # frpc
- name: frpc template - name: '{{conn.name}}: frpc template'
template: template:
src: 'frpc.ini.j2' src: 'frpc.ini.j2'
dest: '/etc/frp/{{conn.name}}.ini' dest: '/etc/frp/{{conn.name}}.ini'
when: 'conn.frpType == "frpc"' when: 'conn.frpType == "frpc"'
register: frpc_config_result register: frpc_config_result
- name: start frpc - name: '{{conn.name}}: start frpc'
systemd: systemd:
name: 'frpc@{{conn.name}}' name: 'frpc@{{conn.name}}'
state: started state: started
enabled: true enabled: true
register: frpc_launch_result register: frpc_launch_result
when: 'conn.frpType == "frpc"' when: 'conn.frpType == "frpc"'
- name: reload frpc - name: '{{conn.name}}: restart frpc'
systemd: systemd:
name: 'frpc@{{conn.name}}' name: 'frpc@{{conn.name}}'
state: reloaded state: restarted
when: 'conn.frpType == "frpc" and frpc_config_result.changed and not frpc_launch_result.changed' when: 'conn.frpType == "frpc" and frpc_config_result.changed and not frpc_launch_result.changed'
# frps # frps
- name: register frps - name: '{{conn.name}}: register frps'
set_fact: set_fact:
frps_needed: 1 frps_needed: 1
when: 'conn.frpType == "frps"' when: 'conn.frpType == "frps"'
# wg # wg
- name: wg conf - name: '{{conn.name}}: wg conf'
template: template:
src: wgfrp.conf.j2 src: wgfrp.conf.j2
dest: '/etc/wireguard/{{conn.name}}.conf' dest: '/etc/wireguard/{{conn.name}}.conf'
- name: enable - name: '{{conn.name}}: start wg'
systemd: systemd:
name: 'wg-quick@{{conn.name}}' name: 'wg-quick@{{conn.name}}'
state: started state: started
enabled: yes enabled: yes
#ignore_errors: true
register: wg_enable_result register: wg_enable_result
- name: config for setconf - name: '{{conn.name}}: config for setconf'
template: template:
src: wgfrp-setconf.conf.j2 src: wgfrp-setconf.conf.j2
dest: '/tmp/{{conn.name}}-setconf.conf' dest: '/tmp/{{conn.name}}-setconf.conf'
register: 'wg_setconf_result' register: 'wg_setconf_result'
when: 'not wg_enable_result.changed' when: 'not wg_enable_result.changed'
- name: setconf - name: '{{conn.name}}: wg setconf'
shell: 'wg setconf {{conn.name}} /tmp/{{conn.name}}-setconf.conf' shell: 'wg setconf {{conn.name}} /tmp/{{conn.name}}-setconf.conf'
when: 'not wg_enable_result.changed and wg_setconf_result.changed' when: 'not wg_enable_result.changed and wg_setconf_result.changed'
...@@ -5,11 +5,11 @@ tcp_mux = true ...@@ -5,11 +5,11 @@ tcp_mux = true
protocol = tcp protocol = tcp
token = {{frpToken}} token = {{frpToken}}
[{{ansible_hostname_short}}_{{conn.name}}] [{{ansible_hostname}}_{{conn.name}}]
privilege_mode = true privilege_mode = true
type = udp type = udp
local_ip = 127.0.0.1 local_ip = 127.0.0.1
local_port = {{conn.localPort}} local_port = {{conn.remotePort}}
remote_port = {{conn.localPort}} remote_port = {{conn.remotePort|int - 1000}}
use_encryption = true use_encryption = true
use_compression = true use_compression = true
[common] [common]
bind_port = {{frps_port}} bind_port = {{frpsPort}}
token = {{frpToken}} token = {{frpToken}}
tcp_mux = true tcp_mux = true
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
state: started state: started
enabled: true enabled: true
register: frps_launch_result register: frps_launch_result
- name: start frps - name: restart frps
systemd: systemd:
name: 'frps' name: 'frps'
state: reloaded state: restarted
when: 'frps_config_result.changed and not frps_launch_result.changed' when: 'frps_config_result.changed and not frps_launch_result.changed'
...@@ -2,11 +2,14 @@ ...@@ -2,11 +2,14 @@
Address = {{address}} Address = {{address}}
PrivateKey = {{key}} PrivateKey = {{key}}
{% if conn.frpType == "frpc" %} {% if conn.frpType == "frpc" %}
ListenPort = {{conn.localPort}} ListenPort = {{conn.remotePort}}
{% endif %} {% endif %}
{% if gwmark is defined %} {% if gwmark is defined %}
FwMark = {{conn.localGatewayMark}} FwMark = {{conn.localGatewayMark}}
{% endif %} {% endif %}
{% if conn.mtu is defined %}
MTU = {{conn.mtu}}
{% endif %}
Table = off Table = off
PostUp = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remoteMark={{conn.remoteMark}} inbound={{conn.inbound}} outbound={{conn.outbound}} {% if conn.mtu is defined %}mtu={{conn.mtu}}{% endif %} /etc/wireguard/postup.sh PostUp = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remoteMark={{conn.remoteMark}} inbound={{conn.inbound}} outbound={{conn.outbound}} {% if conn.mtu is defined %}mtu={{conn.mtu}}{% endif %} /etc/wireguard/postup.sh
PreDown = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remoteMark={{conn.remoteMark}} inbound={{conn.inbound}} outbound={{conn.outbound}} {% if conn.mtu is defined %}mtu={{conn.mtu}}{% endif %} /etc/wireguard/predown.sh PreDown = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{conn.remotePeerAddress}} remoteMark={{conn.remoteMark}} inbound={{conn.inbound}} outbound={{conn.outbound}} {% if conn.mtu is defined %}mtu={{conn.mtu}}{% endif %} /etc/wireguard/predown.sh
...@@ -14,6 +17,6 @@ PreDown = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{ ...@@ -14,6 +17,6 @@ PreDown = dev=%i localPeerAddress={{conn.localPeerAddress}} remotePeerAddress={{
PublicKey = {{conn.wgPublicKey}} PublicKey = {{conn.wgPublicKey}}
AllowedIPs = 0.0.0.0/0, ::/0 AllowedIPs = 0.0.0.0/0, ::/0
{% if conn.frpType == "frps" %} {% if conn.frpType == "frps" %}
Endpoint = 127.0.0.1:{{conn.remotePort}} Endpoint = 127.0.0.1:{{conn.localPort|int - 1000}}
PersistentKeepalive = 1 PersistentKeepalive = 1
{% endif %} {% endif %}
#!/usr/bin/env bash #!/usr/bin/env bash
set -e #set -e
ip addr add "$localPeerAddress" peer "$remotePeerAddress" dev "$dev" scope link ip addr add "$localPeerAddress" peer "$remotePeerAddress" dev "$dev" scope link
...@@ -20,3 +20,5 @@ iptables -t mangle -A FORWARD -o "$dev" -p tcp -m tcp --tcp-flags SYN,RST SYN -m ...@@ -20,3 +20,5 @@ iptables -t mangle -A FORWARD -o "$dev" -p tcp -m tcp --tcp-flags SYN,RST SYN -m
iptables -t mangle -A PREROUTING -i "$dev" -m set ! --match-set mycard src -j CONNMARK --set-xmark "$remoteMark" iptables -t mangle -A PREROUTING -i "$dev" -m set ! --match-set mycard src -j CONNMARK --set-xmark "$remoteMark"
iptables -t mangle -A PREROUTING -m connmark --mark "$remoteMark" -j CONNMARK --restore-mark iptables -t mangle -A PREROUTING -m connmark --mark "$remoteMark" -j CONNMARK --restore-mark
iptables -t mangle -A OUTPUT -m connmark --mark "$remoteMark" -j CONNMARK --restore-mark iptables -t mangle -A OUTPUT -m connmark --mark "$remoteMark" -j CONNMARK --restore-mark
true
...@@ -34,6 +34,7 @@ class InventoryBuilder { ...@@ -34,6 +34,7 @@ class InventoryBuilder {
host_vars(host) { host_vars(host) {
const connections = []; const connections = [];
const null_connection = "10000,null";
for (const h of this.connections) { for (const h of this.connections) {
if (h != host.name) { if (h != host.name) {
const to = host[h]; const to = host[h];
...@@ -45,8 +46,12 @@ class InventoryBuilder { ...@@ -45,8 +46,12 @@ class InventoryBuilder {
} else if (from || to) { } else if (from || to) {
// 对称连接 // 对称连接
connections.push(this.parse_connection(host, this.hosts[h], from || to, true, true)); connections.push(this.parse_connection(host, this.hosts[h], from || to, true, true));
} connections.push(this.parse_connection(host, this.hosts[h], null_connection, false, false));
} else {
// 不连接 // 不连接
connections.push(this.parse_connection(host, this.hosts[h], null_connection, true, false));
connections.push(this.parse_connection(host, this.hosts[h], null_connection, false, true));
}
} }
} }
...@@ -75,6 +80,7 @@ class InventoryBuilder { ...@@ -75,6 +80,7 @@ class InventoryBuilder {
const localGatewayMark = localGatewayName ? localGateway.mark : undefined; const localGatewayMark = localGatewayName ? localGateway.mark : undefined;
const remoteGatewayName = (cis ? params.rif : params.lif) || params.if; const remoteGatewayName = (cis ? params.rif : params.lif) || params.if;
const remoteGateway = remoteGatewayName ? this.gateways[remote.name][remoteGatewayName] : _.find(this.gateways[remote.name]); const remoteGateway = remoteGatewayName ? this.gateways[remote.name][remoteGatewayName] : _.find(this.gateways[remote.name]);
//console.log(remoteGateway.name);
const remoteAddress = remoteGateway.address; const remoteAddress = remoteGateway.address;
const remoteMark = remote.mark; const remoteMark = remote.mark;
const localPort = primary ? remote.port : remote.port2; const localPort = primary ? remote.port : remote.port2;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
set -e set -e
echo "现在会真正去部署了,请务必带 --limit 运行。" echo "现在会真正去部署了,请务必带 --limit 运行。"
echo "现在开放测试的节点:south.mycard.moe,yuzurisa.mycard.moe,hk-hkg-alql2.mycard.moe,ayane.mycard.moe,hk-hkg-alql3.mycard.moe" echo "现在开放测试的节点:south.mycard.moe,yuzurisa.mycard.moe,hk-hkg-alql2.mycard.moe,ayane.mycard.moe,hk-hkg-alql3.mycard.moe,wg-router.mycard.moe"
read -p '确认无误后按回车继续' read -p '确认无误后按回车继续'
...@@ -12,25 +12,25 @@ npm run inventory ...@@ -12,25 +12,25 @@ npm run inventory
cd ansible || exit cd ansible || exit
sed -r -e 's/Address/#Address/g' \ sed -r -e '/^Address/d' \
-e 's/Fwmark/#Fwmark/g' \ -e '/^Fwmark/d' \
-e 's/Table/#Table/g' \ -e '/^Table/d' \
-e 's/DNS/#DNS/g' \ -e '/^DNS/d' \
-e 's/MTU/#MTU/g' \ -e '/^MTU/d' \
-e 's/PostUp/#PostUp/g' \ -e '/^PostUp/d' \
-e 's/PostDown/#PostDown/g' \ -e '/^PostDown/d' \
-e 's/PreUp/#PreUp/g' \ -e '/^PreUp/d' \
-e 's/PreDown/#PreDown/g' \ -e '/^PreDown/d' \
./protocols/wg/wg.conf.j2 > ./protocols/wg/wg-setconf.conf.j2 ./protocols/wg/wg.conf.j2 > ./protocols/wg/wg-setconf.conf.j2
sed -r -e 's/Address/#Address/g' \ sed -r -e '/^Address/d' \
-e 's/Fwmark/#Fwmark/g' \ -e '/^Fwmark/d' \
-e 's/Table/#Table/g' \ -e '/^Table/d' \
-e 's/DNS/#DNS/g' \ -e '/^DNS/d' \
-e 's/MTU/#MTU/g' \ -e '/^MTU/d' \
-e 's/PostUp/#PostUp/g' \ -e '/^PostUp/d' \
-e 's/PostDown/#PostDown/g' \ -e '/^PostDown/d' \
-e 's/PreUp/#PreUp/g' \ -e '/^PreUp/d' \
-e 's/PreDown/#PreDown/g' \ -e '/^PreDown/d' \
./protocols/wgfrp/wgfrp.conf.j2 > ./protocols/wgfrp/wgfrp-setconf.conf.j2 ./protocols/wgfrp/wgfrp.conf.j2 > ./protocols/wgfrp/wgfrp-setconf.conf.j2
ansible-playbook -i ../result/inventory.yaml "$@" configure.yaml ansible-playbook -i ../result/inventory.yaml "$@" configure.yaml
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment