Ubuntu

OpenVPN 不會作為帶有配置文件的服務啟動

  • June 2, 2021

如果我從 CLI 執行 OpenVPN,我的配置文件可以很好地工作:

openvpn server.conf

但是,如果我嘗試將它作為服務啟動,它啟動得很好,不會出錯,但它不會載入我的 conf 文件,tun因為ifconfig.

我已經AUTOSTART設置all/etc/init.d/openvpn

在此處輸入圖像描述

但是快速ifconfig顯示它還沒有開始。我知道它沒有載入我的 conf 文件,因為沒有創建日誌文件,但 OpenVPN 沒有錯誤。

在此處輸入圖像描述

這是在 Ubuntu 16.04.3 上,全新安裝的 OpenVPN。

編輯

根據下面的評論,我也嘗試過多次systemctl,它只是出錯了:

在此處輸入圖像描述 在此處輸入圖像描述

我知道 conf 文件有效,因為我可以從 CLI 執行它openvpn server.conf並且它有效。

編輯2

日誌:

Jan 11 14:31:37 cloud systemd[1]: openvpn@server.service: Unit entered failed state.
Jan 11 14:31:37 cloud systemd[1]: openvpn@server.service: Failed with result 'exit-code'.
Jan 11 16:06:07 cloud systemd[1]: Starting OpenVPN connection to server...
Jan 11 16:06:07 cloud ovpn-server[4726]: OpenVPN 2.3.10 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [EPOLL] [PKCS11] [MH] [IPv6] built on Jun 22 2017
Jan 11 16:06:07 cloud ovpn-server[4726]: library versions: OpenSSL 1.0.2g  1 Mar 2016, LZO 2.08
Jan 11 16:06:07 cloud ovpn-server[4726]: daemon() failed or unsupported: Resource temporarily unavailable (errno=11)
Jan 11 16:06:07 cloud ovpn-server[4726]: Exiting due to fatal error
Jan 11 16:06:07 cloud systemd[1]: openvpn@server.service: Control process exited, code=exited status=1
Jan 11 16:06:07 cloud systemd[1]: Failed to start OpenVPN connection to server.
Jan 11 16:06:07 cloud systemd[1]: openvpn@server.service: Unit entered failed state.
Jan 11 16:06:07 cloud systemd[1]: openvpn@server.service: Failed with result 'exit-code'.
Jan 12 09:55:35 cloud systemd[1]: Starting OpenVPN connection to server...
Jan 12 09:55:35 cloud ovpn-server[12133]: Current Parameter Settings:
Jan 12 09:55:35 cloud ovpn-server[12133]:   config = '/etc/openvpn/server.conf'
Jan 12 09:55:35 cloud ovpn-server[12133]:   mode = 1
Jan 12 09:55:35 cloud ovpn-server[12133]:   persist_config = DISABLED
Jan 12 09:55:35 cloud ovpn-server[12133]:   persist_mode = 1
Jan 12 09:55:35 cloud ovpn-server[12133]:   show_ciphers = DISABLED
Jan 12 09:55:35 cloud ovpn-server[12133]:   show_digests = DISABLED
Jan 12 09:55:35 cloud systemd[1]: openvpn@server.service: Control process exited, code=exited status=1
Jan 12 09:55:35 cloud systemd[1]: Failed to start OpenVPN connection to server.
Jan 12 09:55:35 cloud systemd[1]: openvpn@server.service: Unit entered failed state.
Jan 12 09:55:35 cloud systemd[1]: openvpn@server.service: Failed with result 'exit-code'.

這個問題與Ask 上的另一個問題相同!Ubuntu . 修復:_

我發現的工作是註釋掉 /lib/systemd/system/openvpn@.service 中的 LimitNPROC 行。

當我嘗試執行我的伺服器配置時,我發現它無法重新分配相同的埠,因此我重新啟動伺服器並解決了這個問題。

ubuntu@VPNSERVER:/etc/openvpn$ sudo openvpn server.conf
Fri May 28 18:09:18 2021 OpenVPN 2.4.4 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Apr 27 2021
Fri May 28 18:09:18 2021 library versions: OpenSSL 1.1.1  11 Sep 2018, LZO 2.08
Fri May 28 18:09:18 2021 ECDH curve prime256v1 added
Fri May 28 18:09:18 2021 Outgoing Control Channel Encryption: Cipher 'AES-256-CTR' initialized with 256 bit key
Fri May 28 18:09:18 2021 Outgoing Control Channel Encryption: Using 256 bit message hash 'SHA256' for HMAC authentication
Fri May 28 18:09:18 2021 Incoming Control Channel Encryption: Cipher 'AES-256-CTR' initialized with 256 bit key
Fri May 28 18:09:18 2021 Incoming Control Channel Encryption: Using 256 bit message hash 'SHA256' for HMAC authentication
Fri May 28 18:09:18 2021 TUN/TAP device tun1 opened
Fri May 28 18:09:18 2021 TUN/TAP TX queue length set to 100
Fri May 28 18:09:18 2021 do_ifconfig, tt->did_ifconfig_ipv6_setup=0
Fri May 28 18:09:18 2021 /sbin/ip link set dev tun1 up mtu 1500
Fri May 28 18:09:18 2021 /sbin/ip addr add dev tun1 10.8.0.1/24 broadcast 10.8.0.255
Fri May 28 18:09:18 2021 Could not determine IPv4/IPv6 protocol. Using AF_INET
Fri May 28 18:09:18 2021 Socket Buffers: R=[212992->212992] S=[212992->212992]
# ===>>>>>  blow line was error that I found <<<<<<<===== #
# Fri May 28 18:09:18 2021 TCP/UDP: Socket bind failed on local address # [AF_INET][undef]:1122: Address already in use (errno=98)
Fri May 28 18:09:18 2021 Exiting due to fatal error
Fri May 28 18:09:18 2021 Closing TUN/TAP interface
Fri May 28 18:09:18 2021 /sbin/ip addr del dev tun1 10.8.0.1/24


  **ubuntu@VPNSERVER:/etc/openvpn$ sudo reboot**

在您的情況下,OPenVpn 狀態和重啟命令可能就像

systemctl status openvpn-server@server.service
systemctl restart openvpn-server@server.service

引用自:https://serverfault.com/questions/891810