LoginSignup
6
6

More than 3 years have passed since last update.

月額$3.5で運用できるVPNサーバを1時間もかからず作れるはずの作業記録

Last updated at Posted at 2019-07-02

背景

 家(集合住宅)で契約しているインターネット回線が、夜(19:00-24:00ぐらい)の間、Googleサービス(gmail,youtube,maps)だけが遅くなる現象に悩まされている。
 たまたまVPNを張れるところがあったため、VPN接続してサービスを使用したところ問題無く使用できたことから、上流のプロバイダの問題である可能性が高く、管理組合などを通じて申し入れても時間がかかる上に改善の見通しも薄そうなので、自己解決のために掲題のトライを行う。

必要なサービスの選定

VPNソフトウェアの選定

SoftEther VPN一択

VPSの選定

などから、サービス内容・制約事項と費用を考慮しServerman @ VPSのPetitプラン(月額350円(税抜き))を選定。
2019/7/1 時点では2か月300円。ただし先払い。

当初選定したServerman @ VPSにSoftetherをインストールし稼働したところ発生した以下の事象により、解明の時間がもったいないので最終的にAmazon Lightsail(3.5USD/月)を選定。

  • Softether VPN Serverを動かしたところ、ものの数分であらゆるコマンドを実行しようとしたら-bash: fork: Cannot allocate memoryと表示され、何もできなくなる。
  • SSHログインもできなくなる。(認証のセッションは確立するがその後音沙汰なくなる。)
  • Serverman @ VPSはWebコンソールを提供していないため、再起動をかけてもサービスとして立ち上がってくるとすぐSSHログインできなくなるので、完全初期化しか方法が無い。
  • 仕方なく完全初期化してサービスとして立ち上がらないようにしてcgroupで使用リソースを制限しようとしたが、libcgroup libcgroup-toolsが素直にインストールされない。
  • yum.confからexclude=initscripts*をコメントアウトしてインストールまでできる。なお、以前のinitscriptsをインストールすると再起動できなくなる不具合は現在のinitscriptsのバージョンでは解消されている。
  • インストールはできたがcgredがサービスとして立ち上がってこない。 と、ここまでやってこれ以上このVPSを使うのは時間の無駄と判断し、次点だったAmazon Lightsailを選定する。

VPSサービスの申し込みと基本設定

省略。以下の説明はCentOS上の手順を書いているのでインストールコマンドはyumになっているが、LightsailはOSを選択できるので自分の好みでDebianを選択したため、実際はaptを使った。まぁ適当に読み替えてください。
あと、Webの管理画面「ネットワーキング」からファイアウォールの設定はしないといけないんだけど、気が向いたら追記します。

VPNソフトウェアの導入

準備

何は無くともまずはyum update

必要なソフトウェアの導入

  1. 初期状態はVPSにほとんど何も入っていないので、Softether VPN マニュアル 7.3 Linux へのインストールと初期設定 > 7.3.3 必要なソフトウェアおよびライブラリの確認
    に記載されたソフトウェアを導入。
    yum -y install gcc binutil glibc zlib openssl readline ncurses pthread

  2. Softether ダウンロードセンターから、SoftEther VPN Serverをダウンロードする。
    選択肢を選んでいくとリンクが表示されるので、そのリンクからwgetでVPS側にダウンロード
    する。
     コンポーネントを選択 >SoftEther VPN Server
    プラットフォームを選択 > Linux
     CPUを選択 > Intel x64 / AMD64(64bit)
    wget https://github.com/SoftEtherVPN/SoftEtherVPN_Stable/releases/download/v4.29-9680-rtm/softether-vpnserver-v4.29-9680-rtm-2019.02.28-linux-x64-64bit.tar.gz

  3. Softether VPN マニュアル 7.3 Linux へのインストールと初期設定 >7.3.4 パッケージの解凍 から 7.3.9 サービスの開始と停止 までの記載に沿って実行

  4. Softether ダウンロードセンターからSoftEther VPN Manager for Windows を自分の端末にダウンロード・インストールする。

  5. VPNサーバが起動したら、vpncmdを用いて管理パスワードを設定する。

[root@hostname ~]# /usr/local/vpnserver/vpncmd
vpncmd command - SoftEther VPN Command Line Management Utility
SoftEther VPN Command Line Management Utility (vpncmd command)
Version 4.29 Build 9680   (English)
Compiled 2019/02/28 19:22:54 by yagi at pc33
Copyright (c) SoftEther VPN Project. All Rights Reserved.

By using vpncmd program, the following can be achieved.

1. Management of VPN Server or VPN Bridge
2. Management of VPN Client
3. Use of VPN Tools (certificate creation and Network Traffic Speed Test Tool)

Select 1, 2 or 3: 1

Specify the host name or IP address of the computer that the destination VPN Server or VPN Bridge is operating on.
By specifying according to the format 'host name:port number', you can also specify the port number.
(When the port number is unspecified, 443 is used.)
If nothing is input and the Enter key is pressed, the connection will be made to the port number 8888 of localhost (this computer).
Hostname of IP Address of Destination: localhost

If connecting to the server by Virtual Hub Admin Mode, please input the Virtual Hub name.
If connecting by server admin mode, please press Enter without inputting anything.
Specify Virtual Hub Name:
Connection has been established with VPN Server "localhost" (port 443).

You have administrator privileges for the entire VPN Server.

VPN Server>ServerPasswordSet
ServerPasswordSet command - Set VPN Server Administrator Password
Please enter the password. To cancel press the Ctrl+D key.

Password: **********
Confirm input: **********


The command completed successfully.

サーバ側での作業は以上。

SoftEther VPNの設定

Softether VPN マニュアル > 2. SoftEther VPN 全般マニュアル > 2.4 VPN サーバー管理マネージャ

および

SoftEther VPN マニュアル > 3. SoftEther VPN Server マニュアル
3.3 VPN Server 管理

を確認しながら適切に設定する。

参考
「仮想NATおよび仮想DHCPサーバ機能」は有効にしないと使えないので、マニュアルをよく読んで有効化すること。

ツール類

speedtest-cliのインストール

yum -y python python-setuptools
easy_install speedtest-cli
使い方はLinuxでもSpeedtestがしたい(speedtest-cli)などが詳しい。

Systemdによるサービス化

公式ドキュメントではinit.dによる起動をするようにマニュアル化されているので、モダンな作法に乗っ取りsystemdで動かすように変更する。

#chkconfig --del vpnserver
/etc/systemd/system/vpnserver.service
[Unit]
Description=SoftEther VPN Server
After=network.target network-online.target

[Service]
ExecStart=/usr/local/vpnserver/vpnserver start
ExecStop=/usr/local/vpnserver/vpnserver stop
Type=forking
RestartSec=3s

[Install]
WantedBy=multi-user.target
# systemctl start vpnserver
# systemctl status vpnserver

正常起動したら以下でサービス化

# systemctl enable vpnserver

参考

気が向いたら追記

  • 別の仮想HUBとカスケード接続した時にハマったポイント
  • 別の仮想HUB上ののネットワークと相互接続する
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6