【Ubuntu】Hubotの開発環境構築をVagrantで自動化
Hubotを開発するための環境構築用のVagrantfile作りました。
ホストOSで起動しているクライアントからのリクエストがゲストOSで起動したHubotに飛ぶようになっています。
Slackがクライアントの場合でしか試せてませんが、他のクライアントでもいけると思います。
また、node-inspectorとChromeがインストールされるようプロビジョニングしているので、GUIでデバッグすることもできます。
なお、前提としてゲストOSはUbuntuデスクトップです。
以前上げた記事のBoxファイルをベースにしてます。
はまったこと
nodeのバージョンが古い
最初、下記の記事とか類似の記事がたくさんあったので参考にnodeを入れたのですが、最新が入りませんでした。
Ubuntu 14.04 に Node.jsをインストールする - Qiita
結局、公式に行ったら答えがありました。
Installing Node.js via package manager | Node.js
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - sudo apt-get install -y nodejs
npmのバージョンが古い
Node.jsとnpmをアップデートする方法 – Rriver
npm update -g npm
で解決。
再起動するとiptablesの設定が吹っ飛ぶ
Ubuntuは再起動するたびにiptablesの設定がリセットされてしまうみたい。
iptables-persistentというツールを使うと永続化できます。
$ sudo apt-get install -y iptables-persistent
これで解決だと思いきや、プロビジョニングで、エラーが発生。。。
$ sudo apt-get install -y iptables-persistent ・ ・ ・ ==> default: dpkg-preconfigure: 標準入力を再オープンできません: そのようなファイルやディレクトリはありません
環境変数DEBIAN_FRONTENDをnoninteractiveにしてインストールすることで解決できました。
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y iptables-persistent
DEBIAN_FRONTEND=noninteractive ってなんだ - Qiita
これは、インストーラで使うユーザインタフェースを制御するものらしい。 DEBIAN_FRONTEND=noninteractive のときは、インタラクティブな設定をしなくなる(=入力待ちでブロックしなくなる)ので、自動インストールの際には便利だとか。
Chromeのインストールでエラーが発生する
sudo wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' sudo apt-get update sudo apt-get install -y google-chrome-stable ・ ・ ・ ==> default: W ==> default: : ==> default: http://dl.google.com/linux/chrome/deb/dists/stable/Release の取得に失敗しました 期待されるエントリ 'main/binary-i386/Packages' が Release ファイル内に見つかりません (誤った sources.list エントリか、壊れたファイル) ==> default: E ==> default: : ==> default: いくつかのインデックスファイルのダウンロードに失敗しました。これらは無視されるか、古いものが代わりに使われます。
Google Chromeのリポジトリ取得に失敗しましたエラーを修正する | Ubuntuアプリのいいところ
これは、2016年3月に、32bit-LinuxへのGoogle Chromeのサポートが終了した後に発生しているエラーで、64bit版のUbuntuにおいても同じ現象が発生します。
というわけで、
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
というふうに、アーキテクチャを64bitに指定することでエラーを回避できます。
参考
Hubotインストール
slackと連携するhubotを3分でインストールする(動画付き)
nodeインストール
Installing Node.js via package manager | Node.js
redisインストール
Ubuntu Linux 14.04 LTSにRedis 3をインストールする - CLOVER
iptables
mysql - Vagrant and MariaDB (provision) - Server Fault
Ubuntu 14.04 で OpenVPN - BLOG EX MACHINA
ubuntu - dpkg-reconfigure: unable to re-open stdin: No file or directory - Server Fault
Chromeのインストール
【Vagrant】日本語環境に設定したUbutuデスクトップをBoxファイルにする
環境
- ホストOS:OSX
- ゲストOS:Ubuntu14.02
- Vagrant :1.8.1
- プロバイダ:VirtualBox 5.0.16
- Packer:0.10.0
※最終的に行うBoxファイルの作成はVirtualBoxのみ対応しているので、ご注意を。
手順
PackerによるBoxファイルの作成
VagrantとPackerについては過去記事でも上げてます。
まずはベースとなるBoxファイルをPackerを利用して作成します。
Packerのテンプレートを一から作るのは大変なため、boxcutterをフォークして作成しています。
ubuntu/ubuntu1404-desktop.json at master · mktktmr/ubuntu · GitHub
ubuntu1404-desktop.json
{ "_comment": "Build with `packer build -var-file=ubuntu1404-desktop.json ubuntu.json`", "vm_name": "ubuntu1404-desktop", "desktop": "true", "cpus": "1", "disk_size": "130048", "iso_checksum": "3ffb7a3690ce9a07ac4a4d1b829f990681f7e47d", "iso_checksum_type": "sha1", "iso_name": "ubuntu-14.04.4-server-amd64.iso", "iso_path": "iso", "iso_url": "http://ftp.riken.jp/Linux/ubuntu-releases/14.04.2/ubuntu-14.04.4-server-amd64.iso", "memory": "2048", "preseed": "preseed.cfg", "vagrantfile_template": "tpl/vagrantfile-ubuntu1404-desktop.tpl" }
boxcutterのテンプレートからの主な変更点は、ISOイメージの取得先をオリジナルから、理研のミラーサーバに変更しています。
多分日本でダウンロードするならそのほうが早いかなと。
また、試行錯誤するために何度かpacker buildを繰り返したのですが、そのたびにISOイメージをダウンロードしてると時間かかるし、通信料がばかになりません。
PackerのビルドはローカルにISOイメージがあればダウンロードせずにそちらを参照する仕組みになっています。
その際に参照するディレクトリのPATHの設定が「iso_path」で、そこの値も変えています。
というわけであらかじめ理研のミラーサイトからISOファイルを入手して、gitのクローン先にisoディレクトリ掘って、突っ込んでおきます。
テンプレートの作成が終わったら、packer buildでテンプレートファイルを元にBoxファイルを作成します。
$ packer build -only=virtualbox-iso -var-file=ubuntu1404-desktop.json ubuntu.json virtualbox-iso output will be in this color. ==> virtualbox-iso: Downloading or copying Guest additions virtualbox-iso: Downloading or copying: file:///Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso ==> virtualbox-iso: Downloading or copying ISO virtualbox-iso: Downloading or copying: file:///Users/hoge/Documents/%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%A9/iso/ubuntu-14.04.4-server-amd64.iso ==> virtualbox-iso: Creating floppy disk... virtualbox-iso: Copying: http/preseed.cfg ==> virtualbox-iso: Creating virtual machine... ==> virtualbox-iso: Creating hard drive... ==> virtualbox-iso: Attaching floppy disk... ==> virtualbox-iso: Creating forwarded port mapping for communicator (SSH, WinRM, etc) (host port 3667) ==> virtualbox-iso: Executing custom VBoxManage commands... virtualbox-iso: Executing: modifyvm ubuntu1404-desktop --memory 2048 virtualbox-iso: Executing: modifyvm ubuntu1404-desktop --cpus 1 ==> virtualbox-iso: Starting the virtual machine... ==> virtualbox-iso: Waiting 10s for boot... ==> virtualbox-iso: Typing the boot command... ==> virtualbox-iso: Waiting for SSH to become available... ==> virtualbox-iso: Connected to SSH! ==> virtualbox-iso: Uploading VirtualBox version info (5.0.16) ==> virtualbox-iso: Uploading VirtualBox guest additions ISO... ==> virtualbox-iso: Provisioning with shell script: script/update.sh virtualbox-iso: ==> Disabling the release upgrader virtualbox-iso: ==> Updating list of repositories virtualbox-iso: Ign http://us.archive.ubuntu.com trusty InRelease virtualbox-iso: Get:1 http://us.archive.ubuntu.com trusty-updates InRelease [65.9 kB] virtualbox-iso: Get:2 http://security.ubuntu.com trusty-security InRelease [65.9 kB] virtualbox-iso: Get:3 http://us.archive.ubuntu.com trusty-backports InRelease [65.9 kB] virtualbox-iso: Hit http://us.archive.ubuntu.com trusty Release.gpg ・ ・ 中略 ・ ・ virtualbox-iso: zenity-common install virtualbox-iso: zip install virtualbox-iso: zlib1g:amd64 install virtualbox-iso: ==> Clearing last login information virtualbox-iso: 118528571+0 records in virtualbox-iso: 118528571+0 records out virtualbox-iso: 121373256704 bytes (121 GB) copied, 425.23 s, 285 MB/s virtualbox-iso: 189336+0 records in virtualbox-iso: 189336+0 records out virtualbox-iso: 193880064 bytes (194 MB) copied, 0.478528 s, 405 MB/s virtualbox-iso: ==> Clear out swap and disable until reboot virtualbox-iso: dd: error writing ‘/dev/dm-1’: No space left on device virtualbox-iso: 2049+0 records in virtualbox-iso: 2048+0 records out virtualbox-iso: 2147483648 bytes (2.1 GB) copied, 3.58034 s, 600 MB/s virtualbox-iso: dd exit code 1 is suppressed virtualbox-iso: mkswap: /dev/dm-1: warning: don't erase bootbits sectors virtualbox-iso: on whole disk. Use -f to force. virtualbox-iso: Setting up swapspace version 1, size = 2097148 KiB virtualbox-iso: no label, UUID=b604802c-0ad0-41a1-ade1-aa8d8d81dce5 virtualbox-iso: dd: error writing ‘/EMPTY’: No space left on device virtualbox-iso: 122139+0 records in virtualbox-iso: 122138+0 records out virtualbox-iso: 128071090176 bytes (128 GB) copied, 287.836 s, 445 MB/s virtualbox-iso: dd exit code 1 is suppressed virtualbox-iso: ==> Disk usage before cleanup virtualbox-iso: Filesystem Size Used Avail Use% Mounted on udev 990M 4.0K 990M 1% /dev tmpfs 201M 476K 200M 1% /run /dev/mapper/vagrant--vg-root 123G 3.4G 114G 3% / none 4.0K 0 4.0K 0% /sys/fs/cgroup none 5.0M 0 5.0M 0% /run/lock none 1001M 0 1001M 0% /run/shm none 100M 0 100M 0% /run/user /dev/sda1 236M 39M 185M 18% /boot virtualbox-iso: ==> Disk usage after cleanup virtualbox-iso: Filesystem Size Used Avail Use% Mounted on virtualbox-iso: udev 990M 8.0K 990M 1% /dev virtualbox-iso: tmpfs 201M 476K 200M 1% /run virtualbox-iso: /dev/mapper/vagrant--vg-root 123G 3.4G 114G 3% / virtualbox-iso: none 4.0K 0 4.0K 0% /sys/fs/cgroup virtualbox-iso: none 5.0M 0 5.0M 0% /run/lock virtualbox-iso: none 1001M 0 1001M 0% /run/shm virtualbox-iso: none 100M 0 100M 0% /run/user virtualbox-iso: /dev/sda1 236M 39M 185M 18% /boot ==> virtualbox-iso: Gracefully halting virtual machine... virtualbox-iso: Removing floppy drive... ==> virtualbox-iso: Preparing to export machine... virtualbox-iso: Deleting forwarded port mapping for the communicator (SSH, WinRM, etc) (host port 3667) ==> virtualbox-iso: Exporting virtual machine... virtualbox-iso: Executing: export ubuntu1404-desktop --output output-ubuntu1404-desktop-virtualbox-iso/ubuntu1404-desktop.ovf ==> virtualbox-iso: Unregistering and deleting virtual machine... ==> virtualbox-iso: Running post-processor: vagrant ==> virtualbox-iso (vagrant): Creating Vagrant box for 'virtualbox' provider virtualbox-iso (vagrant): Copying from artifact: output-ubuntu1404-desktop-virtualbox-iso/ubuntu1404-desktop-disk1.vmdk virtualbox-iso (vagrant): Copying from artifact: output-ubuntu1404-desktop-virtualbox-iso/ubuntu1404-desktop.ovf virtualbox-iso (vagrant): Renaming the OVF to box.ovf... virtualbox-iso (vagrant): Using custom Vagrantfile: tpl/vagrantfile-ubuntu1404-desktop.tpl virtualbox-iso (vagrant): Compressing: Vagrantfile virtualbox-iso (vagrant): Compressing: box.ovf virtualbox-iso (vagrant): Compressing: metadata.json virtualbox-iso (vagrant): Compressing: ubuntu1404-desktop-disk1.vmdk Build 'virtualbox-iso' finished. ==> Builds finished. The artifacts of successful builds are: --> virtualbox-iso: 'virtualbox' provider box: box/virtualbox/ubuntu1404-desktop-nocm-0.1.0.box
Boxファイルの登録
作成したBoxファイルをvagrantに登録します。
登録のためのコマンドはvagrant box add {登録名} {Boxファイルのパス | URL}です。
登録名は任意ですが、今回は「ubuntu1404-desktop」にしておきます。
$ vagrant box add ubuntu1404-desktop box/virtualbox/ubuntu1404-desktop-nocm-0.1.0.box ==> box: Box file was not detected as metadata. Adding it directly... ==> box: Adding box '1404-desktop' (v0) for provider: box: Unpacking necessary files from: file:///Users/hoge/Documents/git/boxcutter/ubuntu/box/virtualbox/ubuntu1404-desktop-nocm-0.1.0.box ==> box: Successfully added box '1404-desktop' (v0) for 'virtualbox'!
仮想マシンの起動
vagrant initをすることでVagrantfileのテンプレートファイルが作成されます。
引数には先ほど登録したBoxファイルの名前を指定します。
$ vagrant init ubuntu1404-desktop A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant. $ ls Vagrantfile
Vagrantファイルの中身を確認。
Vagrantfile
# -*- mode: ruby -*- # vi: set ft=ruby : # All Vagrant configuration is done below. The "2" in Vagrant.configure # configures the configuration version (we support older styles for # backwards compatibility). Please don't change it unless you know what # you're doing. Vagrant.configure(2) do |config| # The most common configuration options are documented and commented below. # For a complete reference, please see the online documentation at # https://docs.vagrantup.com. # Every Vagrant development environment requires a box. You can search for # boxes at https://atlas.hashicorp.com/search. config.vm.box = "ubuntu1404-desktop" # Disable automatic box update checking. If you disable this, then # boxes will only be checked for updates when the user runs # `vagrant box outdated`. This is not recommended. # config.vm.box_check_update = false # Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine. In the example below, # accessing "localhost:8080" will access port 80 on the guest machine. # config.vm.network "forwarded_port", guest: 80, host: 8080 # Create a private network, which allows host-only access to the machine # using a specific IP. # config.vm.network "private_network", ip: "192.168.33.10" # Create a public network, which generally matched to bridged network. # Bridged networks make the machine appear as another physical device on # your network. # config.vm.network "public_network" # Share an additional folder to the guest VM. The first argument is # the path on the host to the actual folder. The second argument is # the path on the guest to mount the folder. And the optional third # argument is a set of non-required options. # config.vm.synced_folder "../data", "/vagrant_data" # Provider-specific configuration so you can fine-tune various # backing providers for Vagrant. These expose provider-specific options. # Example for VirtualBox: # # config.vm.provider "virtualbox" do |vb| # # Display the VirtualBox GUI when booting the machine # vb.gui = true # # # Customize the amount of memory on the VM: # vb.memory = "1024" # end # # View the documentation for the provider you are using for more # information on available options. # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies # such as FTP and Heroku are also available. See the documentation at # https://docs.vagrantup.com/v2/push/atlas.html for more information. # config.push.define "atlas" do |push| # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" # end # Enable provisioning with a shell script. Additional provisioners such as # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the # documentation for more information about their specific syntax and use. # config.vm.provision "shell", inline: <<-SHELL # sudo apt-get update # sudo apt-get install -y apache2 # SHELL end
今回立ち上げるゲストOSは日本語化のベースにするだけで、特にプロビジョニングなどはしないため、修正は行わずそのまま使います。
config.vm.boxの値のが正しく設定されていることだけ確認できればOKです。
というわけで、vagrant initに続けてvagrant upで仮想マシンを立ち上げます。
$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'ubuntu1404-desktop'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: ubuntu1404-desktop_default_1459864237341_70016 ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 22 (guest) => 2222 (host) (adapter 1) ==> default: Running 'pre-boot' VM customizations... ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Remote connection disconnect. Retrying... default: Warning: Remote connection disconnect. Retrying... default: default: Vagrant insecure key detected. Vagrant will automatically replace default: this with a newly generated keypair for better security. default: default: Inserting generated public key within guest... default: Removing insecure key from the guest if it's present... default: Key inserted! Disconnecting and reconnecting using new SSH key... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Mounting shared folders... default: /vagrant => /Users/hoge/Documents/vagrant/ubuntu1404-desktop
日本語環境の設定
以下、ゲストOSのUbuntuでの作業になります。
ソフトウェアアップデート
初めてUbuntuを立ち上げるとソフトウェアアップデートの通知が来るので、アップデートしておきます。
再起動が必要な設定がこの後もあるので、ここでは再起動しないことにします。
日付のローカライズ
タイムゾーンをTokyoに設定します。
System Settings > Time&Date を選択します。
地図をクリックしたり、フォームに直接入力するなどしてLocationをTokyoに設定。
ついでにClockの設定も好みに合わせて設定しておきます。
言語のローカライズ
System Settings > Language Support を選択します。
Language Supportを開くと、「言語サポートに必要なソフトウェアのインストールが完了していないので、インストールしてください」的なことを言われます。
英語のサポートなので必要ないかもしれませんが、一応インストールします。
本題の日本語化の作業に入ります。
Install / Remove Languages を選択します。
Japaneseにチェックを入れて、Apply Changesをクリック。
日本語の言語サポートに必要なソフトウェアのインストールが始まります。
インストールが終了したら、日本語の優先度を上げるため言語のリストの一番上に「日本語」が来るようにドラッグします。
日本語を一番上にしたら、Apply System-Wideをクリックし、システム全体に適用します。
次に通貨や日付のフォーマットを日本に合わせる設定を行います。
Regional Format タブを選択します。
日本語を選択し、Apply System-Wideをクリックし、システム全体に適用します。
設定直後はExampleが正しく反映されません。
Language Supportを開き直すと正しく反映されるので、開き直して確認します。
ここまで設定したら、仮想マシンを再起動します。
再起動はホストOSのコンソールからvagrant reloadを叩いて行います。
再起動が済むとフォルダ名を日本語にリネームするか聞かれますので、好みでリネームするかどうか選択してください。
ちなみに私はしませんでした。
キーマップのローカライズ
キーボードのレイアウトがUS配列になっているので、日本語配列に設定します。
システム設定 > テキスト入力を選択。
日本語(Anthy)を選択して右下に現れるツールアイコンをクリックします。
IBus-Anthyの設定ダイアログが開くので、入力タイプを選択します。
キーボードレイアウトをデフォルトからjpに変更します。
ibusを再起動してくださいと表示されますが、一度ログアウトしてログインしなおすだけで大丈夫です。
ここまでで日本語化の作業は終わりになります。
ホストOSに戻ってvagrant haltで仮想マシンを止めてください。
日本語環境にした仮想環境のBoxファイルの出力
日本語設定を行った仮想マシンのVagrantfileがあるディレクトリでvagrant packageを実行することで、日本語設定がされた状態のBoxファイルを作成することができます。
下記例では--output オプションで出力されるBoxファイルのファイル名を指定しています。
指定しないとデフォルトの package.boxというファイル名で出力されます。
$ vagrant package --output ubuntu1404-ja-desktop-nocm-0.1.0.box ==> default: Clearing any previously set forwarded ports... ==> default: Exporting VM... ==> default: Compressing package to: /Users/hoge/Documents/vagrant/ubuntu1404-desktop/ubuntu1404-ja-desktop-nocm-0.1.0.box
ここまでの作業で日本語環境になったUbuntuが使えるようになりました。
利用のする際はBoxファイルの登録で行ったようにvagrant box addをしてvagrant init、vagrant upをするだけです。
今後はこのBoxファイルをベースに、Vagrantfileでプロビジョニングして色々と開発環境を作ってみようと思います。
参考
Vagrantの既存Boxに日本語環境 + GuestAdditions + Chefを入れ、新しいBoxとして追加する - メモ的な思考的な
Ubuntu 13.10 その7 - 日本語環境の構築・Ubuntu Japanese Teamのリポジトリーを追加する - kledgeb
【Vagrant】Packerでboxファイルの作成
以前、vagrantの初歩的な使い方について記事を挙げましたが、その際に利用したBoxファイルはvagrantboxからダウンロードしていました。
今回は他人が作ったBoxファイルを拝借していたのを、自作にしようというのが趣旨です。
環境
- OS X 10.10.5
- Vagrant 1.8.1
- VirtualBox 5.0.16
- Packer 0.10.0
Packerの入手
Boxファイルを作成するツールは幾つかあるみたいですが、一番メジャーそうなPackerを使います。
公式サイトからツールをダウンロードしてきます。
ダウンロードしたファイル(packer_0.10.0_darwin_amd64.zip)を解凍すると"packer"になります。
自分は上記pakerを"/usr/local/bin/"ディレクトリに移動しました。
テンプレートの入手
一からBoxファイルのテンプレート(設定ファイル)を作成するのは大変なためboxcutterからテンプレートを入手します。
今回はUbuntuのBoxファイルを作るので、Ubuntuのリポジトリをgitクローンしておきます。
テンプレートの設定値を変えることで、作成する仮想マシンのディスク容量やメモリ量、ISOファイルのダウンロード先などを変更できますが、今回はいじらず、デフォルトで作成します。
$ git clone https://github.com/boxcutter/ubuntu.git Cloning into 'ubuntu'... remote: Counting objects: 1790, done. remote: Compressing objects: 100% (13/13), done. remote: Total 1790 (delta 3), reused 0 (delta 0), pack-reused 1776 Receiving objects: 100% (1790/1790), 323.25 KiB | 21.00 KiB/s, done. Resolving deltas: 100% (1178/1178), done. Checking connectivity... done. $ cd ubuntu $ ls -la -rw-r--r-- 1 hoge staff 9630 3 21 03:04 ubuntu1510.json -rw-r--r-- 1 hoge staff 421 3 21 03:04 ubuntu1404.json -rw-r--r-- 1 hoge staff 544 3 21 03:04 ubuntu1404-i386.json -rw-r--r-- 1 hoge staff 455 3 21 03:04 ubuntu1404-docker.json -rw-r--r-- 1 hoge staff 421 3 21 03:04 ubuntu1204.json -rw-r--r-- 1 hoge staff 544 3 21 03:04 ubuntu1204-i386.json -rw-r--r-- 1 hoge staff 455 3 21 03:04 ubuntu1204-docker.json -rw-r--r-- 1 hoge staff 547 3 21 03:04 ubuntu1204-desktop.json drwxr-xr-x 6 hoge staff 204 3 21 03:04 tpl drwxr-xr-x 5 hoge staff 170 3 21 03:04 test drwxr-xr-x 14 hoge staff 476 3 21 03:04 script drwxr-xr-x 5 hoge staff 170 3 21 03:04 floppy -rw-r--r-- 1 hoge staff 218 3 21 03:04 custom-script.sh drwxr-xr-x 10 hoge staff 340 3 21 03:04 bin -rw-r--r-- 1 hoge staff 7 3 21 03:04 VERSION -rw-r--r-- 1 hoge staff 8381 3 21 03:04 README.md -rw-r--r-- 1 hoge staff 4170 3 21 03:04 Makefile -rw-r--r-- 1 hoge staff 11335 3 21 03:04 LICENSE -rw-r--r-- 1 hoge staff 4528 3 21 03:04 CHANGELOG.md -rw-r--r-- 1 hoge staff 887 3 21 03:04 AUTHORS drwxr-xr-x 2 hoge staff 68 3 23 07:29 tmp -rw-r--r-- 1 hoge staff 8580 3 23 19:08 ubuntu.json drwxr-xr-x 6 hoge staff 204 3 25 21:41 iso drwxr-xr-x 3 hoge staff 102 3 25 21:46 packer_cache drwxr-xr-x 6 hoge staff 204 3 25 21:50 http -rw-r--r-- 1 hoge staff 565 3 27 10:48 ubuntu1404-desktop.json drwxr-xr-x 5 hoge staff 170 3 27 15:26 box
boxファイルの作成
packer buildでbuildを実行。
boxcutterのテンプレートはpacker buildの-var-fileオプションで設定するテンプレートを組み合わせることで、 様々なOSバージョンやアーキテクチャに対応できるように構成されています。
今回はUbuntu14.04のデスクトップ版のBoxファイルを作成するため、ubuntu1404-desktop.jsonとubuntu.jsonを組み合わせてbuildします。
ちなみに、packer buildはISOファイルのダウンロードなどあるためかなり時間がかかります(1時間くらい)。
気長に待ちましょう。
# 今回作成するBoxファイルはVirtualBox向けのものだけなので、オプションに-only=virtualbox-isoを設定しています $ packer build -only=virtualbox-iso -var-file=ubuntu1404-desktop.json ubuntu.json virtualbox-iso output will be in this color. ==> virtualbox-iso: Downloading or copying Guest additions virtualbox-iso: Downloading or copying: file:///Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso ==> virtualbox-iso: Downloading or copying ISO virtualbox-iso: Downloading or copying: file:///Users/hoge/Documents/ubuntu-14.04.4-server-amd64.iso ==> virtualbox-iso: Creating floppy disk... virtualbox-iso: Copying: http/preseed.cfg ==> virtualbox-iso: Creating virtual machine... ==> virtualbox-iso: Creating hard drive... ==> virtualbox-iso: Attaching floppy disk... ==> virtualbox-iso: Creating forwarded port mapping for communicator (SSH, WinRM, etc) (host port 2590) ==> virtualbox-iso: Executing custom VBoxManage commands... virtualbox-iso: Executing: modifyvm ubuntu1404-desktop --memory 2048 virtualbox-iso: Executing: modifyvm ubuntu1404-desktop --cpus 1 ==> virtualbox-iso: Starting the virtual machine... ==> virtualbox-iso: Waiting 10s for boot... ==> virtualbox-iso: Typing the boot command... ==> virtualbox-iso: Waiting for SSH to become available... ==> virtualbox-iso: Connected to SSH! ==> virtualbox-iso: Uploading VirtualBox version info (5.0.16) ==> virtualbox-iso: Uploading VirtualBox guest additions ISO... ==> virtualbox-iso: Provisioning with shell script: script/update.sh virtualbox-iso: ==> Disabling the release upgrader virtualbox-iso: ==> Updating list of repositories virtualbox-iso: Ign http://us.archive.ubuntu.com trusty InRelease virtualbox-iso: Hit http://security.ubuntu.com trusty-security InRelease virtualbox-iso: Hit http://us.archive.ubuntu.com trusty-updates InRelease #〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜(中略)〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜 virtualbox-iso: 0 upgraded, 1296 newly installed, 0 to remove and 26 not upgraded. virtualbox-iso: Need to get 549 MB of archives. virtualbox-iso: After this operation, 2,093 MB of additional disk space will be used. virtualbox-iso: Get:1 http://us.archive.ubuntu.com/ubuntu/ trusty/main libavahi-common-data amd64 0.6.31-4ubuntu1 [21.2 kB] virtualbox-iso: Get:2 http://us.archive.ubuntu.com/ubuntu/ trusty/main libavahi-common3 amd64 0.6.31-4ubuntu1 [21.7 kB] virtualbox-iso: Get:3 http://us.archive.ubuntu.com/ubuntu/ trusty/main libavahi-client3 amd64 0.6.31-4ubuntu1 [25.1 kB] virtualbox-iso: Get:4 http://us.archive.ubuntu.com/ubuntu/ trusty-updates/main libcups2 amd64 1.7.2-0ubuntu1.7 [179 kB] virtualbox-iso: Get:5 http://us.archive.ubuntu.com/ubuntu/ trusty-updates/main libcupsmime1 amd64 1.7.2-0ubuntu1.7 [12.1 kB] virtualbox-iso: Get:6 http://us.archive.ubuntu.com/ubuntu/ trusty/main libpaper1 amd64 1.1.24+nmu2ubuntu3 [13.4 kB] #〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜(中略)〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜 virtualbox-iso: Get:1292 http://us.archive.ubuntu.com/ubuntu/ trusty/main unity-lens-friends amd64 0.1.3+14.04.20140317-0ubuntu1 [22.9 kB] virtualbox-iso: Get:1293 http://us.archive.ubuntu.com/ubuntu/ trusty/main unity-scope-gdrive all 0.9+13.10.20130723-0ubuntu1 [11.6 kB] virtualbox-iso: Get:1294 http://us.archive.ubuntu.com/ubuntu/ trusty/main usb-modeswitch-data all 20140327-1 [27.0 kB] virtualbox-iso: Get:1295 http://us.archive.ubuntu.com/ubuntu/ trusty/main usb-modeswitch amd64 2.1.1+repack0-1ubuntu1 [50.0 kB] virtualbox-iso: Get:1296 http://us.archive.ubuntu.com/ubuntu/ trusty/main xfonts-mathml all 6ubuntu1 [42.5 kB] virtualbox-iso: [sudo] password for vagrant: debconf: unable to initialize frontend: Dialog virtualbox-iso: debconf: (Dialog frontend will not work on a dumb terminal, an emacs shell buffer, or without a controlling terminal.) virtualbox-iso: debconf: falling back to frontend: Readline virtualbox-iso: debconf: unable to initialize frontend: Readline virtualbox-iso: debconf: (This frontend requires a controlling tty.) virtualbox-iso: debconf: falling back to frontend: Teletype virtualbox-iso: dpkg-preconfigure: unable to re-open stdin: virtualbox-iso: Fetched 549 MB in 34min 7s (268 kB/s) virtualbox-iso: Selecting previously unselected package libavahi-common-data:amd64. virtualbox-iso: (Reading database ... 61160 files and directories currently installed.) virtualbox-iso: Preparing to unpack .../libavahi-common-data_0.6.31-4ubuntu1_amd64.deb ... virtualbox-iso: Unpacking libavahi-common-data:amd64 (0.6.31-4ubuntu1) ... #〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜(中略)〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜 virtualbox-iso: zenity-common install virtualbox-iso: zip install virtualbox-iso: zlib1g:amd64 install virtualbox-iso: ==> Clearing last login information virtualbox-iso: 118528559+0 records in virtualbox-iso: 118528559+0 records out virtualbox-iso: 121373244416 bytes (121 GB) copied, 438.839 s, 277 MB/s virtualbox-iso: 189341+0 records in virtualbox-iso: 189341+0 records out virtualbox-iso: 193885184 bytes (194 MB) copied, 0.553525 s, 350 MB/s virtualbox-iso: ==> Clear out swap and disable until reboot virtualbox-iso: dd: error writing ‘/dev/dm-1’: No space left on device virtualbox-iso: 2049+0 records in virtualbox-iso: 2048+0 records out virtualbox-iso: 2147483648 bytes (2.1 GB) copied, 3.58726 s, 599 MB/s virtualbox-iso: dd exit code 1 is suppressed virtualbox-iso: mkswap: /dev/dm-1: warning: don't erase bootbits sectors virtualbox-iso: on whole disk. Use -f to force. virtualbox-iso: Setting up swapspace version 1, size = 2097148 KiB virtualbox-iso: no label, UUID=a02f609d-1d2e-4086-8ed6-b3c1340a89cc virtualbox-iso: dd: error writing ‘/EMPTY’: No space left on device virtualbox-iso: 122139+0 records in virtualbox-iso: dd exit code 1 is suppressed virtualbox-iso: 122138+0 records out virtualbox-iso: 128071041024 bytes (128 GB) copied, 292.316 s, 438 MB/s virtualbox-iso: ==> Disk usage before cleanup virtualbox-iso: Filesystem Size Used Avail Use% Mounted on udev 990M 4.0K 990M 1% /dev tmpfs 201M 476K 200M 1% /run /dev/mapper/vagrant--vg-root 123G 3.4G 114G 3% / none 4.0K 0 4.0K 0% /sys/fs/cgroup none 5.0M 0 5.0M 0% /run/lock none 1001M 0 1001M 0% /run/shm none 100M 0 100M 0% /run/user /dev/sda1 236M 39M 185M 18% /boot virtualbox-iso: ==> Disk usage after cleanup virtualbox-iso: Filesystem Size Used Avail Use% Mounted on virtualbox-iso: udev 990M 8.0K 990M 1% /dev virtualbox-iso: tmpfs 201M 476K 200M 1% /run virtualbox-iso: /dev/mapper/vagrant--vg-root 123G 3.4G 114G 3% / virtualbox-iso: none 4.0K 0 4.0K 0% /sys/fs/cgroup virtualbox-iso: none 5.0M 0 5.0M 0% /run/lock virtualbox-iso: none 1001M 0 1001M 0% /run/shm virtualbox-iso: none 100M 0 100M 0% /run/user virtualbox-iso: /dev/sda1 236M 39M 185M 18% /boot ==> virtualbox-iso: Gracefully halting virtual machine... virtualbox-iso: Removing floppy drive... ==> virtualbox-iso: Preparing to export machine... virtualbox-iso: Deleting forwarded port mapping for the communicator (SSH, WinRM, etc) (host port 2590) ==> virtualbox-iso: Exporting virtual machine... virtualbox-iso: Executing: export ubuntu1404-desktop --output output-ubuntu1404-desktop-virtualbox-iso/ubuntu1404-desktop.ovf ==> virtualbox-iso: Unregistering and deleting virtual machine... ==> virtualbox-iso: Running post-processor: vagrant ==> virtualbox-iso (vagrant): Creating Vagrant box for 'virtualbox' provider virtualbox-iso (vagrant): Copying from artifact: output-ubuntu1404-desktop-virtualbox-iso/ubuntu1404-desktop-disk1.vmdk virtualbox-iso (vagrant): Copying from artifact: output-ubuntu1404-desktop-virtualbox-iso/ubuntu1404-desktop.ovf virtualbox-iso (vagrant): Renaming the OVF to box.ovf... virtualbox-iso (vagrant): Using custom Vagrantfile: tpl/vagrantfile-ubuntu1404-desktop.tpl virtualbox-iso (vagrant): Compressing: Vagrantfile virtualbox-iso (vagrant): Compressing: box.ovf virtualbox-iso (vagrant): Compressing: metadata.json virtualbox-iso (vagrant): Compressing: ubuntu1404-desktop-disk1.vmdk Build 'virtualbox-iso' finished. ==> Builds finished. The artifacts of successful builds are: --> virtualbox-iso: 'virtualbox' provider box: box/virtualbox/ubuntu1404-desktop-nocm-0.1.0.box
ここまででBoxファイルの作成は完了です。
box/virtualboxディレクトリ下に
ubuntu1404-desktop-nocm-0.1.0.boxというBoxファイルが出来上がっているはずなので、確認してみてください。
vagrantへのbox追加
これ以降は以前挙げたVagrantの使い方と同じなのですが、一応手順載せておきます。
作業は適当なディレクトリを掘って行ってください。
vagrant box addでboxファイルを登録
$ vagrant box add test box/virtualbox/ubuntu1404-desktop-nocm-0.1.0.box ==> box: Box file was not detected as metadata. Adding it directly... ==> box: Adding box 'test' (v0) for provider: box: Unpacking necessary files from: file:///Users/hoge/Documents/ubuntu/box/virtualbox/ubuntu1404-desktop-nocm-0.1.0.box ==> box: Successfully added box 'test' (v0) for 'virtualbox'!
Vagrantfileの作成
vagrant initでVagrantfaileファイルを生成
$ vagrant init test A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant.
vagrantの実行
$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'test2'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: ubuntu1404-desktop_default_1458702162155_73549 ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 22 (guest) => 2222 (host) (adapter 1) ==> default: Running 'pre-boot' VM customizations... ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key default: default: Vagrant insecure key detected. Vagrant will automatically replace default: this with a newly generated keypair for better security. default: default: Inserting generated public key within guest... default: Removing insecure key from the guest if it's present... default: Key inserted! Disconnecting and reconnecting using new SSH key... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Mounting shared folders... default: /vagrant => /Users/hoge/Documents/vagrant/ubuntu1404-desktop
うまく起動したでしょうか?
Boxファイルを自作しておけば、中身が分かるし、Boxファイルを余所からダウンロードする時間も省けるため、Boxファイルの登録が気軽にできて良いかと思います。
参考
Appendix B. Automating the installation using preseeding
Packerをつかって3ステップでVagrantのBoxを作る - Qiita
PreseedによるUbuntuの自動インストール入門 - Qiita
日本人向け Packer スクリプト差分 for Ubuntu Trusty - 来年読む。
【Vagrant】インストールと基本コマンド
環境
- OS X 10.10.5
- Vagrant 1.8.1
- VirtualBox 5.0.16 r105871
用語
プロバイダ
Virtual Boxとか、VM Wareとか仮想マシン本体のこと。 EC2なんかもプロバイダとして利用出来るらしい。
プロビジョニング
Chefとか。 ミドルウェアのインストールや設定を行うツール。 シェルスクリプトでも出来るみたいで、Chefを使う気満々だったのが少し削がれた。
Boxファイル
仮想マシンを起動する際のベースとなるイメージファイル。 通常、OSイメージをベースにvagrantユーザの作成・sshd起動・プロビジョニングツールのインストールなど最小限の設定を行う。
Vagrantfile
仮想マシンのスペックやプロビジョニングツールの指定などの構成を記述するファイル。 Rubyで記述する。 こいつさえあれば、どんな環境でも同じ仮想マシンが構築できる。
Vagrantインストール
公式サイトからインストーラを入手、ポチポチしてインストールします。
バージョン確認
$ vagrant -v
Vagrant 1.8.1
ヘルプ
$ vagrant -h Usage: vagrant [options] <command> [<args>] -v, --version Print the version and exit. -h, --help Print this help. Common commands: box manages boxes: installation, removal, etc. connect connect to a remotely shared Vagrant environment destroy stops and deletes all traces of the vagrant machine global-status outputs status Vagrant environments for this user halt stops the vagrant machine help shows the help for a subcommand init initializes a new Vagrant environment by creating a Vagrantfile login log in to HashiCorp's Atlas package packages a running vagrant environment into a box plugin manages plugins: install, uninstall, update, etc. port displays information about guest port mappings powershell connects to machine via powershell remoting provision provisions the vagrant machine push deploys code in this environment to a configured destination rdp connects to machine via RDP reload restarts vagrant machine, loads new Vagrantfile configuration resume resume a suspended vagrant machine share share your Vagrant environment with anyone in the world snapshot manages snapshots: saving, restoring, etc. ssh connects to machine via SSH ssh-config outputs OpenSSH valid configuration to connect to the machine status outputs status of the vagrant machine suspend suspends the machine up starts and provisions the vagrant environment version prints current and latest Vagrant version For help on any individual command run `vagrant COMMAND -h` Additional subcommands are available, but are either more advanced or not commonly used. To see all subcommands, run the command `vagrant list-commands`. # vagrant [subcmd] -h でサブコマンドのヘルプも参照できる $ vagrant box -h Usage: vagrant box <subcommand> [<args>] Available subcommands: add list outdated remove repackage update For help on any individual subcommand run `vagrant box <subcommand> -h`
Boxファイルのインストール
Boxファイルは自分で作成可能ですが、vagrantbox.esで配布もされています。
自作は必要ができたら取り組むとして今回はvagrantboxから入手します。
Boxファイルの追加
# vagrant box add [box名(任意)] [URL or PATH] $ vagrant box add Ubuntu14.04_daily_Cloud_Image_amd64 https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box ==> box: Box file was not detected as metadata. Adding it directly... ==> box: Adding box 'Ubuntu14.04_daily_Cloud_Image_amd64' (v0) for provider: box: Downloading: https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box ==> box: Successfully added box 'Ubuntu14.04_daily_Cloud_Image_amd64' (v0) for 'virtualbox'! # 確認 $ vagrant box list Ubuntu14.04_daily_Cloud_Image_amd64 (virtualbox, 0)
Boxファイルの削除
# vagrant box remove [box名]
$ vagrant box remove Ubuntu14.04_daily_Cloud_Image_amd64
Vagrantfileの作成
Vagrantfileは"vagrant init [box名]"を叩くと作成されます。
# vagrant init [box名] $ vagrant init Ubuntu14.04_daily_Cloud_Image_amd64 A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant. # 確認 $ ls Vagrantfile
vagrant init で作成されたvagrantファイルにはデフォルトで色々書かれているので、それを参考に設定を記述してみた。
ちなみに今回設定していることは以下
Vagrantfile
# -*- mode: ruby -*- # vi: set ft=ruby : # All Vagrant configuration is done below. The "2" in Vagrant.configure # configures the configuration version (we support older styles for # backwards compatibility). Please don't change it unless you know what # you're doing. Vagrant.configure(2) do |config| # The most common configuration options are documented and commented below. # For a complete reference, please see the online documentation at # https://docs.vagrantup.com. # Every Vagrant development environment requires a box. You can search for # boxes at https://atlas.hashicorp.com/search. config.vm.box = "Ubuntu14.04_daily_Cloud_Image_amd64" # Disable automatic box update checking. If you disable this, then # boxes will only be checked for updates when the user runs # `vagrant box outdated`. This is not recommended. # config.vm.box_check_update = false # Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine. In the example below, # accessing "localhost:8080" will access port 80 on the guest machine. # config.vm.network "forwarded_port", guest: 80, host: 8080 # Create a private network, which allows host-only access to the machine # using a specific IP. # config.vm.network "private_network", ip: "192.168.33.10" # Create a public network, which generally matched to bridged network. # Bridged networks make the machine appear as another physical device on # your network. # config.vm.network "public_network" # Share an additional folder to the guest VM. The first argument is # the path on the host to the actual folder. The second argument is # the path on the guest to mount the folder. And the optional third # argument is a set of non-required options. # config.vm.synced_folder "../data", "/vagrant_data" # Provider-specific configuration so you can fine-tune various # backing providers for Vagrant. These expose provider-specific options. # Example for VirtualBox: # config.vm.provider "virtualbox" do |vb| # Display the VirtualBox GUI when booting the machine ### (1)仮想マシンをGUIで起動する(ウィンドウを立ち上げる) vb.gui = true # # Customize the amount of memory on the VM: # vb.memory = "1024" end # # View the documentation for the provider you are using for more # information on available options. # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies # such as FTP and Heroku are also available. See the documentation at # https://docs.vagrantup.com/v2/push/atlas.html for more information. # config.push.define "atlas" do |push| # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" # end # Enable provisioning with a shell script. Additional provisioners such as # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the # documentation for more information about their specific syntax and use. ### (2)起動時にパッケージの更新とデスクトップのインストールをする ### プロビジョニングは初回のvagrant upでしか走らないので注意 config.vm.provision "shell", inline: <<-SHELL sudo apt-get update sudo apt-get install -y ubuntu-desktop SHELL end
仮想マシンの起動と停止
起動
vagrantで仮想マシンを起動するには、Vagrantfileがあるディレクトリでvagrant upを叩きます。
$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'Ubuntu14.04_daily_Cloud_Image_amd64'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: Ubuntu1404_daily_Cloud_Image_amd64_default_1458397444446_89786 ==> default: Clearing any previously set forwarded ports... ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 22 (guest) => 2222 (host) (adapter 1) ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Remote connection disconnect. Retrying... default: default: Vagrant insecure key detected. Vagrant will automatically replace default: this with a newly generated keypair for better security. default: default: Inserting generated public key within guest... default: Removing insecure key from the guest if it's present... default: Key inserted! Disconnecting and reconnecting using new SSH key... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... default: The guest additions on this VM do not match the installed version of default: VirtualBox! In most cases this is fine, but in rare cases it can default: prevent things such as shared folders from working properly. If you see default: shared folder errors, please make sure the guest additions within the default: virtual machine match the version of VirtualBox you have installed on default: your host and reload your VM. default: default: Guest Additions Version: 4.3.36 default: VirtualBox Version: 5.0 ==> default: Mounting shared folders... default: /vagrant => /Users/hoge/Documents/vagrant/Ubuntu14.04_daily_Cloud_Image_amd64
Vagrantファイルにて"vb.gui = true"と設定しているので、VirtualBoxのウィンドウで立ち上がる。
初期ユーザは
となってます。
停止
$ vagrant halt
==> default: Attempting graceful shutdown of VM...
廃棄
"vagrant destroy"を叩くと、仮想マシンを廃棄できます。
プロビジョニングの設定などは初期起動時のみしか読み込まれないので、Vagrantfileを書き直した時などは一度仮想マシンを廃棄したほうが良いです。
$ vagrant destroy default: Are you sure you want to destroy the 'default' VM? [y/N] y ==> default: Destroying VM and associated drives...
参考
vagrant
ubuntu
【Python】websocketクライアントの実装
やっつけ。
環境
前提
- websocket-clientパッケージをインストールしていること
websocket-client 0.35.0 : Python Package Index
Type “python setup.py install” or “pip install websocket-client” to install.
自分はpipでインストールしました。
- 別途websocketサーバがあること
ソース
wsclient.py
#!/usr/bin/python # -*- coding: utf-8 -*- import sys import websocket import thread import time def on_message(ws, message): print "debug: called on_message" print message def on_error(ws, error): print "debug: called on_error" print error def on_close(ws): print "### closed ###" def on_open(ws): def run(*args): print("debug: websocket is opened") while(True): line = sys.stdin.readline() if line != "": print "debug: sending value is " + line ws.send(line) thread.start_new_thread(run, ()) if __name__ == "__main__": param = sys.argv url = "デフォルトの接続先"; if len(param) == 2: url = param[1] print "debug: param[1] is " + param[1] websocket.enableTrace(True) ws = websocket.WebSocketApp(url, on_message = on_message, on_error = on_error, on_close = on_close) ws.on_open = on_open ws.run_forever()
使い方
スクリプトとして実行することを想定しています。
接続
ターミナルを開いて上記ファイルを実行
$ ./wsclient.py
接続先に誤りがなければ、以下のようにハンドシェイクのリクエストとレスポンスが帰ってきます。
正常
--- request header --- GET /hoge HTTP/1.1 Upgrade: websocket Connection: Upgrade Host: example.com:443 Origin: http://example.com Sec-WebSocket-Key: JOtIu/5xaswrI2a5IRh/Wg== Sec-WebSocket-Version: 13 ----------------------- --- response header --- HTTP/1.1 101 Switching Protocols Connection: Upgrade Sec-WebSocket-Accept: CjFvo17ay0vliMi8Pdgm8Ve7LME= Upgrade: WebSocket ----------------------- debug: websocket is opened
接続先に誤りがある場合は以下のようになります。
接続先に誤りがある場合
$ ./wsclient.py ほげ debug: param[1] is ほげ debug: called on_error url is invalid
ちなみにスクリプトの第一引数にURLを渡せるようにしてあります。渡さない場合はソースに直書きしてあるURLをデフォルトの接続先として接続するようになってます。
メッセージ送信
標準入力からメッセージを投げることができます。
適当にタイプして、エンターを叩くとタイプされたテキストをサーバに送信します。
ターミナル
--- response header --- HTTP/1.1 101 Switching Protocols Connection: Upgrade Sec-WebSocket-Accept: CjFvo17ay0vliMi8Pdgm8Ve7LME= Upgrade: WebSocket ----------------------- debug: websocket is opened this is test message debug: sending value is this is test message send: '\x81\x95J\x0c5\xad>d\\\xdejeF\x8d>iF\xd9jaP\xde9mR\xc8@' hoge debug: sending value is hoge send: '\x81\x85\x9f"[\xea\xf7M<\x8f\x95'
分かりにくいですが、「this is test message」と「hoge」が入力した文字です。
使い道
あるのかな? 笑
自分はサクッとサーバのレスポンスをテストしたかったので作ってみました。
参考
websocket-client 0.35.0 : Python Package Index
Pythonで学ぶ 基礎からのプログラミング入門 (8) ユーザーからプログラムへの入力をする方法 | マイナビニュース
【CentOS6】Let's Encryptを利用してApacheをHTTPS対応する
2016/12/02 追記
設定がめっちゃ簡単になってるみたい。
無償SSL/TLS証明書の Let’s Encrypt の設定が劇的に簡単になっていた | Webセキュリティの小部屋
こちらの記事を参考にした方が幸せになれそうです。
いちおう現在(2016/11/27)も、当方の記事の方法で証明書の発行はできてます。
環境
手順
git
Let's EncryptはGitHubから入手するので、入っていなかったらgitをインストールしておく。
$ yum install -y git 読み込んだプラグイン:fastestmirror インストール処理の設定をしています Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * epel: ftp.iij.ad.jp * extras: ftp.iij.ad.jp * rpmforge: ftp.kddilabs.jp * updates: ftp.iij.ad.jp 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> Package git.x86_64 0:1.7.1-3.el6_4.1 will be インストール --> 依存性の処理をしています: perl-Git = 1.7.1-3.el6_4.1 のパッケージ: git-1.7.1-3.el6_4.1.x86_64 --> 依存性の処理をしています: rsync のパッケージ: git-1.7.1-3.el6_4.1.x86_64 --> 依存性の処理をしています: perl(Git) のパッケージ: git-1.7.1-3.el6_4.1.x86_64 --> 依存性の処理をしています: perl(Error) のパッケージ: git-1.7.1-3.el6_4.1.x86_64 --> トランザクションの確認を実行しています。 ---> Package perl-Error.noarch 1:0.17015-4.el6 will be インストール ---> Package perl-Git.noarch 0:1.7.1-3.el6_4.1 will be インストール ---> Package rsync.x86_64 0:3.0.6-12.el6 will be インストール --> 依存性解決を終了しました。 依存性を解決しました ============================================================================================================================================================================================== パッケージ アーキテクチャ バージョン リポジトリー 容量 ============================================================================================================================================================================================== インストールしています: git x86_64 1.7.1-3.el6_4.1 base 4.6 M 依存性関連でのインストールをします。: perl-Error noarch 1:0.17015-4.el6 base 29 k perl-Git noarch 1.7.1-3.el6_4.1 base 28 k rsync x86_64 3.0.6-12.el6 base 335 k トランザクションの要約 ============================================================================================================================================================================================== インストール 4 パッケージ 総ダウンロード容量: 5.0 M インストール済み容量: 15 M パッケージをダウンロードしています: (1/4): git-1.7.1-3.el6_4.1.x86_64.rpm | 4.6 MB 00:01 (2/4): perl-Error-0.17015-4.el6.noarch.rpm | 29 kB 00:00 (3/4): perl-Git-1.7.1-3.el6_4.1.noarch.rpm | 28 kB 00:00 (4/4): rsync-3.0.6-12.el6.x86_64.rpm | 335 kB 00:00 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 合計 1.8 MB/s | 5.0 MB 00:02 rpm_check_debug を実行しています トランザクションのテストを実行しています トランザクションのテストを成功しました トランザクションを実行しています インストールしています : 1:perl-Error-0.17015-4.el6.noarch 1/4 インストールしています : rsync-3.0.6-12.el6.x86_64 2/4 インストールしています : perl-Git-1.7.1-3.el6_4.1.noarch 3/4 インストールしています : git-1.7.1-3.el6_4.1.x86_64 4/4 Verifying : git-1.7.1-3.el6_4.1.x86_64 1/4 Verifying : perl-Git-1.7.1-3.el6_4.1.noarch 2/4 Verifying : 1:perl-Error-0.17015-4.el6.noarch 3/4 Verifying : rsync-3.0.6-12.el6.x86_64 4/4 インストール: git.x86_64 0:1.7.1-3.el6_4.1 依存性関連をインストールしました: perl-Error.noarch 1:0.17015-4.el6 perl-Git.noarch 0:1.7.1-3.el6_4.1 rsync.x86_64 0:3.0.6-12.el6 完了しました!
python2.7
Let's Encrypt がサポートするpythonのバージョンは2.7なのですが、CentOS6.x系の標準パッケージではpython2.6がデフォルトとなっています。
というわけで、python2.7はSoftwareCollections(SCL)から入手する必要があります。
SCLリポジトリの追加
# $ yum install centos-release-SCL 読み込んだプラグイン:fastestmirror インストール処理の設定をしています Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * epel: ftp.iij.ad.jp * extras: ftp.iij.ad.jp * rpmforge: ftp.kddilabs.jp * updates: ftp.iij.ad.jp 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> Package centos-release-SCL.x86_64 10:6-5.el6.centos will be インストール --> 依存性解決を終了しました。 依存性を解決しました ============================================================================================================================================================================================== パッケージ アーキテクチャ バージョン リポジトリー 容量 ============================================================================================================================================================================================== インストールしています: centos-release-SCL x86_64 10:6-5.el6.centos extras 3.9 k トランザクションの要約 ============================================================================================================================================================================================== インストール 1 パッケージ 総ダウンロード容量: 3.9 k インストール済み容量: 453 これでいいですか? [y/N]y パッケージをダウンロードしています: centos-release-SCL-6-5.el6.centos.x86_64.rpm | 3.9 kB 00:00 rpm_check_debug を実行しています トランザクションのテストを実行しています トランザクションのテストを成功しました トランザクションを実行しています インストールしています : 10:centos-release-SCL-6-5.el6.centos.x86_64 1/1 Verifying : 10:centos-release-SCL-6-5.el6.centos.x86_64 1/1 インストール: centos-release-SCL.x86_64 10:6-5.el6.centos 完了しました!
python2.7のインストール
$ yum install -y python27 python27-python-devel python27-python-setuptools python27-python-tools python27-python-virtualenv 読み込んだプラグイン:fastestmirror インストール処理の設定をしています Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * epel: ftp.iij.ad.jp * extras: ftp.iij.ad.jp * rpmforge: ftp.kddilabs.jp * updates: ftp.iij.ad.jp 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> Package python27.x86_64 0:1.1-16.el6.centos.alt will be インストール --> 依存性の処理をしています: python27-python-werkzeug のパッケージ: python27-1.1-16.el6.centos.alt.x86_64 --> 依存性の処理をしています: python27-python-sqlalchemy のパッケージ: python27-1.1-16.el6.centos.alt.x86_64 --> 依存性の処理をしています: python27-python-sphinx のパッケージ: python27-1.1-16.el6.centos.alt.x86_64 --> 依存性の処理をしています: python27-python-simplejson のパッケージ: python27-1.1-16.el6.centos.alt.x86_64 --> 依存性の処理をしています: python27-python-nose のパッケージ: python27-1.1-16.el6.centos.alt.x86_64 --> 依存性の処理をしています: python27-python-jinja2 のパッケージ: python27-1.1-16.el6.centos.alt.x86_64 --> 依存性の処理をしています: python27-python のパッケージ: python27-1.1-16.el6.centos.alt.x86_64 ---> Package python27-python-devel.x86_64 0:2.7.5-10.el6.centos.alt will be インストール --> 依存性の処理をしています: libpython2.7.so.1.0()(64bit) のパッケージ: python27-python-devel-2.7.5-10.el6.centos.alt.x86_64 ---> Package python27-python-setuptools.noarch 0:0.9.8-2.el6.centos.alt will be インストール ---> Package python27-python-tools.x86_64 0:2.7.5-10.el6.centos.alt will be インストール --> 依存性の処理をしています: python27-tkinter = 2.7.5-10.el6.centos.alt のパッケージ: python27-python-tools-2.7.5-10.el6.centos.alt.x86_64 ---> Package python27-python-virtualenv.noarch 0:1.10.1-2.el6.centos.alt will be インストール --> トランザクションの確認を実行しています。 ---> Package python27-python.x86_64 0:2.7.5-10.el6.centos.alt will be インストール --> 依存性の処理をしています: python27-runtime のパッケージ: python27-python-2.7.5-10.el6.centos.alt.x86_64 ---> Package python27-python-jinja2.noarch 0:2.6-10.el6.centos.alt will be インストール --> 依存性の処理をしています: python27-python-babel >= 0.8 のパッケージ: python27-python-jinja2-2.6-10.el6.centos.alt.noarch --> 依存性の処理をしています: python27-python-markupsafe のパッケージ: python27-python-jinja2-2.6-10.el6.centos.alt.noarch ---> Package python27-python-libs.x86_64 0:2.7.5-10.el6.centos.alt will be インストール ---> Package python27-python-nose.noarch 0:1.3.0-1.el6.centos.alt will be インストール ---> Package python27-python-simplejson.x86_64 0:3.2.0-1.el6.centos.alt will be インストール ---> Package python27-python-sphinx.noarch 0:1.1.3-7.el6.centos.alt will be インストール --> 依存性の処理をしています: python27-python-pygments のパッケージ: python27-python-sphinx-1.1.3-7.el6.centos.alt.noarch --> 依存性の処理をしています: python27-python-docutils のパッケージ: python27-python-sphinx-1.1.3-7.el6.centos.alt.noarch ---> Package python27-python-sqlalchemy.x86_64 0:0.7.9-3.el6.centos.alt will be インストール ---> Package python27-python-werkzeug.noarch 0:0.8.3-5.el6.centos.alt will be インストール ---> Package python27-tkinter.x86_64 0:2.7.5-10.el6.centos.alt will be インストール --> トランザクションの確認を実行しています。 ---> Package python27-python-babel.noarch 0:0.9.6-7.el6.centos.alt will be インストール ---> Package python27-python-docutils.noarch 0:0.11-1.el6.centos.alt will be インストール ---> Package python27-python-markupsafe.x86_64 0:0.11-11.el6.centos.alt will be インストール ---> Package python27-python-pygments.noarch 0:1.5-2.el6.centos.alt will be インストール ---> Package python27-runtime.x86_64 0:1.1-16.el6.centos.alt will be インストール --> 依存性の処理をしています: scl-utils のパッケージ: python27-runtime-1.1-16.el6.centos.alt.x86_64 --> トランザクションの確認を実行しています。 ---> Package scl-utils.x86_64 0:20120927-27.el6_6 will be インストール --> 依存性解決を終了しました。 依存性を解決しました ============================================================================================================================== パッケージ アーキテクチャ バージョン リポジトリー 容量 ============================================================================================================================== インストールしています: python27 x86_64 1.1-16.el6.centos.alt scl 4.7 k python27-python-devel x86_64 2.7.5-10.el6.centos.alt scl 386 k python27-python-setuptools noarch 0.9.8-2.el6.centos.alt scl 423 k python27-python-tools x86_64 2.7.5-10.el6.centos.alt scl 877 k python27-python-virtualenv noarch 1.10.1-2.el6.centos.alt scl 1.4 M 依存性関連でのインストールをします。: python27-python x86_64 2.7.5-10.el6.centos.alt scl 80 k python27-python-babel noarch 0.9.6-7.el6.centos.alt scl 1.4 M python27-python-docutils noarch 0.11-1.el6.centos.alt scl 1.6 M python27-python-jinja2 noarch 2.6-10.el6.centos.alt scl 550 k python27-python-libs x86_64 2.7.5-10.el6.centos.alt scl 5.5 M python27-python-markupsafe x86_64 0.11-11.el6.centos.alt scl 25 k python27-python-nose noarch 1.3.0-1.el6.centos.alt scl 290 k python27-python-pygments noarch 1.5-2.el6.centos.alt scl 802 k python27-python-simplejson x86_64 3.2.0-1.el6.centos.alt scl 174 k python27-python-sphinx noarch 1.1.3-7.el6.centos.alt scl 1.1 M python27-python-sqlalchemy x86_64 0.7.9-3.el6.centos.alt scl 2.1 M python27-python-werkzeug noarch 0.8.3-5.el6.centos.alt scl 556 k python27-runtime x86_64 1.1-16.el6.centos.alt scl 1.0 M python27-tkinter x86_64 2.7.5-10.el6.centos.alt scl 333 k scl-utils x86_64 20120927-27.el6_6 base 22 k トランザクションの要約 ============================================================================================================================== インストール 20 パッケージ 総ダウンロード容量: 19 M インストール済み容量: 71 M パッケージをダウンロードしています: (1/20): python27-1.1-16.el6.centos.alt.x86_64.rpm | 4.7 kB 00:00 (2/20): python27-python-2.7.5-10.el6.centos.alt.x86_64.rpm | 80 kB 00:01 (3/20): python27-python-babel-0.9.6-7.el6.centos.alt.noarch.rpm | 1.4 MB 00:05 (4/20): python27-python-devel-2.7.5-10.el6.centos.alt.x86_64.rpm | 386 kB 00:00 (5/20): python27-python-docutils-0.11-1.el6.centos.alt.noarch.rpm | 1.6 MB 00:01 (6/20): python27-python-jinja2-2.6-10.el6.centos.alt.noarch.rpm | 550 kB 00:00 (7/20): python27-python-libs-2.7.5-10.el6.centos.alt.x86_64.rpm | 5.5 MB 00:05 (8/20): python27-python-markupsafe-0.11-11.el6.centos.alt.x86_64.rpm | 25 kB 00:00 (9/20): python27-python-nose-1.3.0-1.el6.centos.alt.noarch.rpm | 290 kB 00:00 (10/20): python27-python-pygments-1.5-2.el6.centos.alt.noarch.rpm | 802 kB 00:00 (11/20): python27-python-setuptools-0.9.8-2.el6.centos.alt.noarch.rpm | 423 kB 00:00 (12/20): python27-python-simplejson-3.2.0-1.el6.centos.alt.x86_64.rpm | 174 kB 00:00 (13/20): python27-python-sphinx-1.1.3-7.el6.centos.alt.noarch.rpm | 1.1 MB 00:00 (14/20): python27-python-sqlalchemy-0.7.9-3.el6.centos.alt.x86_64.rpm | 2.1 MB 00:01 (15/20): python27-python-tools-2.7.5-10.el6.centos.alt.x86_64.rpm | 877 kB 00:00 (16/20): python27-python-virtualenv-1.10.1-2.el6.centos.alt.noarch.rpm | 1.4 MB 00:00 (17/20): python27-python-werkzeug-0.8.3-5.el6.centos.alt.noarch.rpm | 556 kB 00:00 (18/20): python27-runtime-1.1-16.el6.centos.alt.x86_64.rpm | 1.0 MB 00:00 (19/20): python27-tkinter-2.7.5-10.el6.centos.alt.x86_64.rpm | 333 kB 00:00 (20/20): scl-utils-20120927-27.el6_6.x86_64.rpm | 22 kB 00:00 ------------------------------------------------------------------------------------------------------------------------------ 合計 653 kB/s | 19 MB 00:29 rpm_check_debug を実行しています トランザクションのテストを実行しています トランザクションのテストを成功しました トランザクションを実行しています インストールしています : scl-utils-20120927-27.el6_6.x86_64 1/20 インストールしています : python27-runtime-1.1-16.el6.centos.alt.x86_64 2/20 インストールしています : python27-python-libs-2.7.5-10.el6.centos.alt.x86_64 3/20 インストールしています : python27-python-2.7.5-10.el6.centos.alt.x86_64 4/20 インストールしています : python27-python-setuptools-0.9.8-2.el6.centos.alt.noarch 5/20 インストールしています : python27-python-pygments-1.5-2.el6.centos.alt.noarch 6/20 インストールしています : python27-python-nose-1.3.0-1.el6.centos.alt.noarch 7/20 インストールしています : python27-python-werkzeug-0.8.3-5.el6.centos.alt.noarch 8/20 インストールしています : python27-python-docutils-0.11-1.el6.centos.alt.noarch 9/20 インストールしています : python27-python-sqlalchemy-0.7.9-3.el6.centos.alt.x86_64 10/20 インストールしています : python27-python-simplejson-3.2.0-1.el6.centos.alt.x86_64 11/20 インストールしています : python27-tkinter-2.7.5-10.el6.centos.alt.x86_64 12/20 インストールしています : python27-python-markupsafe-0.11-11.el6.centos.alt.x86_64 13/20 インストールしています : python27-python-devel-2.7.5-10.el6.centos.alt.x86_64 14/20 インストールしています : python27-python-virtualenv-1.10.1-2.el6.centos.alt.noarch 15/20 インストールしています : python27-python-babel-0.9.6-7.el6.centos.alt.noarch 16/20 インストールしています : python27-python-jinja2-2.6-10.el6.centos.alt.noarch 17/20 インストールしています : python27-python-sphinx-1.1.3-7.el6.centos.alt.noarch 18/20 インストールしています : python27-1.1-16.el6.centos.alt.x86_64 19/20 インストールしています : python27-python-tools-2.7.5-10.el6.centos.alt.x86_64 20/20 Verifying : python27-python-sphinx-1.1.3-7.el6.centos.alt.noarch 1/20 Verifying : python27-python-werkzeug-0.8.3-5.el6.centos.alt.noarch 2/20 Verifying : python27-python-pygments-1.5-2.el6.centos.alt.noarch 3/20 Verifying : python27-python-nose-1.3.0-1.el6.centos.alt.noarch 4/20 Verifying : python27-python-virtualenv-1.10.1-2.el6.centos.alt.noarch 5/20 Verifying : python27-python-docutils-0.11-1.el6.centos.alt.noarch 6/20 Verifying : python27-python-sqlalchemy-0.7.9-3.el6.centos.alt.x86_64 7/20 Verifying : python27-python-setuptools-0.9.8-2.el6.centos.alt.noarch 8/20 Verifying : python27-python-tools-2.7.5-10.el6.centos.alt.x86_64 9/20 Verifying : python27-runtime-1.1-16.el6.centos.alt.x86_64 10/20 Verifying : python27-python-simplejson-3.2.0-1.el6.centos.alt.x86_64 11/20 Verifying : python27-tkinter-2.7.5-10.el6.centos.alt.x86_64 12/20 Verifying : python27-python-markupsafe-0.11-11.el6.centos.alt.x86_64 13/20 Verifying : scl-utils-20120927-27.el6_6.x86_64 14/20 Verifying : python27-python-libs-2.7.5-10.el6.centos.alt.x86_64 15/20 Verifying : python27-python-devel-2.7.5-10.el6.centos.alt.x86_64 16/20 Verifying : python27-python-2.7.5-10.el6.centos.alt.x86_64 17/20 Verifying : python27-1.1-16.el6.centos.alt.x86_64 18/20 Verifying : python27-python-babel-0.9.6-7.el6.centos.alt.noarch 19/20 Verifying : python27-python-jinja2-2.6-10.el6.centos.alt.noarch 20/20 インストール: python27.x86_64 0:1.1-16.el6.centos.alt python27-python-devel.x86_64 0:2.7.5-10.el6.centos.alt python27-python-setuptools.noarch 0:0.9.8-2.el6.centos.alt python27-python-tools.x86_64 0:2.7.5-10.el6.centos.alt python27-python-virtualenv.noarch 0:1.10.1-2.el6.centos.alt 依存性関連をインストールしました: python27-python.x86_64 0:2.7.5-10.el6.centos.alt python27-python-babel.noarch 0:0.9.6-7.el6.centos.alt python27-python-docutils.noarch 0:0.11-1.el6.centos.alt python27-python-jinja2.noarch 0:2.6-10.el6.centos.alt python27-python-libs.x86_64 0:2.7.5-10.el6.centos.alt python27-python-markupsafe.x86_64 0:0.11-11.el6.centos.alt python27-python-nose.noarch 0:1.3.0-1.el6.centos.alt python27-python-pygments.noarch 0:1.5-2.el6.centos.alt python27-python-simplejson.x86_64 0:3.2.0-1.el6.centos.alt python27-python-sphinx.noarch 0:1.1.3-7.el6.centos.alt python27-python-sqlalchemy.x86_64 0:0.7.9-3.el6.centos.alt python27-python-werkzeug.noarch 0:0.8.3-5.el6.centos.alt python27-runtime.x86_64 0:1.1-16.el6.centos.alt python27-tkinter.x86_64 0:2.7.5-10.el6.centos.alt scl-utils.x86_64 0:20120927-27.el6_6 完了しました!
ファイアウォール
httpsは443ポートを利用するため、開けておきます。
$ iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
iptables再起動
$ service iptables restart iptables: チェインをポリシー ACCEPT へ設定中filter [ OK ] iptables: ファイアウォールルールを消去中: [ OK ] iptables: モジュールを取り外し中: [ OK ] iptables: ファイアウォールルールを適用中: [ OK ]
確認
$ iptables -L -n | grep 443 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:443
Let's Encrypt
インストール
GitHubから入手します。
# インストールするディレクトリは任意だが適当と思われる/usr/local/に入れる $ cd /usr/local/ $ git clone https://github.com/letsencrypt/letsencrypt Initialized empty Git repository in /usr/local/letsencrypt/.git/ remote: Counting objects: 32215, done. remote: Compressing objects: 100% (138/138), done. remote: Total 32215 (delta 79), reused 0 (delta 0), pack-reused 32077 Receiving objects: 100% (32215/32215), 8.38 MiB | 1.45 MiB/s, done. Resolving deltas: 100% (22799/22799), done. $ cd letsencrypt
依存パッケージのインストール
「letsencrypt-auto」というスクリプトがあり、実行するとsslやpythonといった依存パッケージをインストールしてくれる。
./letsencrypt-auto --help Bootstrapping dependencies for RedHat-based OSes... yum is /usr/bin/yum 読み込んだプラグイン:fastestmirror インストール処理の設定をしています Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * epel: ftp.iij.ad.jp * extras: ftp.iij.ad.jp * rpmforge: ftp.kddilabs.jp * updates: ftp.iij.ad.jp パッケージ python-2.6.6-64.el6.x86_64 はインストール済みか最新バージョンです 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> Package python-devel.x86_64 0:2.6.6-64.el6 will be インストール ---> Package python-pip.noarch 0:7.1.0-1.el6 will be インストール --> 依存性の処理をしています: python-setuptools のパッケージ: python-pip-7.1.0-1.el6.noarch ---> Package python-tools.x86_64 0:2.6.6-64.el6 will be インストール --> 依存性の処理をしています: tkinter = 2.6.6-64.el6 のパッケージ: python-tools-2.6.6-64.el6.x86_64 ---> Package python-virtualenv.noarch 0:1.10.1-1.el6 will be インストール --> トランザクションの確認を実行しています。 ---> Package python-setuptools.noarch 0:0.6.10-3.el6 will be インストール ---> Package tkinter.x86_64 0:2.6.6-64.el6 will be インストール --> 依存性の処理をしています: libtk8.5.so()(64bit) のパッケージ: tkinter-2.6.6-64.el6.x86_64 --> 依存性の処理をしています: libtcl8.5.so()(64bit) のパッケージ: tkinter-2.6.6-64.el6.x86_64 --> 依存性の処理をしています: libTix.so()(64bit) のパッケージ: tkinter-2.6.6-64.el6.x86_64 --> トランザクションの確認を実行しています。 ---> Package tcl.x86_64 1:8.5.7-6.el6 will be インストール ---> Package tix.x86_64 1:8.4.3-5.el6 will be インストール ---> Package tk.x86_64 1:8.5.7-5.el6 will be インストール --> 依存性解決を終了しました。 依存性を解決しました ============================================================================================================================== パッケージ アーキテクチャ バージョン リポジトリー 容量 ============================================================================================================================== インストールしています: python-devel x86_64 2.6.6-64.el6 base 172 k python-pip noarch 7.1.0-1.el6 epel 1.5 M python-tools x86_64 2.6.6-64.el6 base 870 k python-virtualenv noarch 1.10.1-1.el6 epel 1.3 M 依存性関連でのインストールをします。: python-setuptools noarch 0.6.10-3.el6 base 336 k tcl x86_64 1:8.5.7-6.el6 base 1.9 M tix x86_64 1:8.4.3-5.el6 base 252 k tk x86_64 1:8.5.7-5.el6 base 1.4 M tkinter x86_64 2.6.6-64.el6 base 257 k トランザクションの要約 ============================================================================================================================== インストール 9 パッケージ 総ダウンロード容量: 8.0 M インストール済み容量: 22 M パッケージをダウンロードしています: (1/9): python-devel-2.6.6-64.el6.x86_64.rpm | 172 kB 00:00 (2/9): python-pip-7.1.0-1.el6.noarch.rpm | 1.5 MB 00:01 (3/9): python-setuptools-0.6.10-3.el6.noarch.rpm | 336 kB 00:00 (4/9): python-tools-2.6.6-64.el6.x86_64.rpm | 870 kB 00:01 (5/9): python-virtualenv-1.10.1-1.el6.noarch.rpm | 1.3 MB 00:01 (6/9): tcl-8.5.7-6.el6.x86_64.rpm | 1.9 MB 00:01 (7/9): tix-8.4.3-5.el6.x86_64.rpm | 252 kB 00:00 (8/9): tk-8.5.7-5.el6.x86_64.rpm | 1.4 MB 00:01 (9/9): tkinter-2.6.6-64.el6.x86_64.rpm | 257 kB 00:00 ------------------------------------------------------------------------------------------------------------------------------ 合計 770 kB/s | 8.0 MB 00:10 rpm_check_debug を実行しています トランザクションのテストを実行しています トランザクションのテストを成功しました トランザクションを実行しています インストールしています : 1:tcl-8.5.7-6.el6.x86_64 1/9 インストールしています : 1:tk-8.5.7-5.el6.x86_64 2/9 インストールしています : python-setuptools-0.6.10-3.el6.noarch 3/9 インストールしています : 1:tix-8.4.3-5.el6.x86_64 4/9 インストールしています : tkinter-2.6.6-64.el6.x86_64 5/9 インストールしています : python-devel-2.6.6-64.el6.x86_64 6/9 インストールしています : python-virtualenv-1.10.1-1.el6.noarch 7/9 インストールしています : python-tools-2.6.6-64.el6.x86_64 8/9 インストールしています : python-pip-7.1.0-1.el6.noarch 9/9 Verifying : python-devel-2.6.6-64.el6.x86_64 1/9 Verifying : python-pip-7.1.0-1.el6.noarch 2/9 Verifying : 1:tix-8.4.3-5.el6.x86_64 3/9 Verifying : python-tools-2.6.6-64.el6.x86_64 4/9 Verifying : python-virtualenv-1.10.1-1.el6.noarch 5/9 Verifying : 1:tcl-8.5.7-6.el6.x86_64 6/9 Verifying : 1:tk-8.5.7-5.el6.x86_64 7/9 Verifying : python-setuptools-0.6.10-3.el6.noarch 8/9 Verifying : tkinter-2.6.6-64.el6.x86_64 9/9 インストール: python-devel.x86_64 0:2.6.6-64.el6 python-pip.noarch 0:7.1.0-1.el6 python-tools.x86_64 0:2.6.6-64.el6 python-virtualenv.noarch 0:1.10.1-1.el6 依存性関連をインストールしました: python-setuptools.noarch 0:0.6.10-3.el6 tcl.x86_64 1:8.5.7-6.el6 tix.x86_64 1:8.4.3-5.el6 tk.x86_64 1:8.5.7-5.el6 tkinter.x86_64 0:2.6.6-64.el6 完了しました! 読み込んだプラグイン:fastestmirror インストール処理の設定をしています Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * epel: ftp.iij.ad.jp * extras: ftp.iij.ad.jp * rpmforge: ftp.kddilabs.jp * updates: ftp.iij.ad.jp パッケージ openssl-1.0.1e-42.el6_7.2.x86_64 はインストール済みか最新バージョンです パッケージ ca-certificates-2015.2.4-65.0.1.el6_6.noarch はインストール済みか最新バージョンです 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> Package augeas-libs.x86_64 0:1.0.0-10.el6 will be インストール ---> Package dialog.x86_64 0:1.1-9.20080819.1.el6 will be インストール ---> Package gcc.x86_64 0:4.4.7-16.el6 will be インストール --> 依存性の処理をしています: libgomp = 4.4.7-16.el6 のパッケージ: gcc-4.4.7-16.el6.x86_64 --> 依存性の処理をしています: cpp = 4.4.7-16.el6 のパッケージ: gcc-4.4.7-16.el6.x86_64 --> 依存性の処理をしています: glibc-devel >= 2.2.90-12 のパッケージ: gcc-4.4.7-16.el6.x86_64 --> 依存性の処理をしています: cloog-ppl >= 0.15 のパッケージ: gcc-4.4.7-16.el6.x86_64 --> 依存性の処理をしています: libgomp.so.1()(64bit) のパッケージ: gcc-4.4.7-16.el6.x86_64 ---> Package libffi-devel.x86_64 0:3.0.5-3.2.el6 will be インストール ---> Package openssl-devel.x86_64 0:1.0.1e-42.el6_7.2 will be インストール --> 依存性の処理をしています: zlib-devel のパッケージ: openssl-devel-1.0.1e-42.el6_7.2.x86_64 --> 依存性の処理をしています: krb5-devel のパッケージ: openssl-devel-1.0.1e-42.el6_7.2.x86_64 ---> Package redhat-rpm-config.noarch 0:9.0.3-44.el6.centos will be インストール --> トランザクションの確認を実行しています。 ---> Package cloog-ppl.x86_64 0:0.15.7-1.2.el6 will be インストール --> 依存性の処理をしています: libppl_c.so.2()(64bit) のパッケージ: cloog-ppl-0.15.7-1.2.el6.x86_64 --> 依存性の処理をしています: libppl.so.7()(64bit) のパッケージ: cloog-ppl-0.15.7-1.2.el6.x86_64 ---> Package cpp.x86_64 0:4.4.7-16.el6 will be インストール --> 依存性の処理をしています: libmpfr.so.1()(64bit) のパッケージ: cpp-4.4.7-16.el6.x86_64 ---> Package glibc-devel.x86_64 0:2.12-1.166.el6_7.7 will be インストール --> 依存性の処理をしています: glibc-headers = 2.12-1.166.el6_7.7 のパッケージ: glibc-devel-2.12-1.166.el6_7.7.x86_64 --> 依存性の処理をしています: glibc-headers のパッケージ: glibc-devel-2.12-1.166.el6_7.7.x86_64 ---> Package krb5-devel.x86_64 0:1.10.3-42.el6 will be インストール --> 依存性の処理をしています: libselinux-devel のパッケージ: krb5-devel-1.10.3-42.el6.x86_64 --> 依存性の処理をしています: libcom_err-devel のパッケージ: krb5-devel-1.10.3-42.el6.x86_64 --> 依存性の処理をしています: keyutils-libs-devel のパッケージ: krb5-devel-1.10.3-42.el6.x86_64 ---> Package libgomp.x86_64 0:4.4.7-16.el6 will be インストール ---> Package zlib-devel.x86_64 0:1.2.3-29.el6 will be インストール --> トランザクションの確認を実行しています。 ---> Package glibc-headers.x86_64 0:2.12-1.166.el6_7.7 will be インストール --> 依存性の処理をしています: kernel-headers >= 2.2.1 のパッケージ: glibc-headers-2.12-1.166.el6_7.7.x86_64 --> 依存性の処理をしています: kernel-headers のパッケージ: glibc-headers-2.12-1.166.el6_7.7.x86_64 ---> Package keyutils-libs-devel.x86_64 0:1.4-5.el6 will be インストール ---> Package libcom_err-devel.x86_64 0:1.41.12-22.el6 will be インストール ---> Package libselinux-devel.x86_64 0:2.0.94-5.8.el6 will be インストール --> 依存性の処理をしています: libsepol-devel >= 2.0.32-1 のパッケージ: libselinux-devel-2.0.94-5.8.el6.x86_64 --> 依存性の処理をしています: pkgconfig(libsepol) のパッケージ: libselinux-devel-2.0.94-5.8.el6.x86_64 ---> Package mpfr.x86_64 0:2.4.1-6.el6 will be インストール ---> Package ppl.x86_64 0:0.10.2-11.el6 will be インストール --> トランザクションの確認を実行しています。 ---> Package kernel-headers.x86_64 0:2.6.32-573.18.1.el6 will be インストール ---> Package libsepol-devel.x86_64 0:2.0.41-4.el6 will be インストール --> 依存性解決を終了しました。 依存性を解決しました ============================================================================================================================== パッケージ アーキテクチャ バージョン リポジトリー 容量 ============================================================================================================================== インストールしています: augeas-libs x86_64 1.0.0-10.el6 base 314 k dialog x86_64 1.1-9.20080819.1.el6 base 197 k gcc x86_64 4.4.7-16.el6 base 10 M libffi-devel x86_64 3.0.5-3.2.el6 base 18 k openssl-devel x86_64 1.0.1e-42.el6_7.2 updates 1.2 M redhat-rpm-config noarch 9.0.3-44.el6.centos base 59 k 依存性関連でのインストールをします。: cloog-ppl x86_64 0.15.7-1.2.el6 base 93 k cpp x86_64 4.4.7-16.el6 base 3.7 M glibc-devel x86_64 2.12-1.166.el6_7.7 updates 986 k glibc-headers x86_64 2.12-1.166.el6_7.7 updates 615 k kernel-headers x86_64 2.6.32-573.18.1.el6 updates 3.9 M keyutils-libs-devel x86_64 1.4-5.el6 base 29 k krb5-devel x86_64 1.10.3-42.el6 base 502 k libcom_err-devel x86_64 1.41.12-22.el6 base 33 k libgomp x86_64 4.4.7-16.el6 base 134 k libselinux-devel x86_64 2.0.94-5.8.el6 base 137 k libsepol-devel x86_64 2.0.41-4.el6 base 64 k mpfr x86_64 2.4.1-6.el6 base 157 k ppl x86_64 0.10.2-11.el6 base 1.3 M zlib-devel x86_64 1.2.3-29.el6 base 44 k トランザクションの要約 ============================================================================================================================== インストール 20 パッケージ 総ダウンロード容量: 23 M インストール済み容量: 45 M パッケージをダウンロードしています: (1/20): augeas-libs-1.0.0-10.el6.x86_64.rpm | 314 kB 00:00 (2/20): cloog-ppl-0.15.7-1.2.el6.x86_64.rpm | 93 kB 00:00 (3/20): cpp-4.4.7-16.el6.x86_64.rpm | 3.7 MB 00:01 (4/20): dialog-1.1-9.20080819.1.el6.x86_64.rpm | 197 kB 00:00 (5/20): gcc-4.4.7-16.el6.x86_64.rpm | 10 MB 00:03 (6/20): glibc-devel-2.12-1.166.el6_7.7.x86_64.rpm | 986 kB 00:01 (7/20): glibc-headers-2.12-1.166.el6_7.7.x86_64.rpm | 615 kB 00:00 (8/20): kernel-headers-2.6.32-573.18.1.el6.x86_64.rpm | 3.9 MB 00:01 (9/20): keyutils-libs-devel-1.4-5.el6.x86_64.rpm | 29 kB 00:00 (10/20): krb5-devel-1.10.3-42.el6.x86_64.rpm | 502 kB 00:00 (11/20): libcom_err-devel-1.41.12-22.el6.x86_64.rpm | 33 kB 00:00 (12/20): libffi-devel-3.0.5-3.2.el6.x86_64.rpm | 18 kB 00:00 (13/20): libgomp-4.4.7-16.el6.x86_64.rpm | 134 kB 00:00 (14/20): libselinux-devel-2.0.94-5.8.el6.x86_64.rpm | 137 kB 00:00 (15/20): libsepol-devel-2.0.41-4.el6.x86_64.rpm | 64 kB 00:00 (16/20): mpfr-2.4.1-6.el6.x86_64.rpm | 157 kB 00:00 (17/20): openssl-devel-1.0.1e-42.el6_7.2.x86_64.rpm | 1.2 MB 00:01 (18/20): ppl-0.10.2-11.el6.x86_64.rpm | 1.3 MB 00:01 (19/20): redhat-rpm-config-9.0.3-44.el6.centos.noarch.rpm | 59 kB 00:00 (20/20): zlib-devel-1.2.3-29.el6.x86_64.rpm | 44 kB 00:00 ------------------------------------------------------------------------------------------------------------------------------ 合計 1.3 MB/s | 23 MB 00:18 rpm_check_debug を実行しています トランザクションのテストを実行しています トランザクションのテストを成功しました トランザクションを実行しています インストールしています : zlib-devel-1.2.3-29.el6.x86_64 1/20 インストールしています : libcom_err-devel-1.41.12-22.el6.x86_64 2/20 インストールしています : kernel-headers-2.6.32-573.18.1.el6.x86_64 3/20 インストールしています : glibc-headers-2.12-1.166.el6_7.7.x86_64 4/20 インストールしています : glibc-devel-2.12-1.166.el6_7.7.x86_64 5/20 インストールしています : mpfr-2.4.1-6.el6.x86_64 6/20 インストールしています : cpp-4.4.7-16.el6.x86_64 7/20 インストールしています : ppl-0.10.2-11.el6.x86_64 8/20 インストールしています : cloog-ppl-0.15.7-1.2.el6.x86_64 9/20 インストールしています : libsepol-devel-2.0.41-4.el6.x86_64 10/20 インストールしています : libselinux-devel-2.0.94-5.8.el6.x86_64 11/20 インストールしています : keyutils-libs-devel-1.4-5.el6.x86_64 12/20 インストールしています : krb5-devel-1.10.3-42.el6.x86_64 13/20 インストールしています : libgomp-4.4.7-16.el6.x86_64 14/20 インストールしています : gcc-4.4.7-16.el6.x86_64 15/20 インストールしています : openssl-devel-1.0.1e-42.el6_7.2.x86_64 16/20 インストールしています : augeas-libs-1.0.0-10.el6.x86_64 17/20 インストールしています : redhat-rpm-config-9.0.3-44.el6.centos.noarch 18/20 インストールしています : dialog-1.1-9.20080819.1.el6.x86_64 19/20 インストールしています : libffi-devel-3.0.5-3.2.el6.x86_64 20/20 Verifying : libgomp-4.4.7-16.el6.x86_64 1/20 Verifying : keyutils-libs-devel-1.4-5.el6.x86_64 2/20 Verifying : libsepol-devel-2.0.41-4.el6.x86_64 3/20 Verifying : openssl-devel-1.0.1e-42.el6_7.2.x86_64 4/20 Verifying : ppl-0.10.2-11.el6.x86_64 5/20 Verifying : krb5-devel-1.10.3-42.el6.x86_64 6/20 Verifying : gcc-4.4.7-16.el6.x86_64 7/20 Verifying : mpfr-2.4.1-6.el6.x86_64 8/20 Verifying : libffi-devel-3.0.5-3.2.el6.x86_64 9/20 Verifying : kernel-headers-2.6.32-573.18.1.el6.x86_64 10/20 Verifying : libselinux-devel-2.0.94-5.8.el6.x86_64 11/20 Verifying : dialog-1.1-9.20080819.1.el6.x86_64 12/20 Verifying : libcom_err-devel-1.41.12-22.el6.x86_64 13/20 Verifying : glibc-headers-2.12-1.166.el6_7.7.x86_64 14/20 Verifying : zlib-devel-1.2.3-29.el6.x86_64 15/20 Verifying : cpp-4.4.7-16.el6.x86_64 16/20 Verifying : glibc-devel-2.12-1.166.el6_7.7.x86_64 17/20 Verifying : cloog-ppl-0.15.7-1.2.el6.x86_64 18/20 Verifying : redhat-rpm-config-9.0.3-44.el6.centos.noarch 19/20 Verifying : augeas-libs-1.0.0-10.el6.x86_64 20/20 インストール: augeas-libs.x86_64 0:1.0.0-10.el6 dialog.x86_64 0:1.1-9.20080819.1.el6 gcc.x86_64 0:4.4.7-16.el6 libffi-devel.x86_64 0:3.0.5-3.2.el6 openssl-devel.x86_64 0:1.0.1e-42.el6_7.2 redhat-rpm-config.noarch 0:9.0.3-44.el6.centos 依存性関連をインストールしました: cloog-ppl.x86_64 0:0.15.7-1.2.el6 cpp.x86_64 0:4.4.7-16.el6 glibc-devel.x86_64 0:2.12-1.166.el6_7.7 glibc-headers.x86_64 0:2.12-1.166.el6_7.7 kernel-headers.x86_64 0:2.6.32-573.18.1.el6 keyutils-libs-devel.x86_64 0:1.4-5.el6 krb5-devel.x86_64 0:1.10.3-42.el6 libcom_err-devel.x86_64 0:1.41.12-22.el6 libgomp.x86_64 0:4.4.7-16.el6 libselinux-devel.x86_64 0:2.0.94-5.8.el6 libsepol-devel.x86_64 0:2.0.41-4.el6 mpfr.x86_64 0:2.4.1-6.el6 ppl.x86_64 0:0.10.2-11.el6 zlib-devel.x86_64 0:1.2.3-29.el6 完了しました! 読み込んだプラグイン:fastestmirror インストール処理の設定をしています Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * epel: ftp.iij.ad.jp * extras: ftp.iij.ad.jp * rpmforge: ftp.kddilabs.jp * updates: ftp.iij.ad.jp 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> Package mod_ssl.x86_64 1:2.2.15-47.el6.centos.3 will be インストール --> 依存性解決を終了しました。 依存性を解決しました ============================================================================================================================== パッケージ アーキテクチャ バージョン リポジトリー 容量 ============================================================================================================================== インストールしています: mod_ssl x86_64 1:2.2.15-47.el6.centos.3 updates 95 k トランザクションの要約 ============================================================================================================================== インストール 1 パッケージ 総ダウンロード容量: 95 k インストール済み容量: 187 k パッケージをダウンロードしています: mod_ssl-2.2.15-47.el6.centos.3.x86_64.rpm | 95 kB 00:00 rpm_check_debug を実行しています トランザクションのテストを実行しています トランザクションのテストを成功しました トランザクションを実行しています インストールしています : 1:mod_ssl-2.2.15-47.el6.centos.3.x86_64 1/1 Verifying : 1:mod_ssl-2.2.15-47.el6.centos.3.x86_64 1/1 インストール: mod_ssl.x86_64 1:2.2.15-47.el6.centos.3 完了しました! Checking for new version... Creating virtual environment... Installing Python packages... Requesting root privileges to run letsencrypt... /root/.local/share/letsencrypt/bin/letsencrypt --no-self-upgrade --help /root/.local/share/letsencrypt/lib/python2.6/site-packages/cryptography/__init__.py:25: DeprecationWarning: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. DeprecationWarning letsencrypt-auto [SUBCOMMAND] [options] [-d domain] [-d domain] ... The Let's Encrypt agent can obtain and install HTTPS/TLS/SSL certificates. By default, it will attempt to use a webserver both for obtaining and installing the cert. Major SUBCOMMANDS are: (default) run Obtain & install a cert in your current webserver certonly Obtain cert, but do not install it (aka "auth") install Install a previously obtained cert in a server renew Renew previously obtained certs that are near expiry revoke Revoke a previously obtained certificate rollback Rollback server configuration changes made during install config_changes Show changes made to server config during installation plugins Display information about installed plugins Choice of server plugins for obtaining and installing cert: --apache Use the Apache plugin for authentication & installation --standalone Run a standalone webserver for authentication (nginx support is experimental, buggy, and not installed by default) --webroot Place files in a server's webroot folder for authentication OR use different plugins to obtain (authenticate) the cert and then install it: --authenticator standalone --installer apache More detailed help: -h, --help [topic] print this message, or detailed help on a topic; the available topics are: all, automation, paths, security, testing, or any of the subcommands or plugins (certonly, install, nginx, apache, standalone, webroot, etc)
証明書の発行
./letsencrypt-auto certonly --webroot --webroot-path /home/apache/vhost/example/html \ -d example.co.jp -d www.example.co.jp \ --agree-tos -m hoge@example.co.jp Checking for new version... Creating virtual environment... Installing Python packages... Requesting root privileges to run letsencrypt... /root/.local/share/letsencrypt/bin/letsencrypt --no-self-upgrade certonly --webroot --webroot-path /home/apache/vhost/example/html -d example.co.jp -d www.example.co.jp --agree-tos -m hoge@example.co.jp /root/.local/share/letsencrypt/lib/python2.6/site-packages/cryptography/__init__.py:25: DeprecationWarning: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. DeprecationWarning Version: 1.1-20080819 Version: 1.1-20080819 IMPORTANT NOTES: - If you lose your account credentials, you can recover through e-mails sent to example@co.jp. - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/example.co.jp/fullchain.pem. Your cert will expire on 2016-05-29. To obtain a new version of the certificate in the future, simply run Let's Encrypt again. - Your account credentials have been saved in your Let's Encrypt configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Let's Encrypt so making regular backups of this folder is ideal. - If you like Let's Encrypt, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
証明書の生成が正常に終了すると
/etc/letsencrypt/live/example.co.jp/ 配下に証明書(のリンク)が生成されている。
$ ls -la /etc/letsencrypt/live/example.co.jp/ 合計 8 drwxr-xr-x. 2 root root 4096 3月 1 07:37 2016 . drwx------. 3 root root 4096 3月 1 07:37 2016 .. lrwxrwxrwx. 1 root root 40 3月 1 07:37 2016 cert.pem -> ../../archive/example.co.jp/cert1.pem # 証明書 lrwxrwxrwx. 1 root root 41 3月 1 07:37 2016 chain.pem -> ../../archive/example.co.jp/chain1.pem # 証明書チェーン lrwxrwxrwx. 1 root root 45 3月 1 07:37 2016 fullchain.pem -> ../../archive/example.co.jp/fullchain1.pem # 証明書(cert.pemとchain.pemをまとめたもの) lrwxrwxrwx. 1 root root 43 3月 1 07:37 2016 privkey.pem -> ../../archive/example.co.jp/privkey1.pemsh # 秘密鍵
Apacheのhttps対応
ssl.confの設定
# # When we also provide SSL we have to listen to the # the HTTPS port in addition. # Listen 443 https ## ## SSL Global Context ## ## All SSL configuration in this context applies both to ## the main server and all SSL-enabled virtual hosts. ## # Pass Phrase Dialog: # Configure the pass phrase gathering process. # The filtering dialog program (`builtin' is a internal # terminal dialog) has to provide the pass phrase on stdout. SSLPassPhraseDialog builtin # Inter-Process Session Cache: # Configure the SSL Session Cache: First the mechanism # to use and second the expiring timeout (in seconds). SSLSessionCache shmcb:/run/httpd/sslcache(512000) SSLSessionCacheTimeout 300 # Pseudo Random Number Generator (PRNG): # Configure one or more sources to seed the PRNG of the # SSL library. The seed data should be of good random quality. # WARNING! On some platforms /dev/random blocks if not enough entropy # is available. This means you then cannot use the /dev/random device # because it would lead to very long connection times (as long as # it requires to make more entropy available). But usually those # platforms additionally provide a /dev/urandom device which doesn't # block. So, if available, use this one instead. Read the mod_ssl User # Manual for more details. SSLRandomSeed startup file:/dev/urandom 256 SSLRandomSeed connect builtin #SSLRandomSeed startup file:/dev/random 512 #SSLRandomSeed connect file:/dev/random 512 #SSLRandomSeed connect file:/dev/urandom 512 # # Use "SSLCryptoDevice" to enable any supported hardware # accelerators. Use "openssl engine -v" to list supported # engine names. NOTE: If you enable an accelerator and the # server does not start, consult the error logs and ensure # your accelerator is functioning properly. # SSLCryptoDevice builtin #SSLCryptoDevice ubsec
httpd.confの設定
sslモジュールをロードするように以下を追記します。
LoadModule ssl_module modules/mod_ssl.so
バーチャルホストの設定
当方の環境はバーチャルホストにしているので、バーチャルホストの設定ファイルに以下を追記
/etc/httpd/conf.d/vhosts/example.conf
<VirtualHost *:443> ServerAdmin root@example.co.jp DocumentRoot /home/hoge/example.co.jp/html/ ServerName example.co.jp ServerAlias www.example.co.jp ErrorLog /home/hoge/example.co.jp/logs/error_log CustomLog /home/hoge/example.co.jp/logs/access_log common SSLEngine on SSLProtocol all -SSLv2 -SSLv3 SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA SSLCertificateFile /etc/letsencrypt/live/example.co.jp/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.co.jp/privkey.pem SSLCACertificateFile /etc/letsencrypt/live/example.co.jp/fullchain.pem <Directory /> Options Indexes AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost>
ここまで来たらhttpdを再起動してhttpsで接続できるはずです。
httpsを強制させる方法
httpd.confに以下を追記し、mod_rewriteモジュールをロードする。
LoadModule rewrite_module modules/mod_rewrite.so
バーチャルホストなもんで、以下のようにmod_rewriteでhttpsで接続するようにしてやります。
/etc/httpd/conf.d/vhosts/example.conf
<VirtualHost *:80> <!-- 中略 --> <ifModule mod_rewrite.c> RewriteEngine On RewriteLog "/var/log/httpd/rewrite_log" RewriteLogLevel 0 RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L] </ifModule> </VirtualHost>
簡単に説明すると、RewriteCondはrewriteする条件で、例の場合は443ポート以外で接続してきた場合、つまりhttps以外の場合ってことですね。
RewriteRuleはrewrite先を記述する。ちなみに末尾の[R, L]はオプションです。
力尽きたので、詳細はここを参考にしてください。。。
参考
User Guide — Certbot 0.10.0.dev0 documentation
Let’s Encrypt サーバー証明書の取得と自動更新設定メモ | あぱーブログ
Let's Encrypt編 - Apache 2.4系でHTTP/2対応サーバを構築してみるテスト。
http://jetstreamair.blogspot.jp/2015/12/ssllets-encryptcentos6.html
Redhat / CentOS 6.x users need python 2.7 - Server - Let's Encrypt Community Support
Redhat6.x + SCL 使う時に気をつけたい3つのポイント - AWS / PHP / Python ちょいメモ
apacheでhttpへのアクセスをhttpsへ自動リダイレクトする - Qiita
HTTPでアクセスした時、自動的にHTTPSにrewriteする
Apache : mod_rewriteリファレンス - dawgsdk.org
RSA鍵、証明書のファイルフォーマットについて - Qiita
opensslコマンドで証明書情報を確認したい。 | SSL・電子証明書ならGMOグローバルサイン
遭遇したエラー
Invalid command 'SSLEngine' 〜
$ service httpd restart httpd を停止中: [ OK ] httpd を起動中: Syntax error on line 28 of /etc/httpd/conf.d/vhosts/example.conf: Invalid command 'SSLEngine', perhaps misspelled or defined by a module not included in the server configuration
原因
httpd.confにsslモジュールを読み込む設定をしていなかった。
対応
httpd.confに以下を追記
LoadModule ssl_module modules/mod_ssl.so
参考
mod_sslが有効にならない - myChuno::blog
SSLPassPhraseDialog: file '/usr/libexec/httpd-ssl-pass-dialog' does not exist
$ service httpd restart httpd を停止中: [ OK ] httpd を起動中: Syntax error on line 19 of /etc/httpd/conf.d/ssl.conf: SSLPassPhraseDialog: file '/usr/libexec/httpd-ssl-pass-dialog' does not exist [失敗]
原因
/usr/libexec/httpd-ssl-pass-dialogがない。
参考にしたssl.confは
SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog
になってたんですが、これは「SSLのパスフレーズの入力にhttpd-ssl-pass-dialogってスクリプトを使います」ってことだったらしい。
httpd-ssl-pass-dialogなんてスクリプトは作ってないし、そもそもLet's Encryptで生成したSSLのキーにパスワードは必要ないので、
SSLPassPhraseDialog builtin
で良い(ちなみに、SSLのキーにパスワードがかかっているときはダイアログが表示され、手入力が必要)。
対応
参考
Apacheの起動時にSSLのパスフレーズを省略する方法 - それマグで!
Apache2.4 + mod_ssl + SSL証明書 = ちょいつまづく? | 日記の間 | あかつきのお宿
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
$ service httpd restart httpd を停止中: [失敗] httpd を起動中: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
原因
httpd.confのServerNameディレクティブが未設定だったため
対応
httpd.confのServerName設定する。
# httpd.conf.defaultは変更前のhttpd.conf $ diff /etc/httpd/conf/httpd.conf.default /etc/httpd/conf/httpd.conf 276c278 < #ServerName www.example.com:80 --- > ServerName localhost:80
参考
Apache: 起動エラー – Could not reliably determine the server’s fully qualified domain name
【CentOS6】Apache2.2インストール&設定
環境
- サーバOS: CentOS 6.7
インストール
Apache本体の他に以下パッケージもインストールしておく
- httpd-devel: apxsなどの開発用ツールが含まれるパッケージ
- httpd-tools: httpd の監視、統計、ログ分析、DoS の検出、および防衛のためのツールが含まれるパッケージ
- httpd-manual: httpdのドキュメントページを含むパッケージ
$ yum -y install httpd httpd-devel httpd-tools httpd-manual 読み込んだプラグイン:fastestmirror インストール処理の設定をしています Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * epel: ftp.iij.ad.jp * extras: ftp.iij.ad.jp * rpmforge: ftp.kddilabs.jp * updates: ftp.iij.ad.jp 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> Package httpd.x86_64 0:2.2.15-47.el6.centos.3 will be インストール --> 依存性の処理をしています: apr-util-ldap のパッケージ: httpd-2.2.15-47.el6.centos.3.x86_64 --> 依存性の処理をしています: /etc/mime.types のパッケージ: httpd-2.2.15-47.el6.centos.3.x86_64 --> 依存性の処理をしています: libaprutil-1.so.0()(64bit) のパッケージ: httpd-2.2.15-47.el6.centos.3.x86_64 --> 依存性の処理をしています: libapr-1.so.0()(64bit) のパッケージ: httpd-2.2.15-47.el6.centos.3.x86_64 ---> Package httpd-devel.x86_64 0:2.2.15-47.el6.centos.3 will be インストール --> 依存性の処理をしています: apr-util-devel のパッケージ: httpd-devel-2.2.15-47.el6.centos.3.x86_64 --> 依存性の処理をしています: apr-devel のパッケージ: httpd-devel-2.2.15-47.el6.centos.3.x86_64 ---> Package httpd-manual.noarch 0:2.2.15-47.el6.centos.3 will be インストール ---> Package httpd-tools.x86_64 0:2.2.15-47.el6.centos.3 will be インストール --> トランザクションの確認を実行しています。 ---> Package apr.x86_64 0:1.3.9-5.el6_2 will be インストール ---> Package apr-devel.x86_64 0:1.3.9-5.el6_2 will be インストール ---> Package apr-util.x86_64 0:1.3.9-3.el6_0.1 will be インストール ---> Package apr-util-devel.x86_64 0:1.3.9-3.el6_0.1 will be インストール --> 依存性の処理をしています: openldap-devel のパッケージ: apr-util-devel-1.3.9-3.el6_0.1.x86_64 --> 依存性の処理をしています: expat-devel のパッケージ: apr-util-devel-1.3.9-3.el6_0.1.x86_64 --> 依存性の処理をしています: db4-devel のパッケージ: apr-util-devel-1.3.9-3.el6_0.1.x86_64 ---> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 will be インストール ---> Package mailcap.noarch 0:2.1.31-2.el6 will be インストール --> トランザクションの確認を実行しています。 ---> Package db4-devel.x86_64 0:4.7.25-20.el6_7 will be インストール --> 依存性の処理をしています: db4-cxx = 4.7.25-20.el6_7 のパッケージ: db4-devel-4.7.25-20.el6_7.x86_64 --> 依存性の処理をしています: libdb_cxx-4.7.so()(64bit) のパッケージ: db4-devel-4.7.25-20.el6_7.x86_64 ---> Package expat-devel.x86_64 0:2.0.1-11.el6_2 will be インストール ---> Package openldap-devel.x86_64 0:2.4.40-7.el6_7 will be インストール --> 依存性の処理をしています: cyrus-sasl-devel >= 2.1 のパッケージ: openldap-devel-2.4.40-7.el6_7.x86_64 --> トランザクションの確認を実行しています。 ---> Package cyrus-sasl-devel.x86_64 0:2.1.23-15.el6_6.2 will be インストール ---> Package db4-cxx.x86_64 0:4.7.25-20.el6_7 will be インストール --> 依存性解決を終了しました。 依存性を解決しました ============================================================================================================================================================================================== パッケージ アーキテクチャ バージョン リポジトリー 容量 ============================================================================================================================================================================================== インストールしています: httpd x86_64 2.2.15-47.el6.centos.3 updates 831 k httpd-devel x86_64 2.2.15-47.el6.centos.3 updates 155 k httpd-manual noarch 2.2.15-47.el6.centos.3 updates 788 k httpd-tools x86_64 2.2.15-47.el6.centos.3 updates 77 k 依存性関連でのインストールをします。: apr x86_64 1.3.9-5.el6_2 base 123 k apr-devel x86_64 1.3.9-5.el6_2 base 176 k apr-util x86_64 1.3.9-3.el6_0.1 base 87 k apr-util-devel x86_64 1.3.9-3.el6_0.1 base 69 k apr-util-ldap x86_64 1.3.9-3.el6_0.1 base 15 k cyrus-sasl-devel x86_64 2.1.23-15.el6_6.2 base 303 k db4-cxx x86_64 4.7.25-20.el6_7 updates 588 k db4-devel x86_64 4.7.25-20.el6_7 updates 6.6 M expat-devel x86_64 2.0.1-11.el6_2 base 120 k mailcap noarch 2.1.31-2.el6 base 27 k openldap-devel x86_64 2.4.40-7.el6_7 updates 1.1 M トランザクションの要約 ============================================================================================================================================================================================== インストール 15 パッケージ 総ダウンロード容量: 11 M インストール済み容量: 41 M パッケージをダウンロードしています: (1/15): apr-1.3.9-5.el6_2.x86_64.rpm | 123 kB 00:00 (2/15): apr-devel-1.3.9-5.el6_2.x86_64.rpm | 176 kB 00:00 (3/15): apr-util-1.3.9-3.el6_0.1.x86_64.rpm | 87 kB 00:00 (4/15): apr-util-devel-1.3.9-3.el6_0.1.x86_64.rpm | 69 kB 00:00 (5/15): apr-util-ldap-1.3.9-3.el6_0.1.x86_64.rpm | 15 kB 00:00 (6/15): cyrus-sasl-devel-2.1.23-15.el6_6.2.x86_64.rpm | 303 kB 00:00 (7/15): db4-cxx-4.7.25-20.el6_7.x86_64.rpm | 588 kB 00:00 (8/15): db4-devel-4.7.25-20.el6_7.x86_64.rpm | 6.6 MB 00:02 (9/15): expat-devel-2.0.1-11.el6_2.x86_64.rpm | 120 kB 00:00 (10/15): httpd-2.2.15-47.el6.centos.3.x86_64.rpm | 831 kB 00:00 (11/15): httpd-devel-2.2.15-47.el6.centos.3.x86_64.rpm | 155 kB 00:00 (12/15): httpd-manual-2.2.15-47.el6.centos.3.noarch.rpm | 788 kB 00:00 (13/15): httpd-tools-2.2.15-47.el6.centos.3.x86_64.rpm | 77 kB 00:00 (14/15): mailcap-2.1.31-2.el6.noarch.rpm | 27 kB 00:00 (15/15): openldap-devel-2.4.40-7.el6_7.x86_64.rpm | 1.1 MB 00:00 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 合計 1.1 MB/s | 11 MB 00:10 rpm_check_debug を実行しています トランザクションのテストを実行しています トランザクションのテストを成功しました トランザクションを実行しています インストールしています : apr-1.3.9-5.el6_2.x86_64 1/15 インストールしています : apr-util-1.3.9-3.el6_0.1.x86_64 2/15 インストールしています : apr-devel-1.3.9-5.el6_2.x86_64 3/15 インストールしています : apr-util-ldap-1.3.9-3.el6_0.1.x86_64 4/15 インストールしています : httpd-tools-2.2.15-47.el6.centos.3.x86_64 5/15 インストールしています : mailcap-2.1.31-2.el6.noarch 6/15 インストールしています : httpd-2.2.15-47.el6.centos.3.x86_64 7/15 インストールしています : db4-cxx-4.7.25-20.el6_7.x86_64 8/15 インストールしています : db4-devel-4.7.25-20.el6_7.x86_64 9/15 インストールしています : expat-devel-2.0.1-11.el6_2.x86_64 10/15 インストールしています : cyrus-sasl-devel-2.1.23-15.el6_6.2.x86_64 11/15 インストールしています : openldap-devel-2.4.40-7.el6_7.x86_64 12/15 インストールしています : apr-util-devel-1.3.9-3.el6_0.1.x86_64 13/15 インストールしています : httpd-devel-2.2.15-47.el6.centos.3.x86_64 14/15 インストールしています : httpd-manual-2.2.15-47.el6.centos.3.noarch 15/15 Verifying : httpd-devel-2.2.15-47.el6.centos.3.x86_64 1/15 Verifying : httpd-manual-2.2.15-47.el6.centos.3.noarch 2/15 Verifying : apr-devel-1.3.9-5.el6_2.x86_64 3/15 Verifying : cyrus-sasl-devel-2.1.23-15.el6_6.2.x86_64 4/15 Verifying : apr-util-ldap-1.3.9-3.el6_0.1.x86_64 5/15 Verifying : openldap-devel-2.4.40-7.el6_7.x86_64 6/15 Verifying : apr-1.3.9-5.el6_2.x86_64 7/15 Verifying : apr-util-devel-1.3.9-3.el6_0.1.x86_64 8/15 Verifying : httpd-tools-2.2.15-47.el6.centos.3.x86_64 9/15 Verifying : db4-devel-4.7.25-20.el6_7.x86_64 10/15 Verifying : apr-util-1.3.9-3.el6_0.1.x86_64 11/15 Verifying : expat-devel-2.0.1-11.el6_2.x86_64 12/15 Verifying : db4-cxx-4.7.25-20.el6_7.x86_64 13/15 Verifying : mailcap-2.1.31-2.el6.noarch 14/15 Verifying : httpd-2.2.15-47.el6.centos.3.x86_64 15/15 インストール: httpd.x86_64 0:2.2.15-47.el6.centos.3 httpd-devel.x86_64 0:2.2.15-47.el6.centos.3 httpd-manual.noarch 0:2.2.15-47.el6.centos.3 httpd-tools.x86_64 0:2.2.15-47.el6.centos.3 依存性関連をインストールしました: apr.x86_64 0:1.3.9-5.el6_2 apr-devel.x86_64 0:1.3.9-5.el6_2 apr-util.x86_64 0:1.3.9-3.el6_0.1 apr-util-devel.x86_64 0:1.3.9-3.el6_0.1 apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 cyrus-sasl-devel.x86_64 0:2.1.23-15.el6_6.2 db4-cxx.x86_64 0:4.7.25-20.el6_7 db4-devel.x86_64 0:4.7.25-20.el6_7 expat-devel.x86_64 0:2.0.1-11.el6_2 mailcap.noarch 0:2.1.31-2.el6 openldap-devel.x86_64 0:2.4.40-7.el6_7 完了しました!
ファイアウォールの設定
http通信に利用される80番ポートを開けておきます。
$ iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
iptables再起動
$ service iptables restart iptables: チェインをポリシー ACCEPT へ設定中filter [ OK ] iptables: ファイアウォールルールを消去中: [ OK ] iptables: モジュールを取り外し中: [ OK ] iptables: ファイアウォールルールを適用中: [ OK ]
確認
$ iptables -L -n | grep 80 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
ポートマッピング
自分のサーバのネットワークはブロードバンドルータをかませているので、ポートマッピング(ポートフォワーディング)を設定します。
これは利用しているルータによって設定方法が異なると思うので割愛します。
Apacheの設定
バーチャルホスト
今回はネームベースでバーチャルホストを設定します。
まずはhttpd.confから
#NameVirtualHost *:80
とコメントアウトされている箇所を
NameVirtualHost *:80
とコメントアウトを外します。
次にバーチャルホストの設定。
バーチャルホストの設定はhttpd.confに書いてもいいのですが、数が増えてくると管理しにくいので、/etc/httpd/conf.d/vhosts/ 配下にバーチャルホストごとに設定ファイルを作る(1バーチャルホスト=1ファイル)という運用にします。
というわけで、今回はvhostsディレクトリ配下にバーチャルホスト毎の設定ファイルを置くことにします。
/etc/httpd/conf.d/httpd-vhosts.conf
# # Include virtual host based config file. # Include conf.d/vhosts/*.conf # vhostsディレクトリ配下の〜.confファイルを読み込むようにする
バーチャルホストごとに設定ファイルを作成
/etc/httpd/conf.d/vhosts/example.conf
# # example.co.jp # <VirtualHost *:80> ServerAdmin root@example DocumentRoot /home/apache/example/html/ ServerName example.co.jp ServerAlias www.example.co.jp ErrorLog /home/apache/example/logs/error_log CustomLog /home/apache/example/logs/access_log common <Directory /> Options Indexes AllowOverride None Order allow,deny Allow from all </Directory> </VirtualHost>
アクセス
上記の設定の場合、http://example.co.jp もしくは http://www.example.co.jp でアクセスできるはずです。
上記のテストページが出ればOKです。
ちなみに、インストール時にhttpd-manualも入れておけば、http://example.co.jp/manual にアクセスした時に、Apacheのマニュアルに飛べるはずです。
自動起動設定
OSを再起動した時もサーバが自動的に立ち上がるように、設定を変更します。
# 確認 chkconfig | grep httpd httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off # デフォルトだとoffなので... # chkconfig を on に $ chkconfig httpd on # 確認 $ chkconfig | grep httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
参考
Apache HTTP サーバ バージョン 2.2 ドキュメント - Apache HTTP サーバ バージョン 2.2
Apache 2.2.xでネームベースのVirtual Hostの設定 - Qiita