ftao / vpn-deploy-playbook

A Collection of Ansible Playbook for deploy vpn services
GNU General Public License v3.0
918 stars 159 forks source link

wiki写得看不懂 #100

Open monkuu opened 8 years ago

monkuu commented 8 years ago

有很多不明所以,哪些是在本机操作的,哪些是vps上的。 ansible_host应该怎么写,一会儿servername.example.com ansible_ssh_host=ip.of.server ansible_ssh_user=some-user, 一会儿testvm.example.com ansible_ssh_host=192.168.1.14 ansible_ssh_user=vagrant ansible_sudo=true.

一会儿执行ansible-playbook ipsec.yml -l testvm.example.com,一会儿又是说run ansible-playbook PLAYBOOK_NAME.yml to setup servers

如果只是在vps上给自身部署怎么操作? 没有域名只是ip又是怎么操作?

跟Shadowsock的wiki明了易懂比起来,差距蛮大的。希望好好改善一下语言逻辑水平。

ftao commented 8 years ago

确实文档很不完整。对于不了解 ansible 这个工具本身的人,比较难看懂。 建议你了解一些 ansible 的工作机制和概念, 再看会清楚很多。 http://docs.ansible.com/ansible/index.html

关于只是在 vps 给自己部署的话, 大部分的playbook 应该都可以直接使用 -i ansible_hosts.local 比如

ansible-playbook -i ansible_hosts.local  pptp.yml  

也有可能一些没有playbook 没有在ansible_hosts.local 里面定义 对应的group, 会报错。

S1U commented 8 years ago

要装的是IKEv2,用了ansible-playbook -i ansible_hosts.local ipsec.yml, 而且改了group_vars/ipsec.yml里的IKEv2部分

ikev2_users: []                                              
ikev_users:                                                   
  - username: "user1"                                         
    password: "pass1"                                         
#  - username: "user2"                                         
#  password: "passw"   

试了下,只能原始group_vars/ipsec.yml里面预先定义的ikev1_users的用户名密码能连上,上面去掉注释后IKEv2的用户名密码连不上。

ftao commented 8 years ago

group_vars/ipsec.yml 头上的

ipsec_enable_ikev2: false

改成 true , 改了吗?

你参考的IKEv2 文档是这个吗?

https://github.com/ftao/vpn-deploy-playbook/wiki/Setup-IKEv2-VPN-Server

S1U commented 8 years ago

放弃了,还是不行。enable了,local的运行完了之后,mac还是连不上ikev2。 ip:9441/ios8-profile下面没有mobileconfig文件,osx下面到有servercert.pem,但没效果,还是连不上。

再试了加了个vps,用1个运行ansible-playbook到另一个vps部署ipsec,而且default/main.yml里面也改了 ip as domain = true ssh connecting 有问题。用了 -vvvv 说debug,没有用啊。

PLAY [ipsec] ****************************************************************** 

GATHERING FACTS *************************************************************** 
fatal: [另外一个VPS的IP] => SSH Error: Permission denied (publickey,password).
    while connecting to 另外一个VPS的IP:22
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.

TASK: [common | update apt cache] ********************************************* 
FATAL: no hosts matched or all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/root/ipsec.retry

另外一个VPS的IP                : ok=0    changed=0    unreachable=1    failed=0 

ansible_hosts里面是这么写吗?

ansible_ssh_host=另外一个VPS的IP  ansible_ssh_user=root  ansible_sudo=true

[ipsec]
另外一个VPS的IP

ps. 两个VPS都是Debian 7

ftao commented 8 years ago

生成 ios 配置文件, 需要设置 ipsec_gen_ios8_profile: true 这个参数。 另外一台机器, 如果不是密钥认证, 需要输入密码的话, 运行 playbook 的时候加上 -k 参数。

ansible-playbook   -k   .......... 
S1U commented 8 years ago

是有true的。

提示to use the 'ssh' connection type with passwords, you must install the sshpass program。这里面的坑真是不少啊。。。

S1U commented 8 years ago

可以安装在另一个vps上安装了,但是还是只能ikev1能连上,2就是连不上,ipsec.yml配置这样,两个证书都trule,但是安装后在另个vps的 /var/www/ikev2/ 下面ios的目录下面就没有证书,osx下面的证书导入mac并设置always trust后,还是提示连接 用户认证失败。

ipsec_enable_l2tp: false
ipsec_enable_ikev1: true
ipsec_enable_ikev2: true

# the generated server cert should also be imported to osx

ipsec_domain: "{{ inventory_hostname }}"
ipsec_bind_ip:  "{{ ansible_default_ipv4.address }}"
ipsec_subnet: 10.7.0.0/24

ipsec_use_radius: false
ipsec_radius_servers:
  - host: 127.0.0.1
    secret: some-radius-secret

ipsec_dns_servers:
   - 8.8.8.8
   - 8.8.4.4

ipsec_psk: "psk"
ikev1_users:
  - username: "user"
    password: "pass"

ikev2_users: []                                               
ikev_users:                                                   
  - username: "user1"                                         
    password: "pass1"                                         
#  - username: "user2"                                        
#    password: "passw"  

ipsec_gen_ios8_profile: true                                  
ipsec_ios8_include_password: true 

在被装的vps上查看 /etc/ipsec.secrets,发现

: PSK "psk"
user : XAUTH "pass"
: RSA /etc/ipsec.d/private/server_key.pem
ftao commented 8 years ago

这一段写错了

ikev2_users: []                                               
ikev_users:                                                   
  - username: "user1"                                         
    password: "pass1"    

应该是

ikev2_users:                                                   
  - username: "user1"                                         
    password: "pass1"    

似乎我的模版的里面也写错了。

monkuu commented 8 years ago

好嘛,原来坑在这里。。。

重新弄了下,另一VPS响应目录下出现 user2.mobileconfig 和 user2.signed.mobileconfig 安装到iphone后用相应的profile生成的vpn去连接,不管用哪个导入的都不能连接成功,没有提示,直接断开。点进 vpn的设置里面,只有显示 type ikev2,其他什么都没有。

如果用普通正常添加vpn操作,就是 填ip,用户名,密码,psk密钥,也不能连接,提示 negotiation with the vpn server failed.

在mac上没有导入server_cert.pem ,按正常添加vpn设置能连接成功。

mac上ikev1和2都可以连接,iphone上都连接不了,win7上也一样连接不了。


用上面的应用在目标vps的 group_vars/ipsec.yml 的配置,装在控制机vps上面,就是本机安装,ansible-playbook -i ansible_hosts.local ipsec.yml, mac和iphone不用证书,ikev1和2都能连接。而win7无论ikev1还是2都连不上。真是奇葩。

满满的坑啊。。。。

noahlu commented 8 years ago

同样没弄明白,系统Debian,想装IKEv2,但是按照文档装完,手机iOS9里连不上vpn。。

装在本机,安装命令

sudo ansible-playbook -i ansible_hosts.local ipsec.yml 

group_vars/ipsec.yam 文件如下

---
ipsec_enable_l2tp: false
ipsec_enable_ikev1: false
ipsec_enable_ikev2: true

# the generated server cert should also be imported to osx

ipsec_domain: "{{ inventory_hostname }}"
ipsec_bind_ip:  "{{ ansible_default_ipv4.address }}"
ipsec_subnet: 10.7.0.0/24

ipsec_use_radius: false
ipsec_radius_servers:
  - host: 127.0.0.1
    secret: some-radius-secret

ipsec_dns_servers:
   - 8.8.8.8
   - 8.8.4.4

ipsec_psk: "a_long_long_psk"
ikev1_users:
  - username: "a_secret_vpn_username"
    password: "a_secret_vpn_password"

#uncomment following lines to add ikev2 users
ikev2_users:
  - username: "***"
    password: "***"

# uncomment next line if your want to connect to the server by ip address instead of domain name
ipsec_use_ip_as_domain: true
ftao commented 8 years ago

@noahlu ios9 的内置 ikev2 界面确实还没有测试过。 可能的原因是还是需要导入证书, 直接配置的话自动生成的证书是不被接受的。 考虑设置这个变量。 https://github.com/ftao/vpn-deploy-playbook/wiki/Setup-IKEv2-VPN-Server

ipsec_gen_ios8_profile: true   #自动生成ios8 profile
noahlu commented 8 years ago

多谢啦,不过还是有问题。

我按照https://github.com/ftao/vpn-deploy-playbook/wiki/Setup-IKEv2-VPN-Server 里写了一个group_vars/localhost.yml。

然后执行:

sudo ansible-playbook -i ansible_hosts.local localhost.yml 

我直接用ansible_hosts.local 生成出来的mobileconfig文件里都是localhost,没有服务器地址嘛...所以依然连不上

以下是iOS上连vpn的日志

Oct 13 12:23:33 lus-iPhone nesessionmanager[120] <Error>: Plugin com.apple.neplugin.IKEv2 does not have a bundle URL
Oct 13 12:23:33 lus-iPhone neagent[3982] <Error>: IKEv2 Plugin: ikev2_dns_callback: Error -65554
Oct 13 12:23:33 lus-iPhone configd[30] <Notice>: network changed
Oct 13 12:23:33 lus-iPhone neagent[3982] <Notice>: BUG in libdispatch client: kevent[EVFILT_READ] delete: "Bad file descriptor" - 0x9
Oct 13 12:23:33 lus-iPhone neagent[3982] <Error>: Send failed (Can't assign requested address)
Oct 13 12:23:33 lus-iPhone symptomsd[118] <Error>: -[FlowAnalyticsEngine _newFlowData:] netanalyticsdebug: (2) no head-end for flow localhost, discarding all its records
Oct 13 12:23:45 lus-iPhone neagent[3982] <Error>: Failed to receive IKE SA Init packet
Oct 13 12:23:46 lus-iPhone nesessionmanager[120] <Notice>: NESMIKEv2VPNSession[noahlu localhost IKEV2:7AFD498C-0EA7-49F9-B6AC-33967C81A726]: status changed to disconnecting
ftao commented 8 years ago

我更新了一下文档。

如果生成的iOS 中配置文件不正确, 可以考虑设置 ipsec_domain, ipsec_remote_address 为可以正确访问的域名或者IP 地址, 并且保证两者是一致的。 来保证生成的配置文件中的地址或者域名是正确的。

ipsec_domain: "ip or domain of the server"
ipsec_remote_address: "ip or domain of the server" 
noahlu commented 8 years ago

现在配置文件ip对了,还是连不上,是不是 ipsec.yml里没配置ikev2的role?

- hosts: ipsec

  roles:
    - common
    - strongswan
    - role: l2tp
      when: ipsec_enable_l2tp

    - role: ppp-radiusclient
      when: ipsec_enable_l2tp and l2tp_use_radius
      device_type: l2tp
      radius_servers: "xxx"

    - nat

    - role: static-site
      nginx_site_name: 'ipsec-profile-host'
      nginx_site_server_name: 'xxx'
      nginx_site_port: 9441
      nginx_site_ssl_on: false
      nginx_site_root: /var/www/ikev2/
      when: ipsec_gen_ios8_profile
ftao commented 8 years ago

ikev2 的role 就是 strongswan . 这个配置上没有问题。 还连不上的话, 你看一下服务器的配置文件吧。

/etc/ipsec.conf

另外你可能要把服务器上面的

/etc/ipsec.d/certs/server_cert.pem

删掉, 然后重新跑, 因为这里面的域名可能是错的。

这是一个bug, 应该修改域名之后, 重新跑的时候, 重新生成这个文件。

noahlu commented 8 years ago

哎,还是不行。。。

tkinglee commented 7 years ago

@noahlu 这个问题解决了么?我也遇到了这个 Plugin com.tkinglee.rabbit does not have a bundle URL 问题 最后怎样解决的?