ユーザ用ツール

サイト用ツール


ubuntu-server-14-04:openvpn

差分

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

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
ubuntu-server-14-04:openvpn [2016/02/08 19:07] – [インストール前の環境] adminubuntu-server-14-04:openvpn [2016/05/16 14:29] (現在) – [ファイアフォールの設定] admin
行 14: 行 14:
 ^ パッケージ名 ^ バージョン ^ ^ パッケージ名 ^ バージョン ^
 | openvpn | 2.3.2-7ubuntu3.1 | | openvpn | 2.3.2-7ubuntu3.1 |
 +| easy-rsa | 2.2.2-1 |
  
  
-==== インストールするパッケージ等 ====+===== インストール =====
  
  
 +<code>
 +$ sudo apt-get install openvpn easy-rsa
 +</code>
  
-===== インストールと設定 ===== 
  
-==== 前準備 ====+===== 公開鍵基盤の作成 =====
  
-インストール前に /etc/apt/sources.list を変更すれば、パッケージを取得するリポジトリを変更できる。(今回はデフォルトままでインストールを行ったが、extra リポジトリを使用すれば、サードパーティからリリースされた最新のパッケージも利用できる模様)+==== CA(認証局)作成 ====
  
- +CA テンートをコピーする。今回は CA のファイルを /etc/openvpn/easy-rsa/ 以下に配置する。
-まずはソフトウェアリストをアッートする。+
  
  
 <code> <code>
-$ sudo apt-get update+$ 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>
 +$ vim /etc/openvpn/easy-rsa/vars
 +</code>
  
-==== MySQL のインストール ==== 
  
 +<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"
  
-MySQL をインストールしていない場合はここでインストール。+export KEY_ALTNAMES="MyVPN"
  
-<code> +export KEY_NAME="MyVPN" 
-$ sudo apt-get install software-properties-common mysql-server mysql-client mysql-common+export KEY_CN="MyVPN"
 </code> </code>
  
-==== データベースの作成 ==== 
  
-データベースを作成する前に、AppArmor 邪魔されないようにMySQL 対する監視モドを変更する。+<note important>export KEY_ALTNAMES="MyVPN" はもともとファイル含まていないこの設定を含めておかないと、鍵生成時エラが発生する。</note>
  
-MySQL サーバに root として接続する。 
  
-<code> + 
-$ mysql -u root -p +CA 用のファイルを作成する。
-</code>+
  
  
 <code> <code>
-> CREATE DATABASE redminedb character SET utf8; +$ cd /etc/openvpn/easy-rsa/ 
-> CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'password'; +$ source vars 
-> GRANT ALL PRIVILEGES ON redminedb.* TO 'redmine'@'localhost'; +./clean-all 
-> FLUSH PRIVILEGES; +$ ./build-ca
-> exit;+
 </code> </code>
  
  
-  * redmine: Redmine で使用するデタベースのユーザ +鍵生成中に国コドや、組織変数で設定した内容を変更でき。通常はエンターキー連打で OK。
-  * password: user パスワード +
-  * redminedb: 作成すデース名+
  
-<note important>上記の文字列は適当なものに変更する。特にパスワドは複雑なもに。</note>+==== サバ用鍵を作成 ====
  
 +myservername は鍵のファイル名として使用される。
 +
 +<code>
 +$ ./build-key-server myservername
 +</code>
  
 +CA 作成時と同じくエンターキー連打。
  
-==== Redmine をダウド ====+最後の2つの質問は、CA 作成時にはないがこれもエキーで OK。
  
-今回は /var/www/redmine/ に Redmine のファイルを置くことにした。現在の最新バージョンの 2.6 をダウンロードする。 
  
 <code> <code>
-$ sudo mkdir /var/www/redmine +Certificate is to be certified until Feb  5 10:40:34 2026 GMT (3650 days) 
-$ cd /var/www/redmine +Sign the certificate? [y/n]:
-$ 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 の秘密鍵でバ用の公開鍵に署名する。
- +
-必要なディレクトリを作成し、ミッションを修正する。+
  
 <code> <code>
-$ cd /var/www/redmine +1 out of 1 certificate requests certified, commit? [y/n] 
-$ mkdir -p tmp tmp/pdf public/plugin_assets +
-$ 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>
  
 +y を入力して、CA のデータベースに登録する。
  
-==== Redmine の設定 ==== 
  
-設定ファイルをコピーする。+Diffie Hellman パラメタが必要になるので生成する。 
  
 <code> <code>
-cd /var/www/redmine +$ ./build-dh
-$ cp ./config/configuration.yml.example ./config/configuration.yml +
-$ cp ./config/database.yml.example ./config/database.yml+
 </code> </code>
  
-タベース設定変更する。+ 
 +CA と サバ用鍵、証明書を OpenVPN のディレクトリにコピーする。
  
 <code> <code>
-vi ./config/database.yml+cd ./keys 
 +$ sudo cp myservername.crt myservername.key ca.crt dh2048.pem /etc/openvpn
 </code> </code>
  
-以下の production セションを変更。+ 
 +==== ライアト用の鍵作成 ==== 
  
 <code> <code>
-production: +$ cd /etc/openvpn/easy-rsa 
-  adapter: mysql2 +$ source vars 
-  database: redminedb +$ ./build-key client1
-  host: localhost +
-  username: redmine +
-  password: "password" +
-  encoding: utf8+
 </code> </code>
  
-  * database: 作成しデースの名前 +鍵情報の入力があるが、エンターを連打。
-  * username: 作成したユーザのユーザネーム +
-  * password: 設定したパスワ+
  
 +y を入力し、署名してデータベースへ登録する。
  
-==== Bundler をインストール ==== 
  
-Bundler をイントーする。+以下のファルは、クライアント側へ安全な方法でコピーする。(scp等) 
 + 
 +  * /etc/openvpn/ca.crt 
 +  * /etc/openvpn/easy-rsa/keys/client1.crt 
 +  * /etc/openvpn/easy-rsa/keys/client1.key
  
-<code> 
-$ gem install bundler 
-</code> 
  
  
-==== Redmine 実行環境を構築 ====+===== OpenVPN サーバ設定 =====
  
-ンストー時に必要になるパッケージ先にインストする。+サーバの設定ファイルをコピーする。
  
 <code> <code>
-$ sudo apt-get install libmysqlclient-dev imagemagick libmagickwand-dev+$ 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>
  
-Bundler で Redmine の実行環境構築する。+ 
 +/etc/openvpn/server.conf 編集する。
  
 <code> <code>
-cd /var/www/redmine +sudo vim /etc/openvpn/server.conf
-$ bundle install --without development test+
 </code> </code>
  
 +以下の証明書と鍵ファイル名を確認する。特に dh2048.pem を確認。
  
 +<code>
 +ca ca.crt
 +cert myservername.crt
 +key myservername.key 
 +dh dh2048.pem
 +</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 の起動を確認する。 
  
  
行 299: 行 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.1454926041.txt.gz · 最終更新: 2016/02/08 19:07 by admin