忘備録

日々の調べ物をまとめる。アウトプットする。基本自分用。

【Vagrant】Packerでboxファイルの作成

以前、vagrantの初歩的な使い方について記事を挙げましたが、その際に利用したBoxファイルはvagrantboxからダウンロードしていました。

mktktmr.hatenablog.jp

今回は他人が作ったBoxファイルを拝借していたのを、自作にしようというのが趣旨です。

環境

Packerの入手

Boxファイルを作成するツールは幾つかあるみたいですが、一番メジャーそうなPackerを使います。

Packer by HashiCorp

公式サイトからツールをダウンロードしてきます。

ダウンロードしたファイル(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.jsonubuntu.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仮想マシン起動

$ 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

うまく起動したでしょうか?

f:id:mktktmr:20160406192511p:plain

Boxファイルを自作しておけば、中身が分かるし、Boxファイルを余所からダウンロードする時間も省けるため、Boxファイルの登録が気軽にできて良いかと思います。

参考

Appendix B. Automating the installation using preseeding

Packerをつかって3ステップでVagrantのBoxを作る - Qiita

PreseedによるUbuntuの自動インストール入門 - Qiita

日本人向け Packer スクリプト差分 for Ubuntu Trusty - 来年読む。

「Packer」でDocker用のイメージファイルを作ってみよう - さくらのナレッジ

Packerを使ったISOイメージからの仮想マシン自動デプロイ - さくらのナレッジ

【Vagrant】インストールと基本コマンド

環境

用語

プロバイダ

Virtual Boxとか、VM Wareとか仮想マシン本体のこと。 EC2なんかもプロバイダとして利用出来るらしい。

プロビジョニング

Chefとか。 ミドルウェアのインストールや設定を行うツールシェルスクリプトでも出来るみたいで、Chefを使う気満々だったのが少し削がれた。

Boxファイル

仮想マシンを起動する際のベースとなるイメージファイル。 通常、OSイメージをベースにvagrantユーザの作成・sshd起動・プロビジョニングツールのインストールなど最小限の設定を行う。

Vagrantfile

仮想マシンのスペックやプロビジョニングツールの指定などの構成を記述するファイル。 Rubyで記述する。 こいつさえあれば、どんな環境でも同じ仮想マシンが構築できる。

Vagrantインストール

公式サイトからインストーラを入手、ポチポチしてインストールします。

Vagrant by HashiCorp

バージョン確認

$ 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ファイルにはデフォルトで色々書かれているので、それを参考に設定を記述してみた。

ちなみに今回設定していることは以下

  1. 仮想マシンのウィンドウを開く
  2. プロビジョニングの設定
    • パッケージの更新
    • ubuntu-desktopのインストール

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のウィンドウで立ち上がる。

VirtualBox

f:id:mktktmr:20160319233308p:plain

初期ユーザは

id: vagrant
pass: vagrant

となってます。

停止

$ 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) ユーザーからプログラムへの入力をする方法 | マイナビニュース

WebSocket サーバの実装とプロトコル解説 - Block Rockin’ Codes

【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」というスクリプトがあり、実行するとsslpythonといった依存パッケージをインストールしてくれる。

 ./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  31 07:37 2016 .
drwx------. 3 root root 4096  31 07:37 2016 ..
lrwxrwxrwx. 1 root root   40  31 07:37 2016 cert.pem -> ../../archive/example.co.jp/cert1.pem # 証明書
lrwxrwxrwx. 1 root root   41  31 07:37 2016 chain.pem -> ../../archive/example.co.jp/chain1.pem # 証明書チェーン
lrwxrwxrwx. 1 root root   45  31 07:37 2016 fullchain.pem -> ../../archive/example.co.jp/fullchain1.pem # 証明書(cert.pemとchain.pemをまとめたもの)
lrwxrwxrwx. 1 root root   43  31 07:37 2016 privkey.pem -> ../../archive/example.co.jp/privkey1.pemsh # 秘密鍵

Apachehttps対応

ssl.confの設定

/etc/httpd/conf.d/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モジュールをロードするように以下を追記します。

/etc/httpd/conf/httpd.conf

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_rewritehttpsで接続するようにしてやります。

/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

SSL証明書インストールに関するメモ | ぺんラボブログ

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

Apacheのエラー:Could not reliably determine the server’s fully qualified domain name〜とメッセージが出たときの対応 - yummy-yummy

【CentOS6】Apache2.2インストール&設定

環境

インストール

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から

/etc/httpd/conf/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 でアクセスできるはずです。

f:id:mktktmr:20160301035915p:plain

上記のテストページが出ればOKです。

ちなみに、インストール時にhttpd-manualも入れておけば、http://example.co.jp/manual にアクセスした時に、Apacheのマニュアルに飛べるはずです。

f:id:mktktmr:20160309045526p:plain

自動起動設定

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

apache2.2 バーチャルホストの設定 前編

Apache httpd tools freecode日本語情報ページ - OSDN

Chapter 17. Web Servers

【Python】URLエンコードされたテキストファイルをデコードしてファイル出力

URLエンコードされた文字列が吐かれたログファイルをデコードすることがあったので、お勉強がてら作ってみた。

環境

Python 2.7.10

ソース

f_cnv.py

#!/usr/bin/python
# -*- coding: utf-8 -*-

# 文字コードの指定:http://yono.cc/python/python_basics/japanese.html
# コメント:http://python301.blog123.fc2.com/blog-entry-9.html

import sys
import urllib

# 命名規約:http://nekowarau.seesaa.net/article/426647551.html
def url_decode(input_path, output_path):
    
    # if文:http://www.pythonweb.jp/tutorial/if/index4.html
    # 論理演算子:http://www.pythonweb.jp/tutorial/if/index6.html
    if input_path == "" and output_path =="":
        sys.exit ("error: The number of parameters has to be 2" + "\n" + "info: First param is input file path, second param is output file path")

    print "input file is " + input_path + ", " + "output file is " + output_path

    # 数値=>文字列:http://www.pythonweb.jp/tutorial/string/index9.html
    # インデックス付きfor:http://www.gesource.jp/programming/python/code/0022.html
    """
    strParam = ""
    for i, e in enumerate(param):
        strParam = strParam + " param[" + str(i) + "]" + "=" + e

    print "info: param is" + strParam
    """

    # ファイル入力:http://www.yukun.info/blog/2008/06/python-file.html#readlines_8211_1
    rf = open(input_path)
    lines = rf.readlines() 
    rf.close()

    # ファイル出力:http://www.mwsoft.jp/programming/python/file.html
    wf  = open(output_path, "w")

    for line in lines:
        # urlエンコード・デコード:http://python.g.hatena.ne.jp/mhrs/20060609/p1
        decodedLine = urllib.unquote_plus(line);
        wf.write(decodedLine)
    print

    wf.close()

# メイン関数的な:http://qiita.com/shunsuke227ono/items/a043bfa9998e7033de3a
if __name__ == "__main__":
    
    # コマンドライン引数:http://www.python-izm.com/contents/basis/command_line_arguments.shtml
    param = sys.argv

    # 配列のサイズ:http://www.pythonweb.jp/tutorial/list/index5.html
    if len(param) != 3:
        # 終了メソッド:http://d.hatena.ne.jp/kakurasan/20110512/p1
        sys.exit ("error: The number of parameters has to be 2" + "\n" + "info: First param is input file path, second param is output file path")
    
    url_decode(param[1], param[2])

使い方

第一引数に入力ファイル、第二引数に出力ファイルのパスを渡します。

スクリプトとして実行

例)encode.txtをデコードしてdecode.txtとして出力

$ ./f_env.py /home/hoge/Documents/encode.txt /home/hoge/Documents/decode.txt

モジュールとして実行

例)上記と同じ処理を対話型シェルで実行

$ python
>>> import f_env
>>> f_cnv.url_decode("/home/hoge/Documents/encode.txt", "/home/hoge/Documents/decode.txt")

.pycファイル

上記のモジュールとして実行で呼び出すと「f_env.pyc」というファイルが作られていた。

こいつはなんぞと思いググってみた。

.pycファイルを作成させない方法メモ - かせきのうさぎさん

Python で書かれたモジュールを import すると自動的に .pycファイルが作成される。このファイルはコンパイルして得られたバイトコードを保存したものだ。つまり一種のキャッシュである。モジュールは他のファイルからも import される可能性が高いので、こうしておけばコンパイルする時間を節約できる。

ということらしい。

【CentOS6】java8 + Tomcat7をインストール

今回はyumを利用します。

yumを利用するとパスをごにょごにょしたり、起動スクリプト自作しなくてよかったりメリットあるので利用します。

yumに頼った所為でハマったのですが。。。

自分の手で色々やってインストールするなら↓が詳しくて良いかも。

LinuxサーバへのTomcat 7導入 (Tomcatインストール)

環境

  • サーバOS: CentOS6.7
  • webサーバ: Apache2.2

手順

javaのインストール

java8関連のパッケージはベースリポジトリにあるのでyumでインストール。

$ yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
読み込んだプラグイン:fastestmirror
インストール処理の設定をしています
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.iij.ad.jp
 * rpmforge: ftp.kddilabs.jp
 * updates: centosv4.centos.org
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> Package java-1.8.0-openjdk.x86_64 1:1.8.0.71-1.b15.el6_7 will be インストール
--> 依存性の処理をしています: java-1.8.0-openjdk-headless = 1:1.8.0.71-1.b15.el6_7 のパッケージ: 1:java-1.8.0-openjdk-1.8.0.71-1.b15.el6_7.x86_64
--> 依存性の処理をしています: xorg-x11-fonts-Type1 のパッケージ: 1:java-1.8.0-openjdk-1.8.0.71-1.b15.el6_7.x86_64
--> 依存性の処理をしています: libjvm.so(SUNWprivate_1.1)(64bit) のパッケージ: 1:java-1.8.0-openjdk-1.8.0.71-1.b15.el6_7.x86_64
--> 依存性の処理をしています: libjava.so(SUNWprivate_1.1)(64bit) のパッケージ: 1:java-1.8.0-openjdk-1.8.0.71-1.b15.el6_7.x86_64
--> 依存性の処理をしています: libasound.so.2(ALSA_0.9.0rc4)(64bit) のパッケージ: 1:java-1.8.0-openjdk-1.8.0.71-1.b15.el6_7.x86_64
--> 依存性の処理をしています: libasound.so.2(ALSA_0.9)(64bit) のパッケージ: 1:java-1.8.0-openjdk-1.8.0.71-1.b15.el6_7.x86_64
--> 依存性の処理をしています: libjvm.so()(64bit) のパッケージ: 1:java-1.8.0-openjdk-1.8.0.71-1.b15.el6_7.x86_64
--> 依存性の処理をしています: libjava.so()(64bit) のパッケージ: 1:java-1.8.0-openjdk-1.8.0.71-1.b15.el6_7.x86_64
--> 依存性の処理をしています: libgif.so.4()(64bit) のパッケージ: 1:java-1.8.0-openjdk-1.8.0.71-1.b15.el6_7.x86_64
--> 依存性の処理をしています: libawt.so()(64bit) のパッケージ: 1:java-1.8.0-openjdk-1.8.0.71-1.b15.el6_7.x86_64
--> 依存性の処理をしています: libasound.so.2()(64bit) のパッケージ: 1:java-1.8.0-openjdk-1.8.0.71-1.b15.el6_7.x86_64
--> 依存性の処理をしています: libXtst.so.6()(64bit) のパッケージ: 1:java-1.8.0-openjdk-1.8.0.71-1.b15.el6_7.x86_64
---> Package java-1.8.0-openjdk-devel.x86_64 1:1.8.0.71-1.b15.el6_7 will be インストール
--> トランザクションの確認を実行しています。
---> Package alsa-lib.x86_64 0:1.0.22-3.el6 will be インストール
---> Package giflib.x86_64 0:4.1.6-3.1.el6 will be インストール
--> 依存性の処理をしています: libSM.so.6()(64bit) のパッケージ: giflib-4.1.6-3.1.el6.x86_64
--> 依存性の処理をしています: libICE.so.6()(64bit) のパッケージ: giflib-4.1.6-3.1.el6.x86_64
---> Package java-1.8.0-openjdk-headless.x86_64 1:1.8.0.71-1.b15.el6_7 will be インストール
--> 依存性の処理をしています: tzdata-java >= 2014f-1 のパッケージ: 1:java-1.8.0-openjdk-headless-1.8.0.71-1.b15.el6_7.x86_64
--> 依存性の処理をしています: jpackage-utils のパッケージ: 1:java-1.8.0-openjdk-headless-1.8.0.71-1.b15.el6_7.x86_64
---> Package libXtst.x86_64 0:1.2.2-2.1.el6 will be インストール
---> Package xorg-x11-fonts-Type1.noarch 0:7.2-11.el6 will be インストール
--> 依存性の処理をしています: ttmkfdir のパッケージ: xorg-x11-fonts-Type1-7.2-11.el6.noarch
--> 依存性の処理をしています: ttmkfdir のパッケージ: xorg-x11-fonts-Type1-7.2-11.el6.noarch
--> 依存性の処理をしています: mkfontdir のパッケージ: xorg-x11-fonts-Type1-7.2-11.el6.noarch
--> 依存性の処理をしています: mkfontdir のパッケージ: xorg-x11-fonts-Type1-7.2-11.el6.noarch
--> トランザクションの確認を実行しています。
---> Package jpackage-utils.noarch 0:1.7.5-3.14.el6 will be インストール
---> Package libICE.x86_64 0:1.0.6-1.el6 will be インストール
---> Package libSM.x86_64 0:1.2.1-2.el6 will be インストール
---> Package ttmkfdir.x86_64 0:3.0.9-32.1.el6 will be インストール
---> Package tzdata-java.noarch 0:2016a-2.el6 will be インストール
---> Package xorg-x11-font-utils.x86_64 1:7.2-11.el6 will be インストール
--> 依存性の処理をしています: libfontenc.so.1()(64bit) のパッケージ: 1:xorg-x11-font-utils-7.2-11.el6.x86_64
--> 依存性の処理をしています: libXfont.so.1()(64bit) のパッケージ: 1:xorg-x11-font-utils-7.2-11.el6.x86_64
--> トランザクションの確認を実行しています。
---> Package libXfont.x86_64 0:1.4.5-5.el6_7 will be インストール
---> Package libfontenc.x86_64 0:1.0.5-2.el6 will be インストール
--> 依存性解決を終了しました。

依存性を解決しました

=======================================================================================================================
 パッケージ                             アーキテクチャ    バージョン                          リポジトリー        容量
=======================================================================================================================
インストールしています:
 java-1.8.0-openjdk                     x86_64            1:1.8.0.71-1.b15.el6_7              updates            190 k
 java-1.8.0-openjdk-devel               x86_64            1:1.8.0.71-1.b15.el6_7              updates             10 M
依存性関連でのインストールをします。:
 alsa-lib                               x86_64            1.0.22-3.el6                        base               370 k
 giflib                                 x86_64            4.1.6-3.1.el6                       base                37 k
 java-1.8.0-openjdk-headless            x86_64            1:1.8.0.71-1.b15.el6_7              updates             32 M
 jpackage-utils                         noarch            1.7.5-3.14.el6                      base                60 k
 libICE                                 x86_64            1.0.6-1.el6                         base                53 k
 libSM                                  x86_64            1.2.1-2.el6                         base                37 k
 libXfont                               x86_64            1.4.5-5.el6_7                       updates            137 k
 libXtst                                x86_64            1.2.2-2.1.el6                       base                19 k
 libfontenc                             x86_64            1.0.5-2.el6                         base                24 k
 ttmkfdir                               x86_64            3.0.9-32.1.el6                      base                43 k
 tzdata-java                            noarch            2016a-2.el6                         updates            177 k
 xorg-x11-font-utils                    x86_64            1:7.2-11.el6                        base                75 k
 xorg-x11-fonts-Type1                   noarch            7.2-11.el6                          base               520 k

トランザクションの要約
=======================================================================================================================
インストール        15 パッケージ

総ダウンロード容量: 43 M
インストール済み容量: 146 M
パッケージをダウンロードしています:
(1/15): alsa-lib-1.0.22-3.el6.x86_64.rpm                                                        | 370 kB     00:00     
(2/15): giflib-4.1.6-3.1.el6.x86_64.rpm                                                         |  37 kB     00:00     
(3/15): java-1.8.0-openjdk-1.8.0.71-1.b15.el6_7.x86_64.rpm                                      | 190 kB     00:01     
(4/15): java-1.8.0-openjdk-devel-1.8.0.71-1.b15.el6_7.x86_64.rpm                                |  10 MB     01:27     
(5/15): java-1.8.0-openjdk-headless-1.8.0.71-1.b15.el6_7.x86_64.rpm                             |  32 MB     03:50     
(6/15): jpackage-utils-1.7.5-3.14.el6.noarch.rpm                                                |  60 kB     00:00     
(7/15): libICE-1.0.6-1.el6.x86_64.rpm                                                           |  53 kB     00:00     
(8/15): libSM-1.2.1-2.el6.x86_64.rpm                                                            |  37 kB     00:00     
(9/15): libXfont-1.4.5-5.el6_7.x86_64.rpm                                                       | 137 kB     00:01     
(10/15): libXtst-1.2.2-2.1.el6.x86_64.rpm                                                       |  19 kB     00:00     
(11/15): libfontenc-1.0.5-2.el6.x86_64.rpm                                                      |  24 kB     00:00     
(12/15): ttmkfdir-3.0.9-32.1.el6.x86_64.rpm                                                     |  43 kB     00:00     
(13/15): tzdata-java-2016a-2.el6.noarch.rpm                                                     | 177 kB     00:01     
(14/15): xorg-x11-font-utils-7.2-11.el6.x86_64.rpm                                              |  75 kB     00:00     
(15/15): xorg-x11-fonts-Type1-7.2-11.el6.noarch.rpm                                             | 520 kB     00:00     
-----------------------------------------------------------------------------------------------------------------------
合計                                                                                   136 kB/s |  43 MB     05:27     
rpm_check_debug を実行しています
トランザクションのテストを実行しています
トランザクションのテストを成功しました
トランザクションを実行しています
  インストールしています  : libfontenc-1.0.5-2.el6.x86_64                                                         1/15 
  インストールしています  : libICE-1.0.6-1.el6.x86_64                                                             2/15 
  インストールしています  : libSM-1.2.1-2.el6.x86_64                                                              3/15 
  インストールしています  : giflib-4.1.6-3.1.el6.x86_64                                                           4/15 
  インストールしています  : libXfont-1.4.5-5.el6_7.x86_64                                                         5/15 
  インストールしています  : 1:xorg-x11-font-utils-7.2-11.el6.x86_64                                               6/15 
  インストールしています  : libXtst-1.2.2-2.1.el6.x86_64                                                          7/15 
  インストールしています  : alsa-lib-1.0.22-3.el6.x86_64                                                          8/15 
  インストールしています  : tzdata-java-2016a-2.el6.noarch                                                        9/15 
  インストールしています  : jpackage-utils-1.7.5-3.14.el6.noarch                                                 10/15 
  インストールしています  : ttmkfdir-3.0.9-32.1.el6.x86_64                                                       11/15 
  インストールしています  : xorg-x11-fonts-Type1-7.2-11.el6.noarch                                               12/15 
  インストールしています  : 1:java-1.8.0-openjdk-headless-1.8.0.71-1.b15.el6_7.x86_64                            13/15 
  インストールしています  : 1:java-1.8.0-openjdk-devel-1.8.0.71-1.b15.el6_7.x86_64                               14/15 
  インストールしています  : 1:java-1.8.0-openjdk-1.8.0.71-1.b15.el6_7.x86_64                                     15/15 
  Verifying               : ttmkfdir-3.0.9-32.1.el6.x86_64                                                        1/15 
  Verifying               : libXfont-1.4.5-5.el6_7.x86_64                                                         2/15 
  Verifying               : jpackage-utils-1.7.5-3.14.el6.noarch                                                  3/15 
  Verifying               : libICE-1.0.6-1.el6.x86_64                                                             4/15 
  Verifying               : libfontenc-1.0.5-2.el6.x86_64                                                         5/15 
  Verifying               : tzdata-java-2016a-2.el6.noarch                                                        6/15 
  Verifying               : alsa-lib-1.0.22-3.el6.x86_64                                                          7/15 
  Verifying               : 1:xorg-x11-font-utils-7.2-11.el6.x86_64                                               8/15 
  Verifying               : 1:java-1.8.0-openjdk-devel-1.8.0.71-1.b15.el6_7.x86_64                                9/15 
  Verifying               : libSM-1.2.1-2.el6.x86_64                                                             10/15 
  Verifying               : libXtst-1.2.2-2.1.el6.x86_64                                                         11/15 
  Verifying               : xorg-x11-fonts-Type1-7.2-11.el6.noarch                                               12/15 
  Verifying               : 1:java-1.8.0-openjdk-1.8.0.71-1.b15.el6_7.x86_64                                     13/15 
  Verifying               : 1:java-1.8.0-openjdk-headless-1.8.0.71-1.b15.el6_7.x86_64                            14/15 
  Verifying               : giflib-4.1.6-3.1.el6.x86_64                                                          15/15 

インストール:
  java-1.8.0-openjdk.x86_64 1:1.8.0.71-1.b15.el6_7        java-1.8.0-openjdk-devel.x86_64 1:1.8.0.71-1.b15.el6_7       

依存性関連をインストールしました:
  alsa-lib.x86_64 0:1.0.22-3.el6                                      giflib.x86_64 0:4.1.6-3.1.el6                    
  java-1.8.0-openjdk-headless.x86_64 1:1.8.0.71-1.b15.el6_7           jpackage-utils.noarch 0:1.7.5-3.14.el6           
  libICE.x86_64 0:1.0.6-1.el6                                         libSM.x86_64 0:1.2.1-2.el6                       
  libXfont.x86_64 0:1.4.5-5.el6_7                                     libXtst.x86_64 0:1.2.2-2.1.el6                   
  libfontenc.x86_64 0:1.0.5-2.el6                                     ttmkfdir.x86_64 0:3.0.9-32.1.el6                 
  tzdata-java.noarch 0:2016a-2.el6                                    xorg-x11-font-utils.x86_64 1:7.2-11.el6          
  xorg-x11-fonts-Type1.noarch 0:7.2-11.el6                           

完了しました!

確認

$ java -version
openjdk version "1.8.0_71"
OpenJDK Runtime Environment (build 1.8.0_71-b15)
OpenJDK 64-Bit Server VM (build 25.71-b15, mixed mode)

Tomcatのインストール

残念ながらCentOS6のリポジトリにTomcat7はないので(バージョン6はある)、サードパーティリポジトリから入手する。

# ないんです><
$ yum search tomcat7
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.iij.ad.jp
 * rpmforge: ftp.kddilabs.jp
 * updates: centosx4.centos.org
警告: 一致するものが見つかりません: tomcat7
見つかりませんでした

jpackageリポジトリの取得

Tomcat7はjava関連のパッケージを提供してるjpackageリポジトリから取得することにします。

:: JPackage Project | Home ::

rpm -Uvh http://mirrors.dotsrc.org/jpackage/6.0/generic/free/RPMS/jpackage-release-6-3.jpp6.noarch.rpm
http://mirrors.dotsrc.org/jpackage/6.0/generic/free/RPMS/jpackage-release-6-3.jpp6.noarch.rpm を取得中
エラー: 依存性の欠如:
    yum-priorities は jpackage-release-6-3.jpp6.noarch に必要とされています

yum-prioritiesを入れないとダメみたいです。

$ yum install -y yum-priorities
読み込んだプラグイン:fastestmirror
インストール処理の設定をしています
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.iij.ad.jp
 * rpmforge: ftp.kddilabs.jp
 * updates: centosv4.centos.org
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> Package yum-plugin-priorities.noarch 0:1.1.30-30.el6 will be インストール
--> 依存性解決を終了しました。

依存性を解決しました

============================================================================================================================
 パッケージ                             アーキテクチャ          バージョン                      リポジトリー           容量
============================================================================================================================
インストールしています:
 yum-plugin-priorities                  noarch                  1.1.30-30.el6                   base                   25 k

トランザクションの要約
============================================================================================================================
インストール         1 パッケージ

総ダウンロード容量: 25 k
インストール済み容量: 28 k
パッケージをダウンロードしています:
yum-plugin-priorities-1.1.30-30.el6.noarch.rpm                                                       |  25 kB     00:00     
rpm_check_debug を実行しています
トランザクションのテストを実行しています
トランザクションのテストを成功しました
トランザクションを実行しています
  インストールしています  : yum-plugin-priorities-1.1.30-30.el6.noarch                                                  1/1 
  Verifying               : yum-plugin-priorities-1.1.30-30.el6.noarch                                                  1/1 

インストール:
  yum-plugin-priorities.noarch 0:1.1.30-30.el6                                                                              

完了しました!

気を取り直してリポジトリを取得。

$ rpm -Uvh http://mirrors.dotsrc.org/jpackage/6.0/generic/free/RPMS/jpackage-release-6-3.jpp6.noarch.rpm
http://mirrors.dotsrc.org/jpackage/6.0/generic/free/RPMS/jpackage-release-6-3.jpp6.noarch.rpm を取得中
準備中...                ########################################### [100%]
   1:jpackage-release       ########################################### [100%]

確認

$ cat /etc/yum.repos.d/jpackage.repo
[jpackage]
name=JPackage 6 generic
mirrorlist=http://www.jpackage.org/mirrorlist.php?dist=generic&type=free&release=6.0
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-jpackage
priority=10

インストール

念のため、tomcat7がリポジトリにあるか確認

$ yum search tomcat7
読み込んだプラグイン:fastestmirror, priorities
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.iij.ad.jp
 * jpackage: mirrors.dotsrc.org
 * rpmforge: ftp.kddilabs.jp
 * updates: centosd6.centos.org
jpackage                                                                                             | 1.9 kB     00:00     
jpackage/primary_db                                                                                  | 1.7 MB     00:06     
238 packages excluded due to repository priority protections
=================================================== N/S Matched: tomcat7 ===================================================
tomcat7.noarch : Apache Servlet/JSP Engine, RI for Servlet 3.0/JSP 2.2 API
tomcat7-admin-webapps.noarch : The host-manager and manager web applications for Apache Tomcat
tomcat7-docs-webapp.noarch : The docs web application for Apache Tomcat
tomcat7-el-2.2-api.noarch : Expression Language v2.2 API
tomcat7-javadoc.noarch : Javadoc generated documentation for Apache Tomcat
tomcat7-jsp-2.2-api.noarch : Apache Tomcat JSP API implementation classes
tomcat7-lib.noarch : Libraries needed to run the Tomcat Web container
tomcat7-servlet-3.0-api.noarch : Apache Tomcat Servlet API implementation classes
tomcat7-webapps.noarch : The ROOT and examples web applications for Apache Tomcat

  Name and summary matches only, use "search all" for everything.

大丈夫ですね!

前置きが長くなりましたが、ようやくtomcatをインストール。

# せっかくなんで管理ページも入れておく
$ yum -y install tomcat7-webapps tomcat7-admin-webapps
読み込んだプラグイン:fastestmirror, priorities
インストール処理の設定をしています
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.iij.ad.jp
 * jpackage: mirror.ibcp.fr
 * rpmforge: ftp.kddilabs.jp
 * updates: centosd6.centos.org
238 packages excluded due to repository priority protections
依存性の解決をしています
--> トランザクションの確認を実行しています。
#〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜(中略)〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜
トランザクションの要約
============================================================================================================================
インストール        41 パッケージ

合計容量: 35 M
インストール済み容量: 91 M
パッケージをダウンロードしています:


パッケージ tomcat7-7.0.54-2.jpp6.noarch.rpm は署名されていません

。。。と思ったら、署名されていないとか言われてインストールできません。

--nogpgcheckオプションをつけて再実行。

$ yum install -y --nogpgcheck tomcat7-webapps tomcat7-admin-webapps
読み込んだプラグイン:fastestmirror, priorities
インストール処理の設定をしています
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.iij.ad.jp
 * jpackage: mirrors.dotsrc.org
 * rpmforge: ftp.kddilabs.jp
 * updates: centosv4.centos.org
238 packages excluded due to repository priority protections
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> Package tomcat7-admin-webapps.noarch 0:7.0.54-2.jpp6 will be インストール
--> 依存性の処理をしています: tomcat7 = 7.0.54-2.jpp6 のパッケージ: tomcat7-admin-webapps-7.0.54-2.jpp6.noarch
---> Package tomcat7-webapps.noarch 0:7.0.54-2.jpp6 will be インストール
--> 依存性の処理をしています: jakarta-taglibs-standard >= 1.1 のパッケージ: tomcat7-webapps-7.0.54-2.jpp6.noarch
--> トランザクションの確認を実行しています。
---> Package apache-taglibs-standard.noarch 0:1.1.2-8.jpp6 will be インストール
--> 依存性の処理をしています: xalan-j2 >= 2.6.0 のパッケージ: apache-taglibs-standard-1.1.2-8.jpp6.noarch
--> 依存性の処理をしています: jsp_2_1_api のパッケージ: apache-taglibs-standard-1.1.2-8.jpp6.noarch
--> 依存性の処理をしています: servlet_2_5_api のパッケージ: apache-taglibs-standard-1.1.2-8.jpp6.noarch
---> Package tomcat7.noarch 0:7.0.54-2.jpp6 will be インストール
--> 依存性の処理をしています: tomcat7-lib = 7.0.54-2.jpp6 のパッケージ: tomcat7-7.0.54-2.jpp6.noarch
--> 依存性の処理をしています: apache-commons-daemon のパッケージ: tomcat7-7.0.54-2.jpp6.noarch
--> 依存性の処理をしています: /lib/lsb/init-functions のパッケージ: tomcat7-7.0.54-2.jpp6.noarch
--> 依存性の処理をしています: apache-commons-logging のパッケージ: tomcat7-7.0.54-2.jpp6.noarch
--> トランザクションの確認を実行しています。
---> Package apache-commons-daemon.noarch 1:1.0.15-1.jpp6 will be インストール
---> Package apache-commons-logging.noarch 0:1.1.3-2.jpp6 will be インストール
---> Package redhat-lsb-core.x86_64 0:4.0-7.el6.centos will be インストール
--> 依存性の処理をしています: perl-Test-Simple のパッケージ: redhat-lsb-core-4.0-7.el6.centos.x86_64
--> 依存性の処理をしています: perl-Test-Harness のパッケージ: redhat-lsb-core-4.0-7.el6.centos.x86_64
--> 依存性の処理をしています: perl-ExtUtils-MakeMaker のパッケージ: redhat-lsb-core-4.0-7.el6.centos.x86_64
--> 依存性の処理をしています: perl-CGI のパッケージ: redhat-lsb-core-4.0-7.el6.centos.x86_64
--> 依存性の処理をしています: /usr/bin/time のパッケージ: redhat-lsb-core-4.0-7.el6.centos.x86_64
--> 依存性の処理をしています: /usr/bin/pax のパッケージ: redhat-lsb-core-4.0-7.el6.centos.x86_64
--> 依存性の処理をしています: /usr/bin/patch のパッケージ: redhat-lsb-core-4.0-7.el6.centos.x86_64
--> 依存性の処理をしています: /usr/bin/msgfmt のパッケージ: redhat-lsb-core-4.0-7.el6.centos.x86_64
--> 依存性の処理をしています: /usr/bin/man のパッケージ: redhat-lsb-core-4.0-7.el6.centos.x86_64
--> 依存性の処理をしています: /usr/bin/bc のパッケージ: redhat-lsb-core-4.0-7.el6.centos.x86_64
--> 依存性の処理をしています: /usr/bin/batch のパッケージ: redhat-lsb-core-4.0-7.el6.centos.x86_64
--> 依存性の処理をしています: /usr/bin/at のパッケージ: redhat-lsb-core-4.0-7.el6.centos.x86_64
--> 依存性の処理をしています: /bin/gettext のパッケージ: redhat-lsb-core-4.0-7.el6.centos.x86_64
---> Package tomcat6-jsp-2.1-api.noarch 0:6.0.33-2.jpp6 will be インストール
---> Package tomcat6-servlet-2.5-api.noarch 0:6.0.33-2.jpp6 will be インストール
---> Package tomcat7-lib.noarch 0:7.0.54-2.jpp6 will be インストール
--> 依存性の処理をしています: tomcat7-servlet-3.0-api = 7.0.54-2.jpp6 のパッケージ: tomcat7-lib-7.0.54-2.jpp6.noarch
--> 依存性の処理をしています: tomcat7-jsp-2.2-api = 7.0.54-2.jpp6 のパッケージ: tomcat7-lib-7.0.54-2.jpp6.noarch
--> 依存性の処理をしています: tomcat7-el-2.2-api = 7.0.54-2.jpp6 のパッケージ: tomcat7-lib-7.0.54-2.jpp6.noarch
--> 依存性の処理をしています: /usr/share/java/ecj3.jar のパッケージ: tomcat7-lib-7.0.54-2.jpp6.noarch
--> 依存性の処理をしています: apache-commons-dbcp-tomcat5 のパッケージ: tomcat7-lib-7.0.54-2.jpp6.noarch
--> 依存性の処理をしています: apache-commons-pool-tomcat5 のパッケージ: tomcat7-lib-7.0.54-2.jpp6.noarch
--> 依存性の処理をしています: ecj3 のパッケージ: tomcat7-lib-7.0.54-2.jpp6.noarch
--> 依存性の処理をしています: apache-commons-collections-tomcat5 のパッケージ: tomcat7-lib-7.0.54-2.jpp6.noarch
---> Package xalan-j2.noarch 0:2.7.1-8.jbossorg_1.jpp6 will be インストール
--> 依存性の処理をしています: jaxp_parser_impl のパッケージ: xalan-j2-2.7.1-8.jbossorg_1.jpp6.noarch
--> トランザクションの確認を実行しています。
---> Package apache-commons-collections-tomcat5.noarch 0:3.2.1-6.jpp6 will be インストール
---> Package apache-commons-dbcp-tomcat5.noarch 0:1.3.0-0.r830852.4.jpp6 will be インストール
---> Package apache-commons-pool-tomcat5.noarch 0:1.5.7-1.jpp6 will be インストール
---> Package at.x86_64 0:3.1.10-48.el6 will be インストール
---> Package bc.x86_64 0:1.06.95-1.el6 will be インストール
---> Package ecj3.noarch 1:3.7-1.jpp6 will be インストール
---> Package gettext.x86_64 0:0.17-18.el6 will be インストール
--> 依存性の処理をしています: cvs のパッケージ: gettext-0.17-18.el6.x86_64
---> Package java-1.5.0-gcj.x86_64 0:1.5.0.0-29.1.el6 will be インストール
--> 依存性の処理をしています: libgcj >= 4.1.2-5 のパッケージ: java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64
--> 依存性の処理をしています: sinjdoc のパッケージ: java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64
--> 依存性の処理をしています: /usr/lib64/security/classpath.security のパッケージ: java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64
--> 依存性の処理をしています: /usr/bin/gij のパッケージ: java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64
--> 依存性の処理をしています: /usr/bin/gij のパッケージ: java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64
--> 依存性の処理をしています: /usr/bin/gcj-dbtool のパッケージ: java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64
--> 依存性の処理をしています: /usr/bin/gcj-dbtool のパッケージ: java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64
---> Package man.x86_64 0:1.6f-32.el6 will be インストール
--> 依存性の処理をしています: lzma のパッケージ: man-1.6f-32.el6.x86_64
---> Package patch.x86_64 0:2.6-6.el6 will be インストール
---> Package pax.x86_64 0:3.4-10.1.el6 will be インストール
---> Package perl-CGI.x86_64 0:3.51-141.el6_7.1 will be インストール
---> Package perl-ExtUtils-MakeMaker.x86_64 0:6.55-141.el6_7.1 will be インストール
--> 依存性の処理をしています: perl-devel のパッケージ: perl-ExtUtils-MakeMaker-6.55-141.el6_7.1.x86_64
---> Package perl-Test-Harness.x86_64 0:3.17-141.el6_7.1 will be インストール
---> Package perl-Test-Simple.x86_64 0:0.92-141.el6_7.1 will be インストール
---> Package time.x86_64 0:1.7-38.el6 will be インストール
---> Package tomcat7-el-2.2-api.noarch 0:7.0.54-2.jpp6 will be インストール
---> Package tomcat7-jsp-2.2-api.noarch 0:7.0.54-2.jpp6 will be インストール
---> Package tomcat7-servlet-3.0-api.noarch 0:7.0.54-2.jpp6 will be インストール
--> トランザクションの確認を実行しています。
---> Package cvs.x86_64 0:1.11.23-16.el6 will be インストール
---> Package libgcj.x86_64 0:4.4.7-16.el6 will be インストール
--> 依存性の処理をしています: zip >= 2.1 のパッケージ: libgcj-4.4.7-16.el6.x86_64
--> 依存性の処理をしています: libart_lgpl >= 2.1.0 のパッケージ: libgcj-4.4.7-16.el6.x86_64
---> Package perl-devel.x86_64 4:5.10.1-141.el6_7.1 will be インストール
--> 依存性の処理をしています: perl(ExtUtils::ParseXS) のパッケージ: 4:perl-devel-5.10.1-141.el6_7.1.x86_64
--> 依存性の処理をしています: gdbm-devel のパッケージ: 4:perl-devel-5.10.1-141.el6_7.1.x86_64
---> Package sinjdoc.x86_64 0:0.5-9.1.el6 will be インストール
--> 依存性の処理をしています: java_cup >= 0.10 のパッケージ: sinjdoc-0.5-9.1.el6.x86_64
---> Package xz-lzma-compat.x86_64 0:4.999.9-0.5.beta.20091007git.el6 will be インストール
--> 依存性の処理をしています: xz = 4.999.9-0.5.beta.20091007git.el6 のパッケージ: xz-lzma-compat-4.999.9-0.5.beta.20091007git.el6.x86_64
--> トランザクションの確認を実行しています。
---> Package gdbm-devel.x86_64 0:1.8.0-38.el6 will be インストール
---> Package java-cup.noarch 2:0.11-0.a.3.jpp6 will be インストール
---> Package libart_lgpl.x86_64 0:2.3.20-5.1.el6 will be インストール
---> Package perl-ExtUtils-ParseXS.x86_64 1:2.2003.0-141.el6_7.1 will be インストール
---> Package xz.x86_64 0:4.999.9-0.5.beta.20091007git.el6 will be インストール
---> Package zip.x86_64 0:3.0-1.el6_7.1 will be インストール
--> 依存性解決を終了しました。

依存性を解決しました

============================================================================================================================
 パッケージ                                 アーキテクチャ バージョン                                リポジトリー      容量
============================================================================================================================
インストールしています:
 tomcat7-admin-webapps                      noarch         7.0.54-2.jpp6                             jpackage          41 k
 tomcat7-webapps                            noarch         7.0.54-2.jpp6                             jpackage         737 k
依存性関連でのインストールをします。:
 apache-commons-collections-tomcat5         noarch         3.2.1-6.jpp6                              jpackage          29 k
 apache-commons-daemon                      noarch         1:1.0.15-1.jpp6                           jpackage          52 k
 apache-commons-dbcp-tomcat5                noarch         1.3.0-0.r830852.4.jpp6                    jpackage         158 k
 apache-commons-logging                     noarch         1.1.3-2.jpp6                              jpackage          78 k
 apache-commons-pool-tomcat5                noarch         1.5.7-1.jpp6                              jpackage          78 k
 apache-taglibs-standard                    noarch         1.1.2-8.jpp6                              jpackage         299 k
 at                                         x86_64         3.1.10-48.el6                             base              61 k
 bc                                         x86_64         1.06.95-1.el6                             base             110 k
 cvs                                        x86_64         1.11.23-16.el6                            base             712 k
 ecj3                                       noarch         1:3.7-1.jpp6                              jpackage         1.0 M
 gdbm-devel                                 x86_64         1.8.0-38.el6                              base              25 k
 gettext                                    x86_64         0.17-18.el6                               base             1.8 M
 java-1.5.0-gcj                             x86_64         1.5.0.0-29.1.el6                          base             139 k
 java-cup                                   noarch         2:0.11-0.a.3.jpp6                         jpackage         104 k
 libart_lgpl                                x86_64         2.3.20-5.1.el6                            base              65 k
 libgcj                                     x86_64         4.4.7-16.el6                              base              19 M
 man                                        x86_64         1.6f-32.el6                               base             263 k
 patch                                      x86_64         2.6-6.el6                                 base              90 k
 pax                                        x86_64         3.4-10.1.el6                              base              69 k
 perl-CGI                                   x86_64         3.51-141.el6_7.1                          updates          209 k
 perl-ExtUtils-MakeMaker                    x86_64         6.55-141.el6_7.1                          updates          294 k
 perl-ExtUtils-ParseXS                      x86_64         1:2.2003.0-141.el6_7.1                    updates           46 k
 perl-Test-Harness                          x86_64         3.17-141.el6_7.1                          updates          232 k
 perl-Test-Simple                           x86_64         0.92-141.el6_7.1                          updates          113 k
 perl-devel                                 x86_64         4:5.10.1-141.el6_7.1                      updates          424 k
 redhat-lsb-core                            x86_64         4.0-7.el6.centos                          base              25 k
 sinjdoc                                    x86_64         0.5-9.1.el6                               base             705 k
 time                                       x86_64         1.7-38.el6                                base              26 k
 tomcat6-jsp-2.1-api                        noarch         6.0.33-2.jpp6                             jpackage          75 k
 tomcat6-servlet-2.5-api                    noarch         6.0.33-2.jpp6                             jpackage          89 k
 tomcat7                                    noarch         7.0.54-2.jpp6                             jpackage         103 k
 tomcat7-el-2.2-api                         noarch         7.0.54-2.jpp6                             jpackage          54 k
 tomcat7-jsp-2.2-api                        noarch         7.0.54-2.jpp6                             jpackage          82 k
 tomcat7-lib                                noarch         7.0.54-2.jpp6                             jpackage         4.9 M
 tomcat7-servlet-3.0-api                    noarch         7.0.54-2.jpp6                             jpackage         186 k
 xalan-j2                                   noarch         2.7.1-8.jbossorg_1.jpp6                   jpackage         3.1 M
 xz                                         x86_64         4.999.9-0.5.beta.20091007git.el6          base             137 k
 xz-lzma-compat                             x86_64         4.999.9-0.5.beta.20091007git.el6          base              16 k
 zip                                        x86_64         3.0-1.el6_7.1                             updates          259 k

トランザクションの要約
============================================================================================================================
インストール        41 パッケージ

合計容量: 35 M
インストール済み容量: 91 M
パッケージをダウンロードしています:
rpm_check_debug を実行しています
トランザクションのテストを実行しています
トランザクションのテストを成功しました
トランザクションを実行しています
警告: RPMDB は yum 以外で変更されました。
  インストールしています  : tomcat6-servlet-2.5-api-6.0.33-2.jpp6.noarch                                               1/41 
  インストールしています  : tomcat7-servlet-3.0-api-7.0.54-2.jpp6.noarch                                               2/41 
  インストールしています  : tomcat7-jsp-2.2-api-7.0.54-2.jpp6.noarch                                                   3/41 
  インストールしています  : tomcat6-jsp-2.1-api-6.0.33-2.jpp6.noarch                                                   4/41 
  インストールしています  : cvs-1.11.23-16.el6.x86_64                                                                  5/41 
  インストールしています  : gettext-0.17-18.el6.x86_64                                                                 6/41 
  インストールしています  : bc-1.06.95-1.el6.x86_64                                                                    7/41 
  インストールしています  : patch-2.6-6.el6.x86_64                                                                     8/41 
  インストールしています  : 1:apache-commons-daemon-1.0.15-1.jpp6.noarch                                               9/41 
  インストールしています  : perl-CGI-3.51-141.el6_7.1.x86_64                                                          10/41 
  インストールしています  : apache-commons-collections-tomcat5-3.2.1-6.jpp6.noarch                                    11/41 
  インストールしています  : apache-commons-logging-1.1.3-2.jpp6.noarch                                                12/41 
  インストールしています  : 2:java-cup-0.11-0.a.3.jpp6.noarch                                                         13/41 
  インストールしています  : tomcat7-el-2.2-api-7.0.54-2.jpp6.noarch                                                   14/41 
  インストールしています  : zip-3.0-1.el6_7.1.x86_64                                                                  15/41 
  インストールしています  : apache-commons-dbcp-tomcat5-1.3.0-0.r830852.4.jpp6.noarch                                 16/41 
  インストールしています  : apache-commons-pool-tomcat5-1.5.7-1.jpp6.noarch                                           17/41 
  インストールしています  : xz-4.999.9-0.5.beta.20091007git.el6.x86_64                                                18/41 
  インストールしています  : xz-lzma-compat-4.999.9-0.5.beta.20091007git.el6.x86_64                                    19/41 
  インストールしています  : man-1.6f-32.el6.x86_64                                                                    20/41 
  インストールしています  : libart_lgpl-2.3.20-5.1.el6.x86_64                                                         21/41 
  インストールしています  : libgcj-4.4.7-16.el6.x86_64                                                                22/41 
  インストールしています  : java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64                                                    23/41 
  インストールしています  : sinjdoc-0.5-9.1.el6.x86_64                                                                24/41 
  インストールしています  : 1:ecj3-3.7-1.jpp6.noarch                                                                  25/41 
  インストールしています  : tomcat7-lib-7.0.54-2.jpp6.noarch                                                          26/41 
  インストールしています  : xalan-j2-2.7.1-8.jbossorg_1.jpp6.noarch                                                   27/41 
  インストールしています  : apache-taglibs-standard-1.1.2-8.jpp6.noarch                                               28/41 
  インストールしています  : pax-3.4-10.1.el6.x86_64                                                                   29/41 
  インストールしています  : gdbm-devel-1.8.0-38.el6.x86_64                                                            30/41 
  インストールしています  : 1:perl-ExtUtils-ParseXS-2.2003.0-141.el6_7.1.x86_64                                       31/41 
  インストールしています  : perl-ExtUtils-MakeMaker-6.55-141.el6_7.1.x86_64                                           32/41 
  インストールしています  : 4:perl-devel-5.10.1-141.el6_7.1.x86_64                                                    33/41 
  インストールしています  : perl-Test-Harness-3.17-141.el6_7.1.x86_64                                                 34/41 
  インストールしています  : perl-Test-Simple-0.92-141.el6_7.1.x86_64                                                  35/41 
  インストールしています  : at-3.1.10-48.el6.x86_64                                                                   36/41 
  インストールしています  : time-1.7-38.el6.x86_64                                                                    37/41 
  インストールしています  : redhat-lsb-core-4.0-7.el6.centos.x86_64                                                   38/41 
  インストールしています  : tomcat7-7.0.54-2.jpp6.noarch                                                              39/41 
  インストールしています  : tomcat7-admin-webapps-7.0.54-2.jpp6.noarch                                                40/41 
  インストールしています  : tomcat7-webapps-7.0.54-2.jpp6.noarch                                                      41/41 
  Verifying               : time-1.7-38.el6.x86_64                                                                     1/41 
  Verifying               : at-3.1.10-48.el6.x86_64                                                                    2/41 
  Verifying               : tomcat7-7.0.54-2.jpp6.noarch                                                               3/41 
  Verifying               : redhat-lsb-core-4.0-7.el6.centos.x86_64                                                    4/41 
  Verifying               : gdbm-devel-1.8.0-38.el6.x86_64                                                             5/41 
  Verifying               : 4:perl-devel-5.10.1-141.el6_7.1.x86_64                                                     6/41 
  Verifying               : pax-3.4-10.1.el6.x86_64                                                                    7/41 
  Verifying               : tomcat7-jsp-2.2-api-7.0.54-2.jpp6.noarch                                                   8/41 
  Verifying               : tomcat7-servlet-3.0-api-7.0.54-2.jpp6.noarch                                               9/41 
  Verifying               : libart_lgpl-2.3.20-5.1.el6.x86_64                                                         10/41 
  Verifying               : xz-4.999.9-0.5.beta.20091007git.el6.x86_64                                                11/41 
  Verifying               : sinjdoc-0.5-9.1.el6.x86_64                                                                12/41 
  Verifying               : tomcat7-admin-webapps-7.0.54-2.jpp6.noarch                                                13/41 
  Verifying               : tomcat6-servlet-2.5-api-6.0.33-2.jpp6.noarch                                              14/41 
  Verifying               : apache-commons-pool-tomcat5-1.5.7-1.jpp6.noarch                                           15/41 
  Verifying               : 1:ecj3-3.7-1.jpp6.noarch                                                                  16/41 
  Verifying               : man-1.6f-32.el6.x86_64                                                                    17/41 
  Verifying               : perl-Test-Simple-0.92-141.el6_7.1.x86_64                                                  18/41 
  Verifying               : apache-commons-dbcp-tomcat5-1.3.0-0.r830852.4.jpp6.noarch                                 19/41 
  Verifying               : libgcj-4.4.7-16.el6.x86_64                                                                20/41 
  Verifying               : zip-3.0-1.el6_7.1.x86_64                                                                  21/41 
  Verifying               : java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64                                                    22/41 
  Verifying               : tomcat7-el-2.2-api-7.0.54-2.jpp6.noarch                                                   23/41 
  Verifying               : tomcat6-jsp-2.1-api-6.0.33-2.jpp6.noarch                                                  24/41 
  Verifying               : xz-lzma-compat-4.999.9-0.5.beta.20091007git.el6.x86_64                                    25/41 
  Verifying               : perl-ExtUtils-MakeMaker-6.55-141.el6_7.1.x86_64                                           26/41 
  Verifying               : 2:java-cup-0.11-0.a.3.jpp6.noarch                                                         27/41 
  Verifying               : apache-commons-logging-1.1.3-2.jpp6.noarch                                                28/41 
  Verifying               : apache-commons-collections-tomcat5-3.2.1-6.jpp6.noarch                                    29/41 
  Verifying               : tomcat7-lib-7.0.54-2.jpp6.noarch                                                          30/41 
  Verifying               : perl-CGI-3.51-141.el6_7.1.x86_64                                                          31/41 
  Verifying               : gettext-0.17-18.el6.x86_64                                                                32/41 
  Verifying               : apache-taglibs-standard-1.1.2-8.jpp6.noarch                                               33/41 
  Verifying               : 1:apache-commons-daemon-1.0.15-1.jpp6.noarch                                              34/41 
  Verifying               : 1:perl-ExtUtils-ParseXS-2.2003.0-141.el6_7.1.x86_64                                       35/41 
  Verifying               : xalan-j2-2.7.1-8.jbossorg_1.jpp6.noarch                                                   36/41 
  Verifying               : patch-2.6-6.el6.x86_64                                                                    37/41 
  Verifying               : bc-1.06.95-1.el6.x86_64                                                                   38/41 
  Verifying               : cvs-1.11.23-16.el6.x86_64                                                                 39/41 
  Verifying               : tomcat7-webapps-7.0.54-2.jpp6.noarch                                                      40/41 
  Verifying               : perl-Test-Harness-3.17-141.el6_7.1.x86_64                                                 41/41 

インストール:
  tomcat7-admin-webapps.noarch 0:7.0.54-2.jpp6                    tomcat7-webapps.noarch 0:7.0.54-2.jpp6                   

依存性関連をインストールしました:
  apache-commons-collections-tomcat5.noarch 0:3.2.1-6.jpp6       apache-commons-daemon.noarch 1:1.0.15-1.jpp6               
  apache-commons-dbcp-tomcat5.noarch 0:1.3.0-0.r830852.4.jpp6    apache-commons-logging.noarch 0:1.1.3-2.jpp6               
  apache-commons-pool-tomcat5.noarch 0:1.5.7-1.jpp6              apache-taglibs-standard.noarch 0:1.1.2-8.jpp6              
  at.x86_64 0:3.1.10-48.el6                                      bc.x86_64 0:1.06.95-1.el6                                  
  cvs.x86_64 0:1.11.23-16.el6                                    ecj3.noarch 1:3.7-1.jpp6                                   
  gdbm-devel.x86_64 0:1.8.0-38.el6                               gettext.x86_64 0:0.17-18.el6                               
  java-1.5.0-gcj.x86_64 0:1.5.0.0-29.1.el6                       java-cup.noarch 2:0.11-0.a.3.jpp6                          
  libart_lgpl.x86_64 0:2.3.20-5.1.el6                            libgcj.x86_64 0:4.4.7-16.el6                               
  man.x86_64 0:1.6f-32.el6                                       patch.x86_64 0:2.6-6.el6                                   
  pax.x86_64 0:3.4-10.1.el6                                      perl-CGI.x86_64 0:3.51-141.el6_7.1                         
  perl-ExtUtils-MakeMaker.x86_64 0:6.55-141.el6_7.1              perl-ExtUtils-ParseXS.x86_64 1:2.2003.0-141.el6_7.1        
  perl-Test-Harness.x86_64 0:3.17-141.el6_7.1                    perl-Test-Simple.x86_64 0:0.92-141.el6_7.1                 
  perl-devel.x86_64 4:5.10.1-141.el6_7.1                         redhat-lsb-core.x86_64 0:4.0-7.el6.centos                  
  sinjdoc.x86_64 0:0.5-9.1.el6                                   time.x86_64 0:1.7-38.el6                                   
  tomcat6-jsp-2.1-api.noarch 0:6.0.33-2.jpp6                     tomcat6-servlet-2.5-api.noarch 0:6.0.33-2.jpp6             
  tomcat7.noarch 0:7.0.54-2.jpp6                                 tomcat7-el-2.2-api.noarch 0:7.0.54-2.jpp6                  
  tomcat7-jsp-2.2-api.noarch 0:7.0.54-2.jpp6                     tomcat7-lib.noarch 0:7.0.54-2.jpp6                         
  tomcat7-servlet-3.0-api.noarch 0:7.0.54-2.jpp6                 xalan-j2.noarch 0:2.7.1-8.jbossorg_1.jpp6                  
  xz.x86_64 0:4.999.9-0.5.beta.20091007git.el6                   xz-lzma-compat.x86_64 0:4.999.9-0.5.beta.20091007git.el6   
  zip.x86_64 0:3.0-1.el6_7.1                                    

完了しました!

今度はうまくインストールされました。

Apacheとの連携

↓ちなみにApacheのインストールついては別記事上げてます

【CentOS6】Apache2.2インストール&設定 - 忘備録

モジュールの追加

/etc/httpd/conf/httpd.conf

# 無効(コメントアウト)になっていないことを確認
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

プロキシ設定

まずはApache側。

httpd.confに書いても良いみたいですが、自分はバーチャルホストを設定しているため、そちらの設定ファイルに記述しました。

/etc/httpd/conf.d/vhosts/example.conf

<VirtualHost *:80>
  ServerName example.co.jp
#〜〜〜〜〜〜(中略)〜〜〜〜〜〜〜〜
  # サーバのルートに対する接続を、8009ポートに転送するという設定
  <Location />
     ProxyPass ajp://localhost:8009/
  </Location>
</VirtualHost>

続いてTomcat側。

/etc/tomcat7/server.xml

    <!-- 無効(コメントアウト)になっていないこと確認 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Tomcatの起動と自動起動設定

# 起動
$ service tomcat7 start
Starting tomcat7:                                          [  OK  ]
# 自動起動設定の確認
$ chkconfig | grep tomcat7
tomcat7         0:off  1:off  2:off  3:off  4:off  5:off  6:off
# 自動起動をON
$ chkconfig tomcat7 on
# 確認
$ chkconfig | grep tomcat7
tomcat7         0:off  1:off  2:on   3:on   4:on   5:on   6:off

本来ここまでくれば、tomcatにアクセスできるのですが、あることをしないと今回の手順ではコンパイルエラーで動きません。

/var/log/tomcat7/catalina.out

3 03, 2016 11:37:27 午後 org.apache.jasper.compiler.JDTCompiler$1 findType
重大: Compilation error
org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException
    at org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.<init>(Unknown Source)
    at org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:231)
    at org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:187)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeFromTypeSignature(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeFromVariantTypeSignature(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeArgumentsFromSignature(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeFromTypeSignature(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.createMethod(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.createMethods(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.cachePartsFrom(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createBinaryTypeFrom(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createBinaryTypeFrom(Unknown Source)
    at org.eclipse.jdt.internal.compiler.Compiler.accept(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.getPackage(Unknown Source)
    at org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference.internalResolveLeafType(Unknown Source)
    at org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference.internalResolveType(Unknown Source)
    at org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference.resolveType(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypeFor(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.fields(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.faultInTypesForFieldsAndMethods(Unknown Source)
    at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes(Unknown Source)
    at org.eclipse.jdt.internal.compiler.Compiler.process(Unknown Source)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Unknown Source)
    at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:466)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:213)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:193)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

調べてるうちに↓の記事に行き着き

CentOS6にJDK8・Tomcat7の環境を構築した時に詰まった話 | hacknote

いろいろ調べてみたところ、 Tomcat 7.0.54ではecjのバージョンを4系にする必要があるようでした。

出ているエラーの内容は違うようでしたが、原因は同じみたいで上記サイトを参考に対応したら動きました。

対応例

$ cd  /usr/share/java/tomcat7
$  ls -la | grep ecj
lrwxrwxrwx. 1 root root      24  33 21:45 2016 [ecj3].jar -> /usr/share/java/ecj3.jar
-rw-r--r--. 1 root root 1155139  730 16:59 2014 ecj3-7.0.54.jar
lrwxrwxrwx. 1 root root      15  33 21:45 2016 ecj3.jar -> ecj3-7.0.54.jar
# 消すのは怖いので古いecjを退避
$ mkdir bk
$ mv [ecj3].jar bk
$ mv ecj3-7.0.54.jar bk
$ mv ecj3.jar  bk
# ecj4.4を入手
$ wget http://central.maven.org/maven2/org/eclipse/jdt/core/compiler/ecj/4.4/ecj-4.4.jar
--2016-03-03 23:27:15--  http://central.maven.org/maven2/org/eclipse/jdt/core/compiler/ecj/4.4/ecj-4.4.jar
central.maven.org をDNSに問いあわせています... 23.235.47.209
central.maven.org|23.235.47.209|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 2298872 (2.2M) [application/java-archive]
`ecj-4.4.jar' に保存中

100%[==================================================================================>] 2,298,872    208K/s 時間 9.3s    

2016-03-03 23:27:25 (242 KB/s) - `ecj-4.4.jar' へ保存完了 [2298872/2298872]

tomcatを再起動してサーバにアクセスしてみます。

f:id:mktktmr:20160309062427p:plain

やっとこうまくいきました。

たぶん無理くりtomcat7入れたせいで依存関係が正しく解決できてないみたいです。

起動スクリプトのバージョン確認もうまくいきませんでした。

$ service tomcat7 version
Error: Could not find or load main class org.apache.catalina.util.ServerInfo

とりあえず動いたので、これについては後日調査します。

Tomcatマネージャの設定

Tomcatの管理ページへの認証設定を記述。

/etc/tomcat7/tomcat-users.xml

<tomcat-users>
  <role rolename="manager-gui"/>
  <user username="tomcat" password="password" roles="manager-gui"/>
</tomcat-users>

http://domain/manager/ にアクセスしてみます。

f:id:mktktmr:20160309062044p:plain

tomcat-users.xmlに設定したusernameとpasswordで認証をします。

f:id:mktktmr:20160309061503p:plain

管理ページにアクセスできます。

管理ページではGUIベースでデプロイやステータスのチェックなどができます。

ロールについて

Tomcat7管理ページのロールには以下のものがあります。

ロール 概要
manager-gui allows access to the HTML GUI and the status pages
manager-status allows access to the status pages only
manager-script allows access to the text interface and the status pages
manager-jmx allows access to the JMX proxy and the status pages
admin-gui allows access to the HTML GUI
admin-script allows access to the text interface

参考

ベリーキュート Blog » Blog Archive » Tomcat 7 インストールと設定

Apache側の設定 - Tomcatとの連携(mod_proxy_ajp) - Apache入門

CentOS6にJDK8・Tomcat7の環境を構築した時に詰まった話 | hacknote

:: JPackage Project | Home ::

Apache側の設定 - Tomcatとの連携(mod_proxy_ajp) - Apache入門

インフラエンジニアのメモ : Tomcat7のManager(管理画面)にアクセスできない