ユーザ用ツール

サイト用ツール


ubuntu-server-14-04:openvpn

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
ubuntu-server-14-04:openvpn [2016/02/08 18:33] adminubuntu-server-14-04:openvpn [2016/05/16 14:29] (現在) – [ファイアフォールの設定] admin
行 13: 行 13:
  
 ^ パッケージ名 ^ バージョン ^ ^ パッケージ名 ^ バージョン ^
-apache2 | 2.4.7-1ubuntu4.1 | +openvpn | 2.3.2-7ubuntu3.1 | 
-mysql-server 5.5.40-0ubuntu0.14.04.+easy-rsa 2.2.2-1 |
-| libapache2-mod-php5 | 5.5.9+dfsg-1ubuntu4.5 | +
-| rvm | 1.26.9 |+
  
-Apache2、MySQL、PHP は Ubuntu をインストールした際に、ついでにインストール済み。 
  
-RVM で選択されているデフォルの Ruby のバジョンは、"ruby-2.0.0-p598"+===== インストール =====
  
-==== インストールするパッケージ等 ==== 
  
 +<code>
 +$ sudo apt-get install openvpn easy-rsa
 +</code>
  
  
-===== インストールと設定 =====+===== 公開鍵基盤の作成 =====
  
-==== 前準備 ====+==== CA(認証局)の作成 ====
  
-ール前に /etc/apt/sources.list 変更すれば、パッケジを取得るリポジトリを変更できる。今回はォルトのままでンストールを行ったが、extra リポジトリを使用れば、サードパーティからリリースされた最新のパッケージも利用でき模様)+CA のテプレートをコピーする。今回は CA のイルを /etc/openvpn/easy-rsa/ 以下に配置する
  
  
-まずはソフトウェアのリストをアップデートする。+<code> 
 +$ sudo mkdir /etc/openvpn/easy-rsa/ 
 +$ sudo chown user:user /etc/openvpn/easy-rsa/ 
 +$ cp -r /usr/share/easy-rsa/* /etc/openvpn/easy-rsa/ 
 +</code>
  
 +変数ファイルを編集する。
  
 <code> <code>
-sudo apt-get update+vim /etc/openvpn/easy-rsa/vars
 </code> </code>
  
 +
 +<code>
 +export KEY_COUNTRY="JP"
 +export KEY_PROVINCE="Tokyo"
 +export KEY_CITY="Shinjuku"
 +export KEY_ORG="Example Company"
 +export KEY_EMAIL="root@example.com"
 +export KEY_OU="MyVPN"
 +
 +export KEY_ALTNAMES="MyVPN"
 +
 +export KEY_NAME="MyVPN"
 +export KEY_CN="MyVPN"
 +</code>
 +
 +
 +<note important>export KEY_ALTNAMES="MyVPN" はもともとファイルに含まれていないが、この設定を含めておかないと、鍵生成時にエラーが発生する。</note>
  
  
-==== MySQL のインストール ==== 
  
 +CA 用のファイルを作成する。
  
-MySQL をインストールしていない場合はここでインストール。 
  
 <code> <code>
-sudo apt-get install software-properties-common mysql-server mysql-client mysql-common+cd /etc/openvpn/easy-rsa/ 
 +$ source vars 
 +$ ./clean-all 
 +$ ./build-ca
 </code> </code>
  
-==== データベースの作成 ==== 
  
-データベースを作する前、AppArmor に邪魔されないように、MySQL に対する監視モードを変更る。+鍵生国コードや、組織名等の変数で設定した内容を変更でき。通常はエンターキー連打で OK
  
-MySQL サーバに root として接続する。+==== サーバ用の鍵を作成 ==== 
 + 
 +myservername は鍵のファイル名として使用される。
  
 <code> <code>
-mysql -u root -p+./build-key-server myservername
 </code> </code>
 +
 +CA 作成時と同じくエンターキー連打。
 +
 +最後の2つの質問は、CA 作成時にはないがこれもエンターキーで OK。
  
  
 <code> <code>
-> CREATE DATABASE redminedb character SET utf8; +Certificate is to be certified until Feb  5 10:40:34 2026 GMT (3650 days) 
-> CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'password'; +Sign the certificate? [y/n]:
-> GRANT ALL PRIVILEGES ON redminedb.* TO 'redmine'@'localhost'; +
-> FLUSH PRIVILEGES; +
-> exit;+
 </code> </code>
  
 +y を入力して、先ほど作成した CA の秘密鍵で、サーバ用の公開鍵に署名する。
  
-  * redmine: Redmine で使用するデータベースのユーザ名 +<code> 
-  * password: user のパスワード +1 out of 1 certificate requests certified, commit? [y/n]  
-  * redminedb: 作成するデータベース名 +</code>
- +
-<note important>上記の文字列は適当なものに変更する。特にパスワードは複雑なものに。</note>+
  
 +y を入力して、CA のデータベースに登録する。
  
  
-==== Redmine をダウンロド ====+Diffie Hellman パラメタが必要になるので生成する。
  
-今回は /var/www/redmine/ に Redmine のファイルを置くことにした。現在の最新バージョンの 2.6 をダウンロードする。 
  
 <code> <code>
-sudo mkdir /var/www/redmine +$ ./build-dh
-$ cd /var/www/redmine +
-$ sudo chown $USER:$USER . +
-$ wget "http://www.redmine.org/releases/redmine-2.6.0.tar.gz" +
-$ tar -xzvf ./redmine-2.6.0.tar.gz --strip-components=1 +
-$ rm ./redmine-2.6.0.tar.gz+
 </code> </code>
  
-<note>http://www.redmine.org/projects/redmine/wiki/Download から Redmine のバージョンを選択してダウンロードできる。</note> 
  
-必要なディレクトリを作成し、パミッションを修正する。+CA と サーバ用の鍵、証明書を OpenVPN のディレクトリにコピーする。
  
 <code> <code>
-$ cd /var/www/redmine +$ cd ./keys 
-$ mkdir -p tmp tmp/pdf public/plugin_assets +$ sudo cp myservername.crt myservername.key ca.crt dh2048.pem /etc/openvpn
-$ sudo chown -R www-data:www-data files log tmp public/plugin_assets +
-$ sudo chmod -R 775 files log tmp public/plugin_assets+
 </code> </code>
  
  
-==== Redmine 設定 ====+==== クライアント用鍵を作成 ====
  
-設定ファイルをコピーする。 
  
 <code> <code>
-$ cd /var/www/redmine +$ cd /etc/openvpn/easy-rsa 
-cp ./config/configuration.yml.example ./config/configuration.yml +source vars 
-cp ./config/database.yml.example ./config/database.yml+$ ./build-key client1
 </code> </code>
  
-デースの設定変更する+また鍵情報の入力があるが、エンターキー連打
  
-<code> +y を入力し、署名してデータベースへ登録する。
-$ vi ./config/database.yml +
-</code>+
  
-以下の production セクションを変更。 
  
-<code> +以下のファイルは、クライアント側へ安全な方法でコピーする。(scp等)
-production: +
-  adapter: mysql2 +
-  database: redminedb +
-  host: localhost +
-  username: redmine +
-  password: "password" +
-  encoding: utf8 +
-</code>+
  
-  * database: 作成したデータベースの名前 +  * /etc/openvpn/ca.crt 
-  * username: 作成したユーザのユーザネーム +  * /etc/openvpn/easy-rsa/keys/client1.crt 
-  * password: 設定したパスワード+  * /etc/openvpn/easy-rsa/keys/client1.key
  
  
-==== Bundler をインストール ==== 
  
-Bundler をインストールする。+===== OpenVPN サバの設定 ===== 
 + 
 +サーバの設定ファイをコピーする。
  
 <code> <code>
-gem install bundler+sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn 
 +$ sudo gzip -d /etc/openvpn/server.conf.gz
 </code> </code>
  
  
-==== Redmine の実行環境構築 ==== +/etc/openvpn/server.conf 編集する。
- +
-インストール時に必要になるパッケージを先にインストールする。+
  
 <code> <code>
-$ sudo apt-get install libmysqlclient-dev imagemagick libmagickwand-dev+$ sudo vim /etc/openvpn/server.conf
 </code> </code>
  
-Bundler で Redmine 実行環境構築する。+以下証明書と鍵ファイル名確認する。特に dh2048.pem を確認
  
 <code> <code>
-$ cd /var/www/redmine +ca ca.crt 
-$ bundle install --without development test+cert myservername.crt 
 +key myservername.key  
 +dh dh2048.pem
 </code> </code>
  
- +以下コメントを解除
- +
-==== セッションストアトークを生成 ==== +
- +
-セッションスアのトークン生成する+
  
 <code> <code>
-$ bundle exec rake generate_secret_token+user nobody 
 +group nogroup
 </code> </code>
  
  
-==== タベース初期化 ====+==== ネットワ設定 ====
  
  
-Redmine で使うデータデータベースに格納する。+/etc/sysctl.conf 編集する。
  
 <code> <code>
-bundle exec rake db:migrate RAILS_ENV=production +sudo vim /etc/sysctl.conf
-$ bundle exec rake redmine:load_default_data RAILS_ENV=production+
 </code> </code>
  
-途中言語選択があるで好きな言語選択する。+以下コメントを解除して、IPv4 フォワード有効にする。
  
-以下のエラが出たが、www-data ユーザ以外で実行したため。実際運用では www-data が実行ユザになので問題ない+<code> 
 +net.ipv4.ip_forward=1 
 +</code> 
 + 
 +ネットワ設定をリロドする。
  
 <code> <code>
-Rails Error: Unable to access log file. Please ensure that /var/www/redmine/log/production.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.+$ sudo sysctl -p /etc/sysctl.conf
 </code> </code>
  
  
-==== Phusion Passenger のインストル ====+==== OpenVPN サバを起動 ====
  
-Phusion Passenger のインストールに必要になるパッケージを先にインストールする。 
  
 <code> <code>
-$ sudo apt-get install libcurl4-openssl-dev apache2-threaded-dev libapr1-dev libaprutil1-dev+$ sudo service openvpn start
 </code> </code>
  
 +<code>
 + * Starting virtual private network daemon(s)...
 +   Autostarting VPN 'server'
 +</code>
  
-Phusion Passenger をインストルする。+仮想ポトが作成されていかを確認
  
 <code> <code>
-gem install passenger +ifconfig tun0
-$ passenger-install-apache2-module+
 </code> </code>
  
-対話式に質問してくるので答えていく。 
  
- * Which languages are you interested in?: Ruby みを選択+===== ファイアフォール設定 =====
  
-以下のエラーが発生した+ファイアフォールを以下のコマンドで設定する
  
 <code> <code>
-AH00526: Syntax error on line 33 of /etc/apache2/sites-enabled/server-ssl.conf: +$ sudo ufw status  
-SSLCertificateKeyFile: file '/etc/ssl/private/server.key' does not exist or is empty+$ sudo ufw enable 
 +$ sudo ufw default deny incoming 
 +$ sudo ufw default allow outgoing
 </code> </code>
  
-一般ユザで Phusion Passenger のインストールを実行しているため、root にしか権限がない秘密鍵アクセスできないためらしい。 +OpenVPN サへの接続許可
- +
-一時的に該当コメントアウトして再度インストールする+
  
 <code> <code>
-passenger-install-apache2-module+sudo ufw allow 1194/udp
 </code> </code>
  
-うまく騙せた。コメントアウトした行を元に戻す。 
  
-最後に Apache2 の設定方法が表示されるでコピしておく+ファイアウォールデフォルトルルを変更
  
 +<code>
 +$ sudo vim /etc/default/ufw
 +</code>
 +
 +<code>
 +DEFAULT_FORWARD_POLICY="ACCEPT"
 +</code>
  
  
-==== Apache2 の設定 ==== 
  
-Phusion Passenger のインストールの最後に、以下のような設定例が出力されるので、指示に従って Apache2 の設定を変更する。 
  
 <code> <code>
-   LoadModule passenger_module /home/user/.rvm/gems/ruby-2.0.0-p598/gems/passenger-4.0.57/buildout/apache2/mod_passenger.so +$ sudo vim /etc/ufw/before.rules
-   <IfModule mod_passenger.c> +
-     PassengerRoot /home/user/.rvm/gems/ruby-2.0.0-p598/gems/passenger-4.0.57 +
-     PassengerDefaultRuby /home/user/.rvm/gems/ruby-2.0.0-p598/wrappers/ruby +
-   </IfModule>+
 </code> </code>
  
 +
 +以下のルールを “*filter” の直前に入力する。
  
 <code> <code>
-   <VirtualHost *:80> +# START OPENVPN RULES 
-      ServerName www.yourhost.com +# NAT table rules 
-      !!! Be sure to point DocumentRoot to 'public'! +*nat 
-      DocumentRoot /somewhere/public     +:POSTROUTING ACCEPT [0:0] 
-      <Directory /somewhere/public> +Allow traffic from OpenVPN client to eth0 and Wlan0 
-         # This relaxes Apache security settings. +-A POSTROUTING -s 10.8.0.0/8 -o eth0 -j MASQUERADE 
-         AllowOverride all +-A POSTROUTING -s 10.8.0.0/8 -o wlan0 -j MASQUERADE 
-         # MultiViews must be turned off. +COMMIT 
-         Options -MultiViews +END OPENVPN RULES
-         # Uncomment this if you're on Apache >= 2.4: +
-         #Require all granted +
-      </Directory> +
-   </VirtualHost>+
 </code> </code>
  
-最終的に、以下の内容を稼働中のサイトの <VirtualHost> ディレクティブに追加した。 
  
-Passenger の設定については [[http://www.modrails.com/documentation/Users%20guide%20Apache.html|Phusion Passenger users guide, Apache version]] 参照+ufw 再起動する
  
 <code> <code>
-### for Redmine +$ sudo ufw disable && sudo ufw enable 
-LoadModule passenger_module /home/user/.rvm/gems/ruby-2.0.0-p598/gems/passenger-4.0.57/buildout/apache2/mod_passenger.so +</code>
-<IfModule mod_passenger.c> +
-        PassengerRoot /home/user/.rvm/gems/ruby-2.0.0-p598/gems/passenger-4.0.57 +
-        PassengerDefaultRuby /home/user/.rvm/gems/ruby-2.0.0-p598/wrappers/ruby+
  
-        ## Passenger Configuration +===== クライアントの設定 =====
-        ## Details at http://www.modrails.com/documentation/Users%20guide%20Apache.html +
-        PassengerMinInstances 6 +
-        PassengerMaxPoolSize 20 +
-        RailsBaseURI /redmine +
-        PassengerAppRoot /var/www/redmine+
  
-        RailsSpawnMethod smart 
-        PassengerPoolIdleTime 1000 
-        RailsAppSpawnerIdleTime 3600 
-        PassengerMaxPreloaderIdleTime 0 
-        PassengerMaxRequests 5000 
-        PassengerStatThrottleRate 5 
  
-        PassengerUser www-data +自分は Mac で Tunnelblick 使用
-        PassengerGroup www-data +
-</ifModule> +
-</code> +
- +
-Apache2 再起動する+
  
 <code> <code>
-$ sudo service apache2 restart+# sample client.ovpn for Tunnelblick 
 +client 
 +remote blue.example.com 
 +port 1194 
 +proto udp 
 +dev tun 
 +dev-type tun 
 +ns-cert-type server 
 +reneg-sec 86400 
 +auth-nocache 
 +auth-retry interact 
 +comp-lzo yes 
 +verb 3 
 +ca ca.crt 
 +cert client1.crt 
 +key client1.key
 </code> </code>
- 
- 
-https://your.domain.com/redmine にアクセスして Redmine の起動を確認する。 
  
  
行 305: 行 302:
  
  
 +  * [[https://help.ubuntu.com/14.04/serverguide/openvpn.html|Ubuntu Documentation]]
 +  * [[https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-ubuntu-14-04|How To Set Up an OpenVPN Server on Ubuntu 14.04]]
  
 +  * [[https://ubuntu-mate.community/t/vpn-how-to-connect-successfully-securely-ufw-openvpn-ubuntumate-15-04/1452|VPN-How To Connect Successfully & Securely -UFW/OpenVPN/UbuntuMATE 15.04]]
ubuntu-server-14-04/openvpn.1454924035.txt.gz · 最終更新: 2016/02/08 18:33 by admin