Quantcast
Channel: 俺的備忘録 〜なんかいろいろ〜
Viewing all 1028 articles
Browse latest View live

CentOS 7にOSSのログ分析ツール『Graylog』をインストールする

$
0
0

以前、Syslogサーバとして利用できるログ分析ツール『Graylog』について仮想アプライアンスとして触ってみたのだけど、今回はこれをCentOS 7にインストールしてみる。
仮想アプライアンスと違い、ある程度カスタマイズできるので仕事で導入するときはこっちのほうがいいかな?とりあえず、やっていこう。

1.前提パッケージの導入

1-1.OracleJDKのインストール

まずは、前に書いたようにこちらからOracle JDKのrpmパッケージのURLを確認して、以下のようにコマンドを実行しOracleJDKをインストールする。

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-x64.rpm
rpm -ihv jdk-8u101-linux-x64.rpm
[root@BS-PUB-CENT7-01 ~]# java -version
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

 

1-2.Elasticsearchのインストール

次に、Elasticsearchのインストールを行う。
以下のコマンドでリポジトリのインストール、設定を行う。

rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
cat << EOF > /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-2.x]
name=Elasticsearch repository for 2.x packages
baseurl=https://packages.elastic.co/elasticsearch/2.x/centos
gpgcheck=1
gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
EOF

 

で、以下のコマンドでElasticsearchのインストールを行う。

yum -y install elasticsearch

 

サービスの起動回りについて設定を行う。

systemctl daemon-reload
systemctl enable elasticsearch

 

Elasticsearchの設定ファイルを編集し、サービス再起動を行う。

cp /etc/elasticsearch/elasticsearch.yml{,.bk}
cat <<EOF >> /etc/elasticsearch/elasticsearch.yml
cluster.name: graylog
script.inline: false
script.indexed: false
script.file: false
EOF
service elasticsearch restart

 

以下のコマンドを実行して、ちゃんと設定できていることを確認する。
無事設定できていれば、赤字になっているとこは同じステータスになってるはずだ。

curl -X GET http://localhost:9200
curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
[root@BS-PUB-CENT7-01 ~]# curl -X GET http://localhost:9200
{
  "name" : "Spymaster",
  "cluster_name" : "graylog",
  "version" : {
    "number" : "2.3.5",
    "build_hash" : "90f439ff60a3c0f497f91663701e64ccd01edbb4",
    "build_timestamp" : "2016-07-27T10:36:52Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.0"
  },
  "tagline" : "You Know, for Search"
}
[root@BS-PUB-CENT7-01 ~]# curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
{
  "cluster_name" : "graylog",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 0,
  "active_shards" : 0,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}

 

1-3.MongoDBのインストール

次に、MongoDB 3.2をインストールする。
以下のコマンドでリポジトリ設定、パッケージインストールを実施する。

cat <<"EOF" > /etc/yum.repos.d/mongodb-org-3.2.repo
[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc
EOF
yum install -y mongodb-org

 

サービスの起動設定を行う。

systemctl start mongod
systemctl enable mongod

2.Graylogのインストール

前提となるパッケージをインストールできたら、Graylogのインストールを行う。
まず、以下のコマンドでリポジトリを導入してパッケージをインストールする。

rpm -Uvh https://packages.graylog2.org/repo/packages/graylog-2.0-repository_latest.rpm
yum -y install graylog-server

 

次に、Graylog自体の設定ファイルを編集する。
(以下のコマンドではEpelとpwgenをインストールしている)

yum -y install epel-release
yum -y install pwgen
sed -e "/^password_secret/c password_secret = $(pwgen -N 1 -s 96)" \
    -e "/^root_password_sha2 /c root_password_sha2 = $(echo -n P@ssw0rd | sha256sum | awk '{print $1}')" \
    -e "/^#root_email/c root_email = root@localhost" \
    -e "/^root_timezone/c root_timezone = Japan" \
    -e "/elasticsearch_discovery_zen_ping_unicast_hosts/c elasticsearch_discovery_zen_ping_unicast_hosts = $(hostname -I | xargs -n 1 | xargs -I{} echo {}:9300 | tr '\n' ',' | sed 's/,$//g')" \
    -e "/elasticsearch_replicas/c elasticsearch_replicas = 1" \
    -e "/^rest_listen_uri/c rest_listen_uri = http://IPアドレス:12900/" \
    -e "/#web_listen_uri/c web_listen_uri = http://IPアドレス:9000/" \
    -i.bk /etc/graylog/server/server.conf

 

設定ファイルの編集ができたら、以下のコマンドでサービスの起動設定を行う。

systemctl daemon-reload
systemctl restart graylog-server
systemctl enable graylog-server
systemctl enable elasticsearch

 

最後に、Firewalldのポート開放を行う。

firewall-cmd --permanent --zone=public --add-port=9000/tcp
firewall-cmd --permanent --zone=public --add-port=12900/tcp
firewall-cmd --permanent --zone=public --add-port=1514/tcp
firewall-cmd --reload

 

3.WebブラウザからGraylogにアクセスする

さて、それではWebブラウザからGraylogにアクセスしよう。
「http://IPアドレス:9000」にアクセスする。IDは「admin」、パスワードはroot_password_sha2で指定したものでログインできる。

20160830_083249000000

20160830_083712000000

 

無事、ログインすることができた。
あとは、以前書いた内容のようにSyslogの設定もろもろを行うだけだ。

なお、今回は一般ユーザで構築しているため、1024番ポート以下のポートを開けることができない。
そのため、rsyslogのデフォルトポートである514ではなく、10514とかその辺を指定して開けてやるといいだろう。

 

サーバ/インフラエンジニア養成読本 ログ収集〜可視化編 [現場主導のデータ分析環境を構築!] Software Design plus サーバ/インフラエンジニア養成読本 ログ収集〜可視化編 [現場主導のデータ分析環境を構築!] Software Design plus

Ubuntu Server 16.04 LTSにOSSのログ分析ツール『Graylog』をインストールする

$
0
0

前回、CentOS 7にGraylogをインストールしたので、今回はUbuntu Server 16.04 LTSにインストールを行う。

1.前提パッケージの導入

1-1.Oracle JDKのインストール

まずは、以下のコマンドでOracle JDKのインストールを行う。

sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
sudo apt-get -y install oracle-java8-installer
blacknon@BS-PUB-UBUNTU-01:~$ java -version
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

 

1-2.Elasticsearchのインストール

次に、Elasticsearchのインストールを行う。
以下のコマンドでリポジトリのインストール、設定を行う。

sudo wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb http://packages.elastic.co/elasticsearch/1.7/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch.list
sudo apt-get update
sudo apt-get install elasticsearch
sudo update-rc.d elasticsearch defaults

 

インストール後、設定ファイルの編集を行いサービス再起動を実施する。

sudo cp /etc/elasticsearch/elasticsearch.yml{,.bk}
suod sh -c 'cat <<EOF >> /etc/elasticsearch/elasticsearch.yml
cluster.name: graylog
script.disable_dynamic: true
EOF'
sudo service elasticsearch restart

 

最後に、以下のコマンドを実行し正常に返ってくること確認する。

curl -X GET http://localhost:9200
curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
blacknon@BS-PUB-UBUNTU-01:~$ curl -X GET http://localhost:9200
{
  "status" : 200,
  "name" : "Gauntlet",
  "cluster_name" : "graylog",
  "version" : {
    "number" : "1.7.5",
    "build_hash" : "00f95f4ffca6de89d68b7ccaf80d148f1f70e4d4",
    "build_timestamp" : "2016-02-02T09:55:30Z",
    "build_snapshot" : false,
    "lucene_version" : "4.10.4"
  },
  "tagline" : "You Know, for Search"
}
blacknon@BS-PUB-UBUNTU-01:~$ curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
{
  "cluster_name" : "graylog",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 0,
  "active_shards" : 0,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0
}

 

1-3.MongoDBのインストール

次に、MongoDBをインストールする。
以下のコマンドでリポジトリの追加、インストールを行う。

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
sudo apt-get install mongodb-org

 

サービスの起動設定などを行う。

sudo systemctl start mongod
sudo systemctl enable mongod

2.Graylogのインストール

前提となるパッケージの導入ができたら、Graylogのインストールを行う。
以下のコマンドで、リポジトリの導入とパッケージのインストールを行う。

wget https://packages.graylog2.org/repo/packages/graylog-2.0-repository_latest.deb
sudo dpkg -i graylog-2.0-repository_latest.deb
sudo apt-get install -y apt-transport-https
sudo apt-get update
sudo apt-get install -y graylog-server

 

次に、Graylogの設定ファイルを編集する。

sudo apt-get install pwgen
sudo \
sed -e "/^password_secret/c password_secret = $(pwgen -N 1 -s 96)" \
    -e "/^root_password_sha2 /c root_password_sha2 = $(echo -n P@ssw0rd | sha256sum | awk '{print $1}')" \
    -e "/^#root_email/c root_email = メールアドレス" \
    -e "/^root_timezone/c root_timezone = Japan" \
    -e "/elasticsearch_discovery_zen_ping_unicast_hosts/c elasticsearch_discovery_zen_ping_unicast_hosts = $(hostname -I | xargs -n 1 | xargs -I{} echo {}:9300 | tr '\n' ',' | sed 's/,$//g')" \
    -e "/elasticsearch_replicas/c elasticsearch_replicas = 1" \
    -e "/^rest_listen_uri/c rest_listen_uri = http://IPアドレス:12900/" \
    -e "/#web_listen_uri/c web_listen_uri = http://IPアドレス:9000/" \
    -i.bk /etc/graylog/server/server.conf

 

設定ファイルを編集したら、以下のコマンドでサービスの起動設定を行う。

sudo systemctl daemon-reload
sudo systemctl restart graylog-server
sudo systemctl enable graylog-server
sudo systemctl enable elasticsearch

 

3.WebブラウザからGraylogにアクセスする

サービス起動後、Webブラウザから「http://IPアドレス:9000」へアクセスする。

20160831_070448000000

20160831_070501000000

 

無事、ログインできた。
Syslogの設定については、以前仮想アプライアンスを利用した際に記述したのでそちらを参照してもらいたい。

なお、その際に注意したいのがポート番号。仮想アプライアンスと違って一般ユーザを作って動かしているため、1024番以下のポートを開くことができない。
(setcapで「setcap ‘cap_net_bind_service=+ep’ PATH」をしてもダメだった)
そのため、514以外の適当なポート(10514とか)を開いてやるといいだろう。

rsyslog 実践ログ管理入門 rsyslog 実践ログ管理入門

GraylogでWebインターフェイスのSSLを有効にする(オレオレ証明書)

$
0
0

Graylogでは、デフォルトだとWebインターフェイスがhttpsになっておらず、ちょっとよろしくない。
で、一応設定としてSSLの有効化は行えるようなので、(手順と違いオレオレ証明書にはなるが)設定を行ってみることにする。

まず、以下のコマンドでSSLの証明書、鍵を作成する。

sudo openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /etc/ssl/certs/graylog-proxy.key -out /etc/ssl/certs/graylog-proxy.crt

 

次に、Graylogの設定ファイル(/etc/graylog/server/server.conf)において、以下の項目を変更する。

rest_listen_uri = https://IPアドレス:12900/
rest_enable_tls = true
rest_tls_cert_file = /etc/ssl/certs/graylog-proxy.crt
rest_tls_key_file = /etc/ssl/certs/graylog-proxy.key
web_listen_uri = https://IPアドレス:9000/
web_enable_tls = true
web_tls_cert_file = /etc/ssl/certs/graylog-proxy.crt
web_tls_key_file = /etc/ssl/certs/graylog-proxy.key

あとは、Graylogのサービス再起動を行ってブラウザからアクセスするだけだ。

sudo systemctl restart graylog-server

20160901_195050000000

20160901_195055000000

 

無事、SSLを有効にできた。
とりあえず、セキュリティが気になるのでこの辺は設定しておいたほうがいいかもしれない。

サーバ/インフラエンジニア養成読本 ログ収集〜可視化編 [現場主導のデータ分析環境を構築!] Software Design plus サーバ/インフラエンジニア養成読本 ログ収集〜可視化編 [現場主導のデータ分析環境を構築!] Software Design plus

GraylogからSlackにアラートを通知させる

$
0
0

Graylogでログを監視して、Slackにアラートを通知させるにはこちらのSlackへの通知プラグインを導入すればよい。
インストール方法は簡単。こちらからパッケージかjarファイルをダウンロードしてきて、所定の場所(graylog.confに「plugin_dir」で指定されているディレクトリ)に配置してやればよい。

とりあえず、今回はCentOS 7なので、rpmパッケージをインストールしてやる。

rpm -ihv https://github.com/Graylog2/graylog-plugin-slack/releases/download/2.2.1/graylog-plugin-slack-2.2.1-1.noarch.rpm

 

インストール後、Graylogのサービス再起動を実施する。

systemctl restart graylog-server

 

サービス再起動が完了したら、こちらからSlackのWebHookの設定を行っておく。
これについては詳細は省く。

 

1.Streamの新規作成

WebHookの設定(投稿用URLや投稿チャンネル、表示するユーザ名など)を設定したら、Graylogの設定画面を開き、「Streams」から「Create Stream」をクリックする。
Title、Descriptionの入力を行い、新規Streamを作成する。

20160901_221832000000

 

2.ルール作成

Streamの作成をしたら、アラートのルールを定める。
「Edit rules」をクリックし、まずどのInputから来るログを対象とするか選択する。

20160901_222946000000

20160901_223027000000

 

次に、「Add stream rule」をクリックし、対象となるフィールドやマッチさせるタイプ、キーワードを指定する。
(ここでは、テストのためにとりあえずValueを「error」にしている。マッチしない場合にアラートを出させることもできるようだけど、ちょっと面倒なのでやらない。)

20160901_223801000000

 

ルールが追加できたら、「I’m done」で登録する。

3.アウトプットの設定

Streamの「Manage Outputs」をクリックし、次の画面で「Slack Output」を選択して「Launch new output」をクリックする。

20160901_222027000000

20160901_222252000000

 

OutputのタイトルやWebHookの投稿URL、チャンネルなどを入力してSaveする。

20160901_222543000000

 

4.Slackにアラートを投げる

一通り設定が終わったら、Streamsのトップ画面から対象のstreamを起動させる。

20160901_224507000000

 

streamが起動したら、loggerなどで対象のキーワードを持つログをはかせてみよう。

[root@BS-PUB-CENT7-02 ~]# logger error

20160901_224802000000_1

 

確かに、Slackにちゃんとアラートが上がってきた。
今回は簡単な設定しかしていないが、いろいろと細かく設定もできるみたいなので、実運用でも問題なく使えそうだ。

Slack入門 [ChatOpsによるチーム開発の効率化] Slack入門 [ChatOpsによるチーム開発の効率化]

CentOS 7でyumからSecurityUpdateを行えるようにする

$
0
0

CentOSではyumでセキュリティ関連のパッケージのみ導入する場合は「yum-plugin-security」というパッケージを利用することで、セキュリティ関連のアップデートをかけることができる…
のだけど、CentOSではこのパッケージを利用しても「No packages needed for security」と出力され、セキュリティアップデートは実行されない。同じRHELベースのAmazonLinuxなどでは実行されるのに…

[root@BS-PUB-CENT7-01 ~]# yum --security update
読み込んだプラグイン:fastestmirror
base                                                                    | 3.6 kB  00:00:00
elasticsearch-2.x                                                       | 2.9 kB  00:00:00
epel/x86_64/metalink                                                    | 6.3 kB  00:00:00
extras                                                                  | 3.4 kB  00:00:00
graylog                                                                 | 2.9 kB  00:00:00
mongodb-org-3.2                                                         | 2.5 kB  00:00:00
updates                                                                 | 3.4 kB  00:00:00
Loading mirror speeds from cached hostfile
 * base: download.nus.edu.sg
 * epel: mirror.rise.ph
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
 --> kernel-tools-3.10.0-327.28.3.el7.x86_64 from updates removed (updateinfo)
 --> kernel-3.10.0-327.28.3.el7.x86_64 from updates removed (updateinfo)
 --> python-perf-3.10.0-327.28.2.el7.x86_64 from @updates removed (updateinfo)
 --> kernel-tools-libs-3.10.0-327.28.2.el7.x86_64 from @updates removed (updateinfo)
 --> python-perf-3.10.0-327.28.3.el7.x86_64 from updates removed (updateinfo)
 --> elasticsearch-2.4.0-1.noarch from elasticsearch-2.x removed (updateinfo)
 --> kernel-tools-3.10.0-327.28.2.el7.x86_64 from @updates removed (updateinfo)
 --> kernel-tools-libs-3.10.0-327.28.3.el7.x86_64 from updates removed (updateinfo)
 --> elasticsearch-2.3.5-1.noarch from @elasticsearch-2.x removed (updateinfo)
No packages needed for security; 5 packages available
依存性の解決をしています

 

これは、CentOSのリポジトリではセキュリティアップデートの情報が提供されていないことが原因らしい。
つまり、その情報を提供しているリポジトリを別途導入してやることで利用できるようになるということだ。

で、CentOS用のセキュリティ情報を提供しているCEFS projectというものがあるので、このプロジェクトが提供している情報をもとにローカルリポジトリを導入してやることで、yumでセキュリティアップデートが行えるようになる。こちらに有志が作ったリポジトリ導入スクリプトがあるので、今回はこれをCentOS 7に導入してやる。

まず、以下のコマンドで実行させるスクリプトをダウンロードする。
(CentOS 7ではyum-plugin-securityはyumに統合されているので不要だが、念のため記述)

yum install createrepo yum-plugin-security bzip2
mkdir -p /security && cd /security
wget https://raw.githubusercontent.com/vmfarms/generate_updateinfo/master/generate_updateinfo.py

 

ダウンロードしたスクリプトファイルで、リポジトリの保存先、バージョン(デフォルトがCentOS6なので、CentOS7への書き換え)を行う。

sed -e '/^BUILD_PREFIX = /s/"\/tmp"/"\/security"/g' \
    -e '/^RELEASES = /s/6/7/g' \
    -i.bk /security/generate_updateinfo.py

スクリプト編集後、以下のコマンドでリポジトリを作成、登録する。

createrepo /security
python generate_updateinfo.py <(curl -s http://cefs.steve-meier.de/errata.latest.xml.bz2 | bzip2 -dc)
modifyrepo /security/updateinfo-7/updateinfo.xml /security/repodata/

 

最後に、参照するリポジトリとして登録を行う。

cp /etc/yum.repos.d/CentOS-Base.repo{,.bk}
cat << "EOF" >> /etc/yum.repos.d/CentOS-Base.repo
[security]
name=CentOS-$releasever - Security
baseurl=file:///security
EOF

 

これで、yumからセキュリティアップデートが行えるようになった。

yum --security update
[root@BS-PUB-CENT7-01 security]# yum --security update
読み込んだプラグイン:fastestmirror
base                                                                    | 3.6 kB  00:00:00
elasticsearch-2.x                                                       | 2.9 kB  00:00:00
epel/x86_64/metalink                                                    | 6.3 kB  00:00:00
extras                                                                  | 3.4 kB  00:00:00
graylog                                                                 | 2.9 kB  00:00:00
mongodb-org-3.2                                                         | 2.5 kB  00:00:00
security                                                                | 3.3 kB  00:00:00
updates                                                                 | 3.4 kB  00:00:00
(1/2): security/updateinfo                                              |  33 kB  00:00:00
(2/2): security/primary_db                                              | 1.1 kB  00:00:00
Loading mirror speeds from cached hostfile
 * base: mirror.nus.edu.sg
 * epel: kartolo.sby.datautama.net.id
 * extras: mirror.nus.edu.sg
 * updates: mirror.nus.edu.sg
 --> elasticsearch-2.4.0-1.noarch from elasticsearch-2.x removed (updateinfo)
 --> elasticsearch-2.3.5-1.noarch from @elasticsearch-2.x removed (updateinfo)
4 package(s) needed (+0 related) for security, out of 5 available
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ kernel.x86_64 0:3.10.0-327.28.3.el7 を インストール
---> パッケージ kernel-tools.x86_64 0:3.10.0-327.28.2.el7 を 更新
---> パッケージ kernel-tools.x86_64 0:3.10.0-327.28.3.el7 を アップデート
---> パッケージ kernel-tools-libs.x86_64 0:3.10.0-327.28.2.el7 を 更新
---> パッケージ kernel-tools-libs.x86_64 0:3.10.0-327.28.3.el7 を アップデート
---> パッケージ python-perf.x86_64 0:3.10.0-327.28.2.el7 を 更新
---> パッケージ python-perf.x86_64 0:3.10.0-327.28.3.el7 を アップデート
--> 依存性解決を終了しました。

依存性を解決しました

===============================================================================================
 Package                   アーキテクチャー
                                          バージョン                     リポジトリー     容量
===============================================================================================
インストール中:
 kernel                    x86_64         3.10.0-327.28.3.el7            updates          33 M
更新します:
 kernel-tools              x86_64         3.10.0-327.28.3.el7            updates         2.4 M
 kernel-tools-libs         x86_64         3.10.0-327.28.3.el7            updates         2.3 M
 python-perf               x86_64         3.10.0-327.28.3.el7            updates         2.4 M

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

総ダウンロード容量: 40 M
Is this ok [y/d/N]: y
Downloading packages:
updates/7/x86_64/prestodelta                                            | 698 kB  00:00:03
(1/4): python-perf-3.10.0-327.28.3.el7.x86_64.rpm                       | 2.4 MB  00:00:04
(2/4): kernel-tools-libs-3.10.0-327.28.3.el7.x86_64.rpm                 | 2.3 MB  00:00:04
(3/4): kernel-3.10.0-327.28.3.el7.x86_64.rpm                            |  33 MB  00:00:07
(4/4): kernel-tools-3.10.0-327.28.3.el7.x86_64.rpm                      | 2.4 MB  00:00:06
-----------------------------------------------------------------------------------------------
合計                                                           5.5 MB/s |  40 MB  00:00:07
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  更新します              : kernel-tools-libs-3.10.0-327.28.3.el7.x86_64                   1/7
  更新します              : kernel-tools-3.10.0-327.28.3.el7.x86_64                        2/7
  更新します              : python-perf-3.10.0-327.28.3.el7.x86_64                         3/7
  インストール中          : kernel-3.10.0-327.28.3.el7.x86_64                              4/7
  整理中                  : kernel-tools-3.10.0-327.28.2.el7.x86_64                        5/7
  整理中                  : kernel-tools-libs-3.10.0-327.28.2.el7.x86_64                   6/7
  整理中                  : python-perf-3.10.0-327.28.2.el7.x86_64                         7/7
  検証中                  : kernel-tools-3.10.0-327.28.3.el7.x86_64                        1/7
  検証中                  : kernel-3.10.0-327.28.3.el7.x86_64                              2/7
  検証中                  : python-perf-3.10.0-327.28.3.el7.x86_64                         3/7
  検証中                  : kernel-tools-libs-3.10.0-327.28.3.el7.x86_64                   4/7
  検証中                  : python-perf-3.10.0-327.28.2.el7.x86_64                         5/7
  検証中                  : kernel-tools-libs-3.10.0-327.28.2.el7.x86_64                   6/7
  検証中                  : kernel-tools-3.10.0-327.28.2.el7.x86_64                        7/7

インストール:
  kernel.x86_64 0:3.10.0-327.28.3.el7

更新:
  kernel-tools.x86_64 0:3.10.0-327.28.3.el7   kernel-tools-libs.x86_64 0:3.10.0-327.28.3.el7
  python-perf.x86_64 0:3.10.0-327.28.3.el7

完了しました!
新しいLinuxの教科書 新しいLinuxの教科書

CentOS 7にepel、remiのリポジトリを追加する

$
0
0

CentOSでちょっと新しめのパッケージを入れる際にかなりの確率でお世話になるepelとremiのリポジトリ。
これらのリポジトリを追加する場合は、以下のコマンドを実行すればよい。

epel

yum install -y epel-release
sed -i.bk '/[epel]/,/^enabled/s/enabled=1/enabled=0/' /etc/yum.repos.d/epel.repo # yum実行時に「enablerepo=epel」を付けないと有効にさせない

remi

rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

 

実践!  CentOS 7 サーバー徹底構築 実践! CentOS 7 サーバー徹底構築

UbuntuServerでセキュリティアップデートのみ行わせる(手動・自動)

$
0
0

Ubuntu Serverでセキュリティアップデートのみを行わせるには、yumと違ってapt-get(apt)だけだとできないようだ。
じゃあどうすればいいのかというと、「unattended-upgrades」というパッケージを利用するといいようだ。このパッケージ、手動だけではなく自動でのセキュリティアップデートを行わせることもできるようだ。今回は、UbuntuServer 16.04でこの確認を行う。

1.unattended-upgradesのインストール・設定

まずは、以下のコマンドでunattended-upgradesのインストールを行う。
(Ubuntu Server 16.04ではバンドルされてると思うが、念のため)

sudo apt-get install unattended-upgrades

 

次に設定を確認し、最低限やっておきたい設定だけしておく。
以下のコマンドを実行して、現在の設定状態を確認する(とりあえず、「Unattended-Upgrade::Allowed-Origins」で「”${distro_id}:${distro_codename}-security”;」だけが有効になってればよい)。

cat /etc/apt/apt.conf.d/50unattended-upgrades
blacknon@BS-PUB-UBUNTU-01:~$ cat /etc/apt/apt.conf.d/50unattended-upgrades
// Automatically upgrade packages from these (origin:archive) pairs
Unattended-Upgrade::Allowed-Origins {
        "${distro_id}:${distro_codename}-security";
//      "${distro_id}:${distro_codename}-updates";
//      "${distro_id}:${distro_codename}-proposed";
//      "${distro_id}:${distro_codename}-backports";
};

// List of packages to not update (regexp are supported)
Unattended-Upgrade::Package-Blacklist {
//      "vim";
//      "libc6";
//      "libc6-dev";
//      "libc6-i686";
};

// This option allows you to control if on a unclean dpkg exit
// unattended-upgrades will automatically run
//   dpkg --force-confold --configure -a
// The default is true, to ensure updates keep getting installed
//Unattended-Upgrade::AutoFixInterruptedDpkg "false";

// Split the upgrade into the smallest possible chunks so that
// they can be interrupted with SIGUSR1. This makes the upgrade
// a bit slower but it has the benefit that shutdown while a upgrade
// is running is possible (with a small delay)
//Unattended-Upgrade::MinimalSteps "true";

// Install all unattended-upgrades when the machine is shuting down
// instead of doing it in the background while the machine is running
// This will (obviously) make shutdown slower
//Unattended-Upgrade::InstallOnShutdown "true";

// Send email to this address for problems or packages upgrades
// If empty or unset then no email is sent, make sure that you
// have a working mail setup on your system. A package that provides
// 'mailx' must be installed. E.g. "user@example.com"
//Unattended-Upgrade::Mail "root";

// Set this value to "true" to get emails only on errors. Default
// is to always send a mail if Unattended-Upgrade::Mail is set
//Unattended-Upgrade::MailOnlyOnError "true";

// Do automatic removal of new unused dependencies after the upgrade
// (equivalent to apt-get autoremove)
//Unattended-Upgrade::Remove-Unused-Dependencies "false";

// Automatically reboot *WITHOUT CONFIRMATION*
//  if the file /var/run/reboot-required is found after the upgrade
//Unattended-Upgrade::Automatic-Reboot "false";

// If automatic reboot is enabled and needed, reboot at the specific
// time instead of immediately
//  Default: "now"
//Unattended-Upgrade::Automatic-Reboot-Time "02:00";

// Use apt bandwidth limit feature, this example limits the download
// speed to 70kb/sec
//Acquire::http::Dl-Limit "70";
blacknon@BS-PUB-UBUNTU-01:~$ cat /etc/apt/apt.conf.d/50unattended-upgrades | grep -v -e ^// -e ^$
Unattended-Upgrade::Allowed-Origins {
        "${distro_id}:${distro_codename}-security";
};
Unattended-Upgrade::Package-Blacklist {
};

 

なお、デフォルトではセキュリティアップデートのみが実行されOS再起動はされないのだが、一部のアップデートではOS再起動が必要な場合がある。
その場合は「Unattended-Upgrade::Automatic-Reboot」をtrueにしてやればいいだろう。

2.セキュリティアップデートを手動実行させる

セキュリティアップデートを手動実行させるのは簡単。
sudo付きでオプションなしでコマンドを実行してやればいいだけだ。

sudo unattended-upgrades

 

3.セキュリティアップデートを自動実行させる

セキュリティアップデートを自動実行させる場合は、以下のコマンドを実行して画面の選択肢で<はい>を設定してやればよい。

sudo dpkg-reconfigure -plow unattended-upgrades

20160903_171440000000

20160903_171523000000

 

これで、セキュリティアップデートが日次で実行されるようになった。「/etc/cron.daily」と同じタイミングで実行されるようなので、「/etc/crontab」の設定日時に確認するといいだろう。

 

Linuxで『progress』コマンドを使って動いてるcpやmv、tarの進捗状況を調べる

$
0
0

cpやmv、tarコマンドの進捗状況を調べる方法といえばいくつかあるが、progressコマンドなるものを用いてバックで動いているcpやmvなどの進捗状況を確認することができるようだ。
以下、インストールコマンド。

rpm -ihv http://cbs.centos.org/kojifiles/packages/progress/0.13/1.el6/x86_64/progress-0.13-1.el6.x86_64.rpm # RHEL6系
rpm -ihv http://cbs.centos.org/kojifiles/packages/progress/0.13/1.el7/x86_64/progress-0.13-1.el7.x86_64.rpm # RHEL7系
sudo apt-get install progress # Debian/Ubuntu系

あとは、cpやmv、tar実行中に別ウィンドウからコマンドを実行するだけだ。

progress
[root@BS-PUB-CENT7-01 ~]# progress # 裏で何も動いてないときは以下のメッセージが流れる
No command currently running: cp, mv, dd, tar, cat, rsync, grep, fgrep, egrep, cut, sort, md5sum, sha1sum, sha224sum, sha256sum, sha384sum, sha512sum, adb, gzip, gunzip, bzip2, bunzip2, xz, unxz, lzma, unlzma, zcat, bzcat, lzcat, or wrong permissions.
[root@BS-PUB-CENT7-01 ~]# progress
[24349] tar /root/jdk-8u101-linux-x64.rpm
        18.9% (29.9 MiB / 158.3 MiB)

[24350] gzip /root/aaa.tar.gz
        100.0% (29.2 MiB / 29.2 MiB)

[root@BS-PUB-CENT7-01 ~]# progress
[24349] tar /root/jdk-8u101-linux-x64.rpm
        55.5% (87.8 MiB / 158.3 MiB)

[24350] gzip /root/aaa.tar.gz
        100.0% (86.9 MiB / 86.9 MiB)

[root@BS-PUB-CENT7-01 ~]# progress
[24349] tar /root/jdk-8u101-linux-x64.rpm
        68.5% (108.4 MiB / 158.3 MiB)

[24350] gzip /root/aaa.tar.gz
        100.0% (107.5 MiB / 107.5 MiB)

[root@BS-PUB-CENT7-01 ~]# progress
[24349] tar /root/aaa.tar.gz
        20.8% (43.6 MiB / 210.0 MiB)

[24350] gzip /root/aaa.tar.gz
        100.0% (210.0 MiB / 210.0 MiB)

 

改訂3版 Linuxエンジニア養成読本 (Software Design plus) 改訂3版 Linuxエンジニア養成読本 (Software Design plus)

Ubuntu 14.04上でオープンソースのIPAM・DCIMツール『netbox』をDockerで動作させる

$
0
0

今まで、OpenDCIMDevice42RalphといったDCIMツールを触ってきたのだが、DegitalOceanから『netbox』というDCIMツールが出たようなので、ちょっと触ってみることにする。
ちゃんとOSにインストールするなら、こちらの公式ドキュメントを参考に行うといいだろうが、ちょっと面倒くさそうだ。
Dockerイメージもあるので、今回はお試しということもあってこちらを利用する(なので、前提として最新版(少なくとも、docker-composeのVersion2の記述方法に対応したバージョン)のDockerとdocker-composeがインストール済みとなってる必要がある)。また、Dockerの設定ファイルを見たところ、今時点では16.04には対応してなさそうなので、14.04を用いる。

Dockerおよびdocker-composeをインストールしたら、以下のコマンドで「netbox」のDockerイメージを起動させる。

git clone -b master https://github.com/digitalocean/netbox.git
cd netbox
sudo docker-compose up -d

 

Dockerでの起動が終了したら、「http://IPアドレス」でアクセスできる。
この状態だとログイン前のため、何も編集ができない(閲覧モードになる)。右上の「Log in」からログインできる。

20160904_140150000000

 

ログイン用のデフォルトID/PWは「admin/admin」となっている。

20160904_140716000000

 

ログイン後の画面がこちら。

20160904_140805000000

 

「netbox」は、以下のような構成になっているようだ。

  • Organization
    • Sites … 地理的な場所(DCのある場所)
    • Tenants … そのSiteに紐づく客や部門など
  • DCIM
    • Racks … ラックの情報(Sitesがないと作れない)
    • Devices … ラックに搭載するデバイスの情報
  • IPAM
    • VRFs … VRFの情報
    • Aggregates … トップレベルIPの割り当て情報
    • Prefixes … IPv4/IPv6ネットワーク割り当て情報
    • IP Addresses … 各IPアドレスの管理情報
    • VLANs … 各VLANの管理情報
  • Circuits
    • Providers … インターネットプロバイダ情報
    • Circuits … インターネット接続情報?(インターネット速度など)
  • Secrets
    • Secrets … パスワードなどの機密情報(今時点でSSL経由の通信ないみたいだけど。まぁリバースプロキシをコンテナで動かさせたりすればいいだけだから…)

各機能(特にRackまわり)、なんとなく触ってみたので、スクリーンショットを貼っておく。

ラック。ラックに搭載する機器はデバイスタイプ(自分で設定する。サーバとかスイッチとか)ごとに色を変えられるので、閲覧性は悪くない。

20160904_182842000000

 

 

各デバイスにはネットワークポートを設定でき、それぞれ対向先の機器についても定義できる。
(この辺はまだRalphにはついてないんだよなぁ…今年の10月から開発するって言ってたけど、どうなんだろう…)

20160904_182922000000

20160904_183007000000

 

各ネットワークポートの作成には正規表現を使えるので、スイッチの作成では結構楽。

20160904_183842000000

 

シークレット機能が少し面白い。
登録時に鍵で暗号化しておき、自身のProfileで設定した鍵と一致した場合は中身を見れるようだ。
こんな機能があるのにSSL経由の通信じゃないのは残念だが、また改善されていくだろう。

20160904_183307000000

20160904_183308000000

 

DegitalOceanの作成したツールということもあり、結構期待してもよさそう。
まだDCIMを導入してないような環境であれば一考の価値はありそうだ。

インフラ/ネットワークエンジニアのためのネットワーク技術&設計入門 インフラ/ネットワークエンジニアのためのネットワーク技術&設計入門

cpやmvコマンドに『advcpmv』パッチを適用してプログレスバーによる進捗表示をさせる

$
0
0

以前にもこちらで触れたことがあるのだが、有志の作成した『advcpmv』というパッチをcp、mvファイルに適用することで、コマンド実行時にプログレスバーを表示させることができるようになる。
パッチは、以下の方法で当てることができる。

wget http://ftp.gnu.org/gnu/coreutils/coreutils-8.21.tar.xz
tar xvJf coreutils-8.21.tar.xz
cd coreutils-8.21/
wget https://raw.githubusercontent.com/atdt/advcpmv/master/advcpmv-0.5-8.21.patch
patch -p1 -i advcpmv-0.5-8.21.patch
./configure
make

コンパイル完了後、既存のコマンドと置き換える。

sudo cp src/cp /usr/local/bin/cp
sudo cp src/mv /usr/local/bin/mv
alias cp='/usr/local/bin/cp -g'
alias mv='/usr/local/bin/mv -g'

 

あとは、ふつうにcp、mvコマンドとして利用すればよい。

20160906_085143000000

 

改訂3版 Linuxエンジニア養成読本 (Software Design plus) 改訂3版 Linuxエンジニア養成読本 (Software Design plus)

CentOS7でNginx・MariaDB・PHP7(LEMP環境)を導入する

$
0
0

今回は、CentOS7でNginx・MariaDB・PHP7を利用した環境(LEMP環境)の構築を行う。
なお、作業の前提としてSELinuxはすでに停止済みとする。

1.前提パッケージの導入

まず、前提パッケージであるNginxやphp7を用いるためにepelとremiのインストールを行う。

●epel

yum install -y epel-release
sed -i.bk '/[epel]/,/^enabled/s/enabled=1/enabled=0/' /etc/yum.repos.d/epel.repo

 

●remi

rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

 

2.Nginxのインストール

Webサーバとして利用するNginxをインストールする。

yum install -y --enablerepo=epel nginx

 

サービスの起動設定、ファイアウォールのポート開放を行う。

systemctl restart nginx.service
systemctl enable nginx.service
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --reload

 

3.MariaDBのインストール

以下のコマンドでMariaDBのインストールを行う。

yum install -y mariadb mariadb-server

 

サービスの起動設定、最低限のセキュリティ設定を実施する。

systemctl start mariadb.service
systemctl enable mariadb.service
mysql_secure_installation
[root@BS-PUB-CENT7-01 ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: 行 379: find_mysql_client: コマンドが見つかりません

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

4.php7(+php-fpm)のインストール

最後に、php7のインストールを以下のコマンドで行う。
このとき、一緒にその他必要なパッケージ(php-fpmなど)も導入してしまう。

yum install -y --enablerepo=epel,remi-php70 php php-mbstring php-pear php-fpm php-mcrypt php-mysql
[root@BS-PUB-CENT7-01 ~]# php -v
PHP 7.0.10 (cli) (built: Aug 31 2016 18:07:34) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

 

4-1.php-fpmの関連設定

php-fpmでは、デフォルトの設定だとapacheが実行グループとなっているので、nginxに切り替える対応が必要になる。
以下のコマンドを実行し、置換を行う。

sed -i.bk '/^[user|group]/s/apache/nginx/' /etc/php-fpm.d/www.conf

 

また、php-fpmとNginxを連携させるため、Nginxの設定ファイルである「/etc/nginx/nginx.conf」というファイルを置き換える。
※VirtualHostでやるのであれば、別途「/etc/nginx/conf.d」配下に設定ファイルを作成することを推奨する。今回はテストなのでこのまま進める。

cat << "EOF" > /etc/nginx/conf.d/test.conf
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;
        index index.php;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        location ~ \.php$ {
            include /etc/nginx/fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/test$fastcgi_script_name;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}
EOF

 

作業完了後、php-fpmのサービス起動設定やNginxの再起動などを行う。

systemctl restart php-fpm.service
systemctl enable php-fpm.service
systemctl restart nginx.service

 

最後に、ちゃんとNginxでphpが動作しているかを確認するため、phpinfoファイルを作成、ブラウザからアクセスする。

echo '<?php phpinfo(); ?>' > /usr/share/nginx/html/index.php

20160904_231931000000

 

nginx実践入門 (WEB+DB PRESS plus) nginx実践入門 (WEB+DB PRESS plus)

CentOS7でNginx・MariaDB・PHP7(LEMP環境)によるWordPressの構築

$
0
0

今回は、CentOS 7でNginx・MariaDB・PHP7を用いた環境(LEMP環境)でのWordPressの構築を実施する。
まず、対象のサーバにLEMP環境が導入されていることが前提となるのだが、それについては下の内容を参照してもらいたい。

CentOS7でNginx・MariaDB・PHP7(LEMP環境)を導入する

 

1.Nginxの設定変更

まず、NginxでVirtualHostの設定を行う。
今回の場合、テストとしてローカルネットワーク内で構築をするため、以下のような設定となる。

  • server_name : bs-pub-wordpress-01.blacknon.local
  • listen : 80
  • Document root : /usr/share/nginx/wordpress
  • access_log : /var/log/nginx/wordpress/access.log
  • error_log : /var/log/nginx/wordpress/error.log

●/etc/nginx/conf.d/wordpress.conf

server {
    listen 80;
    server_name bs-pub-wordpress-01.blacknon.local;

    access_log /var/log/nginx/wordpress/access.log;
    error_log /var/log/nginx/wordpress/error.log;

    location / {
        root /usr/share/nginx/wordpress;
        index index.php index.html index.htm;

        if (-f $request_filename) {
            expires 30d;
            break;
            }

        if (!-e $request_filename) {
            rewrite ^(.+)$ /index.php?q=$1 last;
            }
        }

    location ~ .php$ {
        fastcgi_pass   localhost:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   /usr/share/nginx/wordpress/$fastcgi_script_name;
        fastcgi_param  PATH_INFO         $fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
        }
}

 

次に、先ほどの設定ファイルで指定したDocumentRootとログの出力ディレクトリについて作成する。

mkdir /usr/share/nginx/wordpress
mkdir /var/log/nginx/wordpress/
chown -R nginx:nginx /usr/share/nginx/wordpress/

 

Nginxの設定ファイルについてテストを行う。
問題がなければ下のような出力がされる。

nginx -t
[root@BS-PUB-WORDPRESS-01 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

問題がなかったら、以下のコマンドでサービスの再起動を実施する。

systemctl restart nginx.service
systemctl restart php-fpm.service

 

2.MariaDBでのデータベース作成

次に、MariaDBでWordPress用のデータベースを作成する。
以下のコマンドを実行する。

mysql -u root -p <<EOF
CREATE DATABASE wordpress;
CREATE USER 'ユーザ名'@'localhost' IDENTIFIED BY 'パスワード';
GRANT ALL PRIVILEGES ON wordpress.* TO 'ユーザ名'@'localhost';
EOF
[root@BS-PUB-WORDPRESS-01 ~]# mysql -u root -p < CREATE DATABASE wordpress;
> CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'wordpress';
> GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost';
> EOF
Enter password:

3.WordPressのインストール・初期設定

Nginxなどの設定が完了したら、WordPressのインストール、初期設定を行う。
まず、以下のコマンドでカレントディレクトリにWordPressのアーカイブファイルを取得して展開する。

wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz

 

展開後、以下のコマンドを実行してDocument Rootにファイルを移動する。

mv wordpress/* /usr/share/nginx/wordpress/
rmdir wordpress

 

wp-config.phpのサンプルファイルをコピーして設定ファイルを作成する。

cp /usr/share/nginx/wordpress/wp-config{-sample,}.php

 

コピーして作成したwp-config.phpファイルで、以下の項目を編集する。

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpress');

/** MySQL database password */
define('DB_PASSWORD', 'wordpress');

/** MySQL hostname */
define('DB_HOST', 'localhost');

 

設定ファイル編集後、DocumentRoot配下の所有者をnginxに変更する。

chown -R nginx:nginx /usr/share/nginx/wordpress

 

最後に、ブラウザからWordPressにアクセスする。
なお、このとき普通に「http://サーバ名」のみだと、なぜか「http://サーバ名/index.php/wp-admin/install.php」というリダイレクトがされてしまう。
なので、「http://サーバ名/wp-admin/install.php」を直接指定してやるといいだろう。

インストール画面が表示されたら、日本語を選択して「続ける」。

20160905_234205000000

 

作成するブログの情報を記録して「WordPressをインストール」をクリックする。

20160905_234435000000

 

インストールが完了したら、あとは先ほど設定したID/PWでログインするだけだ。

20160905_234445000000

20160905_234459000000

 

以上でインストールは完了。

WordPressサイト作成塾 WordPressサイト作成塾

Linuxコンソールでソートせずにユニークな値を求める

$
0
0

Linuxコンソール上で、ソートせずにユニークな値を取得したい時がある。
例えば、以下のようなファイルからユニークな値を取得する際、よく使われる方法としてはsort+uniqコマンドの組み合わせなのだが、それだと順番がずれてしまう。
あくまでもその文字列が最初に登場した順番でユニークな値を取得したいとする。

[root@BS-PUB-CENT7-01 ~]# cat /tmp/test.txt
test:0
test:2
test:6
test:9
test:4
test:9
test:9
test:9
test:4
test:0
test:2
test:8
test:0
test:7
test:0
[root@BS-PUB-CENT7-01 ~]# cat /tmp/test.txt | sort | uniq
test:0
test:2
test:4
test:6
test:7
test:8
test:9

そんな時は、以下の方法がある。

 

1.awkで取得する

前にこちらでも触れたことがあるが、awkで以下のようにコマンドを実行することで、同じ文字列が2回目の場合は出力させないようにできる。

コマンド | awk '!a[$1]++'
[root@BS-PUB-CENT7-01 ~]# cat /tmp/test.txt | awk '!a[$1]++'
test:0
test:2
test:6
test:9
test:4
test:8
test:7

2.Perlで取得する

awkと同じように、Perlでも同様の処理が行える。

コマンド | perl -ne 'print unless $seen{$_}++'
[root@BS-PUB-CENT7-01 ~]# cat /tmp/test.txt | perl -ne 'print unless $seen{$_}++'
test:0
test:2
test:6
test:9
test:4
test:8
test:7

 

3.johnパッケージのuniqueコマンドを利用する

変わり種としては、脆弱性スキャンを行うツールであるjohnパッケージ(John the Ripper)の中にあるuniqueコマンドが同じような動作をする(ただし、一度違うファイルに書き出す必要があるようだ)。

コマンド | unique 出力先PATH
blacknon@BS-PUB-UBUNTU-01:~$ cat /tmp/test.txt | unique /tmp/test.txt.uniq
blacknon@BS-PUB-UBUNTU-01:~$ cat /tmp/test.txt.uniq
test:0
test:2
test:6
test:9
test:4
test:8
test:7

 

新しいLinuxの教科書 新しいLinuxの教科書

yumコマンドで覚えておきたい使い方19個

$
0
0

CentOSなど、RHEL系のディストリビューションを使っているなら必ず一度は使ったことがあるであろうyumコマンド。
みんな使うけど、installとかupdateばかりで他のオプションはそんなに使われてない場合が多いような気もするが、使いこなせるとかなり便利な機能がいっぱいある。
…といっても、機能がありすぎるので、役に立ちそうなものだけを抜粋している。

1.パッケージをインストールする

yumを使ったことがあるなら、必ず一度は使っている使い方。
指定したパッケージを、yumリポジトリ(yumでインストールされるrpmパッケージのデータベースやデータそのものを持つ、貯蔵庫のようなもの)からインストールする使い方だ。
使い方も説明不要かと思うが、サブコマンド「install」にインストールするパッケージ名を引数として与えればよいだけだ。

yum install パッケージ名
[root@BS-PUB-CENT7-01 ~]# yum install wget
読み込んだプラグイン:fastestmirror
base                                                                    | 3.6 kB  00:00:00
extras                                                                  | 3.4 kB  00:00:00
updates                                                                 | 3.4 kB  00:00:00
(1/2): extras/7/x86_64/primary_db                                       | 160 kB  00:00:00
(2/2): updates/7/x86_64/primary_db                                      | 7.1 MB  00:00:00
Loading mirror speeds from cached hostfile
 * base: mirror.nus.edu.sg
 * extras: mirror.nus.edu.sg
 * updates: mirror.fairway.ne.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ wget.x86_64 0:1.14-10.el7_0.1 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

===============================================================================================
 Package           アーキテクチャー    バージョン                      リポジトリー       容量
===============================================================================================
インストール中:
 wget              x86_64              1.14-10.el7_0.1                 base              545 k

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

総ダウンロード容量: 545 k
インストール容量: 2.0 M
Is this ok [y/d/N]: y
Downloading packages:
wget-1.14-10.el7_0.1.x86_64.rpm                                         | 545 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : wget-1.14-10.el7_0.1.x86_64                                    1/1
  検証中                  : wget-1.14-10.el7_0.1.x86_64                                    1/1

インストール:
  wget.x86_64 0:1.14-10.el7_0.1

完了しました!

 

インストール時に聞かれる「y/n」については、「-y」オプションを付与することで自動的に処理がされる。
これについては他のサブコマンド処理でも同じだ。

 

2.パッケージをアップデートする

これも一度は使ったことがあるだろう。
すでにインストールされているパッケージのバージョンを上げる処理。引数に何も指定しないとアップデート可能なすべてのパッケージがアップデートされてしまうが、引数に対象のパッケージ名を与えることでそのパッケージのみをアップデートさせることができるようになる。

yum update
yum update パッケージ名 # パッケージを指定する場合

 

特定のバージョンにアップデートさせる場合は、パッケージ名-バージョンで指定してやるといいだろう。
指定できるバージョンについては、こちらにあるように「yum –showduplicates list パッケージ名」で確認してやればよい。

yum update パッケージ名-バージョン
[root@BS-PUB-CENT7-01 ~]# yum install httpd-2.4.6-40.el7.centos
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.nus.edu.sg
 * extras: mirror.nus.edu.sg
 * updates: mirror.fairway.ne.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ httpd.x86_64 0:2.4.6-40.el7.centos を インストール
--> 依存性の処理をしています: httpd-tools = 2.4.6-40.el7.centos のパッケージ: httpd-2.4.6-40.el7.centos.x86_64
--> 依存性の処理をしています: /etc/mime.types のパッケージ: httpd-2.4.6-40.el7.centos.x86_64
--> 依存性の処理をしています: libaprutil-1.so.0()(64bit) のパッケージ: httpd-2.4.6-40.el7.centos.x86_64
--> 依存性の処理をしています: libapr-1.so.0()(64bit) のパッケージ: httpd-2.4.6-40.el7.centos.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ apr.x86_64 0:1.4.8-3.el7 を インストール
---> パッケージ apr-util.x86_64 0:1.5.2-6.el7 を インストール
---> パッケージ httpd-tools.x86_64 0:2.4.6-40.el7.centos を インストール
---> パッケージ mailcap.noarch 0:2.1.41-2.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

===============================================================================================
 Package                アーキテクチャー  バージョン                     リポジトリー     容量
===============================================================================================
インストール中:
 httpd                  x86_64            2.4.6-40.el7.centos            base            2.7 M
依存性関連でのインストールをします:
 apr                    x86_64            1.4.8-3.el7                    base            103 k
 apr-util               x86_64            1.5.2-6.el7                    base             92 k
 httpd-tools            x86_64            2.4.6-40.el7.centos            base             82 k
 mailcap                noarch            2.1.41-2.el7                   base             31 k

トランザクションの要約
===============================================================================================
インストール  1 パッケージ (+4 個の依存関係のパッケージ)

総ダウンロード容量: 3.0 M
インストール容量: 10 M
Is this ok [y/d/N]: y
Downloading packages:
(1/5): apr-1.4.8-3.el7.x86_64.rpm                                       | 103 kB  00:00:00
(2/5): apr-util-1.5.2-6.el7.x86_64.rpm                                  |  92 kB  00:00:00
(3/5): mailcap-2.1.41-2.el7.noarch.rpm                                  |  31 kB  00:00:00
(4/5): httpd-tools-2.4.6-40.el7.centos.x86_64.rpm                       |  82 kB  00:00:00
(5/5): httpd-2.4.6-40.el7.centos.x86_64.rpm                             | 2.7 MB  00:00:00
-----------------------------------------------------------------------------------------------
合計                                                           2.8 MB/s | 3.0 MB  00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : apr-1.4.8-3.el7.x86_64                                         1/5
  インストール中          : apr-util-1.5.2-6.el7.x86_64                                    2/5
  インストール中          : httpd-tools-2.4.6-40.el7.centos.x86_64                         3/5
  インストール中          : mailcap-2.1.41-2.el7.noarch                                    4/5
  インストール中          : httpd-2.4.6-40.el7.centos.x86_64                               5/5
  検証中                  : httpd-2.4.6-40.el7.centos.x86_64                               1/5
  検証中                  : apr-1.4.8-3.el7.x86_64                                         2/5
  検証中                  : mailcap-2.1.41-2.el7.noarch                                    3/5
  検証中                  : httpd-tools-2.4.6-40.el7.centos.x86_64                         4/5
  検証中                  : apr-util-1.5.2-6.el7.x86_64                                    5/5

インストール:
  httpd.x86_64 0:2.4.6-40.el7.centos

依存性関連をインストールしました:
  apr.x86_64 0:1.4.8-3.el7                            apr-util.x86_64 0:1.5.2-6.el7
  httpd-tools.x86_64 0:2.4.6-40.el7.centos            mailcap.noarch 0:2.1.41-2.el7

完了しました!
[root@BS-PUB-CENT7-01 ~]# yum --showduplicates list httpd
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.nus.edu.sg
 * extras: mirror.nus.edu.sg
 * updates: mirror.fairway.ne.jp
インストール済みパッケージ
httpd.x86_64                           2.4.6-40.el7.centos                              @base
利用可能なパッケージ
httpd.x86_64                           2.4.6-40.el7.centos                              base
httpd.x86_64                           2.4.6-40.el7.centos.1                            updates
httpd.x86_64                           2.4.6-40.el7.centos.4                            updates
[root@BS-PUB-WORDPRESS-02 ~]# yum install httpd-2.4.6-40.el7.centos.4
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.nus.edu.sg
 * extras: mirror.nus.edu.sg
 * updates: mirror.fairway.ne.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ httpd.x86_64 0:2.4.6-40.el7.centos を 更新
---> パッケージ httpd.x86_64 0:2.4.6-40.el7.centos.4 を アップデート
--> 依存性の処理をしています: httpd-tools = 2.4.6-40.el7.centos.4 のパッケージ: httpd-2.4.6-40.el7.centos.4.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ httpd-tools.x86_64 0:2.4.6-40.el7.centos を 更新
---> パッケージ httpd-tools.x86_64 0:2.4.6-40.el7.centos.4 を アップデート
--> 依存性解決を終了しました。

依存性を解決しました

===============================================================================================
 Package              アーキテクチャー
                                      バージョン                        リポジトリー      容量
===============================================================================================
更新します:
 httpd                x86_64          2.4.6-40.el7.centos.4             updates          2.7 M
依存性関連での更新をします:
 httpd-tools          x86_64          2.4.6-40.el7.centos.4             updates           83 k

トランザクションの要約
===============================================================================================
更新  1 パッケージ (+1 個の依存関係のパッケージ)

総ダウンロード容量: 2.8 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/2): httpd-tools-2.4.6-40.el7.centos.4.x86_64.rpm                     |  83 kB  00:00:00
(2/2): httpd-2.4.6-40.el7.centos.4.x86_64.rpm                           | 2.7 MB  00:00:00
-----------------------------------------------------------------------------------------------
合計                                                           3.4 MB/s | 2.8 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  更新します              : httpd-tools-2.4.6-40.el7.centos.4.x86_64                       1/4
  更新します              : httpd-2.4.6-40.el7.centos.4.x86_64                             2/4
  整理中                  : httpd-2.4.6-40.el7.centos.x86_64                               3/4
  整理中                  : httpd-tools-2.4.6-40.el7.centos.x86_64                         4/4
  検証中                  : httpd-tools-2.4.6-40.el7.centos.4.x86_64                       1/4
  検証中                  : httpd-2.4.6-40.el7.centos.4.x86_64                             2/4
  検証中                  : httpd-2.4.6-40.el7.centos.x86_64                               3/4
  検証中                  : httpd-tools-2.4.6-40.el7.centos.x86_64                         4/4

更新:
  httpd.x86_64 0:2.4.6-40.el7.centos.4

依存性を更新しました:
  httpd-tools.x86_64 0:2.4.6-40.el7.centos.4

完了しました!

2-1.yum upgradeについて

また、似たようなコマンドで「yum upgrade」というコマンドがある。

yum upgrade

 

これは、「yum update –obsoletes」と同じ処理を行っているコマンドだ。
updateの際にすでに旧式となっているパッケージを削除し、適切なパッケージに置き換えてくれる処理として覚えておくといいだろう。

【参考】

 

2-2.アップデート可能なパッケージの一覧を取得する

アップデート可能なパッケージの一覧を取得したいだけなら、以下のコマンドで行える。

yum check-update
[root@BS-PUB-CENT7-01 ~]# yum check-update
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp

elasticsearch.noarch                         2.4.0-1                          elasticsearch-2.x
Security: kernel-3.10.0-327.28.3.el7.x86_64 is an installed security update
Security: kernel-3.10.0-327.28.2.el7.x86_64 is the currently running version

 

2-3.指定したパッケージを除外する

特定のパッケージをアップデートから除外する場合は、「–exclude」オプションで対象のパッケージを指定する。

yum update --exclude=パッケージ名
[root@BS-PUB-CENT7-01 test]# yum check-update
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp

elasticsearch.noarch                         2.4.0-1                          elasticsearch-2.x
Security: kernel-3.10.0-327.28.3.el7.x86_64 is an installed security update
Security: kernel-3.10.0-327.28.2.el7.x86_64 is the currently running version
[root@BS-PUB-CENT7-01 test]# yum update --exclude=elasticsearch
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
No packages marked for update
[root@BS-PUB-CENT7-01 test]# yum update
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ elasticsearch.noarch 0:2.3.4-1 を 更新
---> パッケージ elasticsearch.noarch 0:2.4.0-1 を アップデート
--> 依存性解決を終了しました。

依存性を解決しました

===============================================================================================
 Package                 アーキテクチャー バージョン         リポジトリー                 容量
===============================================================================================
更新します:
 elasticsearch           noarch           2.4.0-1            elasticsearch-2.x            26 M

トランザクションの要約
===============================================================================================
更新  1 パッケージ

総ダウンロード容量: 26 M
Is this ok [y/d/N]:

 

2-4.セキュリティ関連のアップデートのみ実行させる

セキュリティ関連のアップデートのみを実行させる場合は、「–security」オプションを付与してアップデートを行わせる。

yum --security update

ただし、これについてはCentOSではデフォルトのリポジトリにはセキュリティアップデートの情報が登録されないため正常に動かない。
CentOSでこの機能を利用するには、こちらにある手順を用いてセキュリティ情報を管理しているリポジトリを登録してやるとよいだろう。

 

3.パッケージをダウングレードする

パッケージを一つ前のバージョンに戻したい場合は、以下のようにコマンドを実行することでダウングレードが行える。

yum downgrade パッケージ名

 

もしくは、バージョンを指定させる場合には以下のようにコマンドを実行するとよいだろう。
指定できるバージョンについては、アップデートと同じように「yum –showduplicates list パッケージ名」で確認してやればよい。

yum downgrade パッケージ名-バージョン
[root@BS-PUB-CENT7-01 ~]# yum --showduplicates list elasticsearch
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
インストール済みパッケージ
elasticsearch.noarch                         2.3.5-1                         @elasticsearch-2.x
利用可能なパッケージ
elasticsearch.noarch                         2.0.0-1                         elasticsearch-2.x
elasticsearch.noarch                         2.0.1-1                         elasticsearch-2.x
elasticsearch.noarch                         2.0.2-1                         elasticsearch-2.x
elasticsearch.noarch                         2.1.0-1                         elasticsearch-2.x
elasticsearch.noarch                         2.1.1-1                         elasticsearch-2.x
elasticsearch.noarch                         2.1.2-1                         elasticsearch-2.x
elasticsearch.noarch                         2.2.0-1                         elasticsearch-2.x
elasticsearch.noarch                         2.2.1-1                         elasticsearch-2.x
elasticsearch.noarch                         2.2.2-1                         elasticsearch-2.x
elasticsearch.noarch                         2.3.0-1                         elasticsearch-2.x
elasticsearch.noarch                         2.3.1-1                         elasticsearch-2.x
elasticsearch.noarch                         2.3.2-1                         elasticsearch-2.x
elasticsearch.noarch                         2.3.3-1                         elasticsearch-2.x
elasticsearch.noarch                         2.3.4-1                         elasticsearch-2.x
elasticsearch.noarch                         2.3.5-1                         elasticsearch-2.x
elasticsearch.noarch                         2.4.0-1                         elasticsearch-2.x
[root@BS-PUB-CENT7-01 ~]# yum downgrade elasticsearch
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ elasticsearch.noarch 0:2.3.4-1 を ダウングレード
---> パッケージ elasticsearch.noarch 0:2.3.5-1 を 削除
--> 依存性解決を終了しました。

依存性を解決しました

===============================================================================================
 Package                 アーキテクチャー バージョン         リポジトリー                 容量
===============================================================================================
ダウングレード中:
 elasticsearch           noarch           2.3.4-1            elasticsearch-2.x            26 M

トランザクションの要約
===============================================================================================
ダウングレード  1 パッケージ

総ダウンロード容量: 26 M
Is this ok [y/d/N]: y
Downloading packages:
elasticsearch-2.3.4.rpm                                                 |  26 MB  00:00:14
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告: RPMDB は yum 以外で変更されました。
  インストール中          : elasticsearch-2.3.4-1.noarch                                   1/2
  整理中                  : elasticsearch-2.3.5-1.noarch                                   2/2
  検証中                  : elasticsearch-2.3.4-1.noarch                                   1/2
  検証中                  : elasticsearch-2.3.5-1.noarch                                   2/2

削除しました:
  elasticsearch.noarch 0:2.3.5-1

インストール:
  elasticsearch.noarch 0:2.3.4-1

完了しました!

4.パッケージをアンインストールする

パッケージをアンインストールする場合は、以下のようにサブコマンドとして「erase」を指定してやればよい。

yum erase パッケージ名
[root@BS-PUB-CENT7-01 ~]# yum erase wget
読み込んだプラグイン:fastestmirror
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ wget.x86_64 0:1.14-10.el7_0.1 を 削除
--> 依存性解決を終了しました。

依存性を解決しました

===============================================================================================
 Package           アーキテクチャー    バージョン                     リポジトリー        容量
===============================================================================================
削除中:
 wget              x86_64              1.14-10.el7_0.1                @base              2.0 M

トランザクションの要約
===============================================================================================
削除  1 パッケージ

インストール容量: 2.0 M
上記の処理を行います。よろしいでしょうか? [y/N]y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  削除中                  : wget-1.14-10.el7_0.1.x86_64                                    1/1
  検証中                  : wget-1.14-10.el7_0.1.x86_64                                    1/1

削除しました:
  wget.x86_64 0:1.14-10.el7_0.1

完了しました!

 

5.パッケージのリストを取得する

「yum list」を実行することで、設定されているリポジトリやローカルにインストールされているパッケージのリストを取得することができる。
さらに引数を付け加えることでupdateで指定できるパッケージやインストール済のパッケージのリストを抽出して取得することができる。

yum list
yum list installed # インストール済のパッケージを表示させる
yum list updates # アップデート可能なパッケージを表示させる
yum list available # 利用可能なパッケージを表示させる
yum list extras # 利用できないパッケージを表示させる

 

6.パッケージで利用できる各バージョンのリストを取得する

yumで、パッケージで利用できる各バージョンのリストを取得するには、以下のコマンドを実行すればよい。
現在のバージョン、ダウングレード、アップデートできるバージョンがそれぞれ色分けされて表示される。

yum --showduplicates list パッケージ名

20160909_072639000000

[root@BS-PUB-CENT7-01 ~]# yum --showduplicates list elasticsearch
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
インストール済みパッケージ
elasticsearch.noarch                         2.3.4-1                         @elasticsearch-2.x
利用可能なパッケージ
elasticsearch.noarch                         2.0.0-1                         elasticsearch-2.x
elasticsearch.noarch                         2.0.1-1                         elasticsearch-2.x
elasticsearch.noarch                         2.0.2-1                         elasticsearch-2.x
elasticsearch.noarch                         2.1.0-1                         elasticsearch-2.x
elasticsearch.noarch                         2.1.1-1                         elasticsearch-2.x
elasticsearch.noarch                         2.1.2-1                         elasticsearch-2.x
elasticsearch.noarch                         2.2.0-1                         elasticsearch-2.x
elasticsearch.noarch                         2.2.1-1                         elasticsearch-2.x
elasticsearch.noarch                         2.2.2-1                         elasticsearch-2.x
elasticsearch.noarch                         2.3.0-1                         elasticsearch-2.x
elasticsearch.noarch                         2.3.1-1                         elasticsearch-2.x
elasticsearch.noarch                         2.3.2-1                         elasticsearch-2.x
elasticsearch.noarch                         2.3.3-1                         elasticsearch-2.x
elasticsearch.noarch                         2.3.4-1                         elasticsearch-2.x
elasticsearch.noarch                         2.3.5-1                         elasticsearch-2.x
elasticsearch.noarch                         2.4.0-1                         elasticsearch-2.x

 

7.パッケージの情報を取得する

サブコマンドとして「info」を指定することで、パッケージの情報を取得することができる。

yum info # 全パッケージ
yum info パッケージ名

20160909_081356000000

[root@BS-PUB-CENT7-01 ~]# yum info wget
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
利用可能なパッケージ
名前                : wget
アーキテクチャー    : x86_64
バージョン          : 1.14
リリース            : 10.el7_0.1
容量                : 545 k
リポジトリー        : base/7/x86_64
要約                : A utility for retrieving files using the HTTP or FTP protocols
URL                 : http://www.gnu.org/software/wget/
ライセンス          : GPLv3+
説明                : GNU Wget is a file retrieval utility which can use either the HTTP or
                    : FTP protocols. Wget features include the ability to work in the
                    : background while you are logged out, recursive retrieval of
                    : directories, file name wildcard matching, remote file timestamp
                    : storage and comparison, use of Rest with FTP servers and Range with
                    : HTTP servers to retrieve files over slow or unstable connections,
                    : support for Proxy servers, and configurability.

 

8.グループインストールをする

yumでは、グループ名を指定することでパッケージをまとめてインストールさせることができる。

yum groups install グループ名

 

指定できるグループ名のリストおよびその内容については、以下のコマンドで確認できる。
なお、yum全体でいえることだが「-v」オプションを付与することでより細かい情報を表示させることもできる。

yum groups list # グループ名一覧
yum groups info グループ名 # 指定したグループの内容
[root@BS-PUB-CENT7-01 ~]# yum groups list
読み込んだプラグイン:fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
Available Environment Groups:
   最小限のインストール
   Compute Node
   インフラストラクチャサーバー
   ファイルとプリントサーバー
   MATE デスクトップ
   ベーシック Web サーバー
   仮想化ホスト
   サーバー (GUI 使用)
   GNOME Desktop
   KDE Plasma Workspaces
   開発およびクリエイティブワークステーション
利用可能なグループ
   CIFS ファイルサーバー
   Eclipse
   FCoE ストレージクライアント
   Fedora パッケージャ
   Haskell のサポート
   Milkymist
   MySQL データベースクライアント
   MySQL データベースサーバー
   NFS サーバー
   SNMP のサポート
   TeX のサポート
   TurboGears アプリケーションフレームワーク
   WBEM のサポート
   Xfce
   iSCSI ストレージクライアント
   グラフィカル管理ツール
   コンソールインターネットツール
   サーバープラットフォーム
   サーバー環境の開発環境
   システム管理
   システム管理ツール
   ストレージ可用性ツール
   スマートカードサポート
   セキュリティツール
   デスクトップ
   デスクトップ環境
   デスクトップ環境の開発環境
   ネットワークストレージサーバー
   メッセージングクライアントのサポート
   メッセージングサーバーのサポート
   レガシーな UNIX 互換性
   互換性ライブラリ
   仮想化
   教育用ソフトウェア
   汎用デスクトップ
   科学的サポート
   開発ツール
   電子ラボラトリ
完了
[root@BS-PUB-CENT7-01 ~]# yum groups list -v
プラグイン「fastestmirror」を読み込んでいます
Config time: 0.011
Yum version: 3.4.3
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Setting up Package Sacks
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
pkgsack time: 0.033
group time: 0.216
Available Environment Groups:
   最小限のインストール (minimal)
   Compute Node (compute-node-environment)
   インフラストラクチャサーバー (infrastructure-server-environment)
   ファイルとプリントサーバー (file-print-server-environment)
   MATE デスクトップ (mate-desktop-environment)
   ベーシック Web サーバー (web-server-environment)
   仮想化ホスト (virtualization-host-environment)
   サーバー (GUI 使用) (graphical-server-environment)
   GNOME Desktop (gnome-desktop-environment)
   KDE Plasma Workspaces (kde-desktop-environment)
   開発およびクリエイティブワークステーション (developer-workstation-environment)
利用可能なグループ
   CIFS ファイルサーバー (cifs-file-server)
   Eclipse (eclipse)
   FCoE ストレージクライアント (storage-client-fcoe)
   Fedora パッケージャ (fedora-packager)
   Haskell のサポート (haskell)
   Milkymist (milkymist)
   MySQL データベースクライアント (mysql-client)
   MySQL データベースサーバー (mysql)
   NFS サーバー (nfs-file-server)
   SNMP のサポート (system-management-snmp)
   TeX のサポート (tex)
   TurboGears アプリケーションフレームワーク (turbogears)
   WBEM のサポート (system-management-wbem)
   Xfce (xfce-desktop)
   iSCSI ストレージクライアント (storage-client-iscsi)
   グラフィカル管理ツール (graphical-admin-tools)
   コンソールインターネットツール (console-internet)
   サーバープラットフォーム (server-platform)
   サーバー環境の開発環境 (server-platform-devel)
   システム管理 (system-management)
   システム管理ツール (system-admin-tools)
   ストレージ可用性ツール (storage-client-multipath)
   スマートカードサポート (smart-card)
   セキュリティツール (security-tools)
   デスクトップ (basic-desktop)
   デスクトップ環境 (desktop-platform)
   デスクトップ環境の開発環境 (desktop-platform-devel)
   ネットワークストレージサーバー (storage-server)
   メッセージングクライアントのサポート (system-management-messaging-client)
   メッセージングサーバーのサポート (system-management-messaging-server)
   レガシーな UNIX 互換性 (legacy-unix)
   互換性ライブラリ (compat-libraries)
   仮想化 (virtualization)
   教育用ソフトウェア (education)
   汎用デスクトップ (general-desktop)
   科学的サポート (scientific)
   開発ツール (development)
   電子ラボラトリ (electronic-lab)
完了
[root@BS-PUB-CENT7-01 ~]# yum groups info -v security-tools
プラグイン「fastestmirror」を読み込んでいます
Config time: 0.016
Yum version: 3.4.3
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Setting up Package Sacks
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
pkgsack time: 0.032
group time: 0.216

グループ: セキュリティツール
 グループ ID: security-tools
rpmdb time: 0.000
 説明: 整合性や信用を検証するセキュリティツール
 標準パッケージ:
   +scap-security-guide-0.1.25-3.el7.centos.0.1.noarch                                base
 オプション パッケージ:
   aide-0.15.1-9.el7.x86_64                                                           base
   hmaccalc-0.9.13-4.el7.x86_64                                                       base
   openscap-1.2.9-5.el7_2.i686                                                        updates
   openscap-1.2.9-5.el7_2.x86_64                                                      updates
   openscap-utils-1.2.9-5.el7_2.x86_64                                                updates
   scap-workbench-1.0.2-2.el7.x86_64                                                  base
   strongimcv-5.2.0-3.el7.i686                                                        base
   strongimcv-5.2.0-3.el7.x86_64                                                      base
   tncfhh-0.8.3-16.el7.i686                                                           base
   tncfhh-0.8.3-16.el7.x86_64                                                         base
   tpm-quote-tools-1.0.2-3.el7.x86_64                                                 base
   tpm-tools-1.3.8-6.el7.i686                                                         base
   tpm-tools-1.3.8-6.el7.x86_64                                                       base
   trousers-0.3.13-1.el7.i686                                                         base
   trousers-0.3.13-1.el7.x86_64                                                       @anaconda

 

また、アンインストールする場合には「groups remove」を、アップデートする場合には「groups update」を用いる。

yum groups remove グループ名 # アンインストール
yum groups update グループ名 # アップデート

 

9.メタデータなどのキャッシュファイルを削除・更新する

メタデータなどのキャッシュファイルが正常な状態になっておらず、yumでの処理が失敗するといったことがあるなら、「yum clean all」を用いる。

yum clean all

 

また、パッケージ情報を保持するメタデータの更新の間隔は、installやupdateの時に設定ファイルにある「metadata_expire」の値(デフォルトだと90分)の間隔で更新される。
もし今すぐにでもパッケージの最新情報を取得したい場合は、以下のコマンドを実行する。

yum makecache

 

 

10.リポジトリの一覧を取得する

使用できるリポジトリの一覧を取得する場合は、以下のコマンドを実行する。

yum repolist
[root@BS-PUB-CENT7-01 ~]# yum repolist
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
リポジトリー ID               リポジトリー名                                             状態
base/7/x86_64                 CentOS-7 - Base                                             9,007
elasticsearch-2.x             Elasticsearch repository for 2.x packages                      16
epel/x86_64                   Extra Packages for Enterprise Linux 7 - x86_64             10,540
extras/7/x86_64               CentOS-7 - Extras                                             376
graylog/x86_64                graylog                                                        10
mongodb-org-3.2/7             MongoDB Repository                                             50
security                      CentOS-7 - Security                                             0
updates/7/x86_64              CentOS-7 - Updates                                          2,311
repolist: 22,310
[root@BS-PUB-CENT7-01 ~]# yum repolist -v
プラグイン「fastestmirror」を読み込んでいます
Config time: 0.011
Yum version: 3.4.3
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
Setting up Package Sacks
pkgsack time: 0.015
リポジトリー ID            : base/7/x86_64
リポジトリーの名前         : CentOS-7 - Base
リポジトリーのリビジョン   : 1449700451
リポジトリー更新日         : Thu Dec 10 07:35:45 2015
リポジトリー内パッケージ数 : 9,007
リポジトリー容量           : 6.5 G
リポジトリーのミラー       : http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock
リポジトリー基準 URL       : http://ftp.riken.jp/Linux/centos/7.2.1511/os/x86_64/ (9 more)
リポジトリーの期限         : 21,600 秒 (最終: Fri Sep  9 07:46:43 2016)
Repo ファイル名: /etc/yum.repos.d/CentOS-Base.repo

リポジトリー ID            : elasticsearch-2.x
リポジトリーの名前         : Elasticsearch repository for 2.x packages
リポジトリーのリビジョン   : 1472465635
リポジトリー更新日         : Mon Aug 29 19:13:56 2016
リポジトリー内パッケージ数 : 16
リポジトリー容量           : 431 M
リポジトリー基準 URL       : https://packages.elastic.co/elasticsearch/2.x/centos/
リポジトリーの期限         : 21,600 秒 (最終: Fri Sep  9 07:46:45 2016)
Repo ファイル名: /etc/yum.repos.d/elasticsearch.repo

リポジトリー ID            : epel/x86_64
リポジトリーの名前         : Extra Packages for Enterprise Linux 7 - x86_64
リポジトリーのリビジョン   : 1473219190
リポジトリーのタグ         : binary-x86_64
リポジトリー更新日         : Wed Sep  7 15:03:11 2016
リポジトリー内パッケージ数 : 10,540
リポジトリー容量           : 11 G
リポジトリーメタリンク     : https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=x86_64
  更新日                   : Wed Sep  7 15:03:11 2016
リポジトリー基準 URL       : http://ftp.riken.jp/Linux/fedora/epel/7/x86_64/ (15 more)
リポジトリーの期限         : 21,600 秒 (最終: Fri Sep  9 07:46:46 2016)
Repo ファイル名: /etc/yum.repos.d/epel.repo

リポジトリー ID            : extras/7/x86_64
リポジトリーの名前         : CentOS-7 - Extras
リポジトリーのリビジョン   : 1473158555
リポジトリー更新日         : Tue Sep  6 19:43:22 2016
リポジトリー内パッケージ数 : 376
リポジトリー容量           : 1.0 G
リポジトリーのミラー       : http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock
リポジトリー基準 URL       : http://ftp.riken.jp/Linux/centos/7.2.1511/extras/x86_64/ (9 more)
リポジトリーの期限         : 21,600 秒 (最終: Fri Sep  9 07:46:46 2016)
Repo ファイル名: /etc/yum.repos.d/CentOS-Base.repo

リポジトリー ID            : graylog/x86_64
リポジトリーの名前         : graylog
リポジトリーのリビジョン   : 1472742118
リポジトリー更新日         : Fri Sep  2 00:01:58 2016
リポジトリー内パッケージ数 : 10
リポジトリー容量           : 723 M
リポジトリー基準 URL       : https://packages.graylog2.org/repo/el/stable/2.0/x86_64/
リポジトリーの期限         : 21,600 秒 (最終: Fri Sep  9 07:46:49 2016)
Repo ファイル名: /etc/yum.repos.d/graylog.repo

リポジトリー ID            : mongodb-org-3.2/7
リポジトリーの名前         : MongoDB Repository
リポジトリーのリビジョン   : 1471372913
リポジトリー更新日         : Wed Aug 17 03:41:56 2016
リポジトリー内パッケージ数 : 50
リポジトリー容量           : 629 M
リポジトリー基準 URL       : https://repo.mongodb.org/yum/redhat/7/mongodb-org/3.2/x86_64/
リポジトリーの期限         : 21,600 秒 (最終: Fri Sep  9 07:46:49 2016)
Repo ファイル名: /etc/yum.repos.d/mongodb-org-3.2.repo

リポジトリー ID            : security
リポジトリーの名前         : CentOS-7 - Security
リポジトリーのリビジョン   : 1472865910
リポジトリー更新日         : Sat Sep  3 10:25:19 2016
リポジトリー内パッケージ数 : 0
リポジトリー容量           : 0
リポジトリー基準 URL       : file:///security/
リポジトリーの期限         : 21,600 秒 (最終: Fri Sep  9 07:46:49 2016)
Repo ファイル名: /etc/yum.repos.d/CentOS-Base.repo

リポジトリー ID            : updates/7/x86_64
リポジトリーの名前         : CentOS-7 - Updates
リポジトリーのリビジョン   : 1473131199
リポジトリー更新日         : Tue Sep  6 12:10:55 2016
リポジトリー内パッケージ数 : 2,311
リポジトリー容量           : 6.4 G
リポジトリーのミラー       : http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock
リポジトリー基準 URL       : http://ftp.riken.jp/Linux/centos/7.2.1511/updates/x86_64/ (9 more)
リポジトリーの期限         : 21,600 秒 (最終: Fri Sep  9 07:46:49 2016)
Repo ファイル名: /etc/yum.repos.d/CentOS-Base.repo

repolist: 22,310

 

11.リポジトリの使用有無を指定する

yum実行時にリポジトリを使用するかどうかは、以下のオプションで指定できる。

yum --enablerepo=リポジトリ名 ~ # リポジトリを使用する
yum --disablerepo=リポジトリ名 ~ # リポジトリを使用しない

 

なお、各リポジトリがデフォルトで有効・無効になっているかは、「/etc/yum.repos.d/」配下にある各リポジトリの構成ファイルで設定されている。
リポジトリが有効か無効かを調べるには、上記構成ファイルを見るほかに以下のコマンドで確認する方法もある。

yum repoinfo リポジトリ
[root@BS-PUB-CENT7-01 ~]# yum repoinfo epel
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
リポジトリー ID            : epel/x86_64
リポジトリーの名前         : Extra Packages for Enterprise Linux 7 - x86_64
リポジトリーの状態         : 有効
リポジトリーのリビジョン   : 1473219190
リポジトリーのタグ         : binary-x86_64
リポジトリー更新日         : Wed Sep  7 15:03:11 2016
リポジトリー内パッケージ数 : 10,540
リポジトリー容量           : 11 G
リポジトリーメタリンク     : https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=x86_64
  更新日                   : Wed Sep  7 15:03:11 2016
リポジトリー基準 URL       : http://ftp.riken.jp/Linux/fedora/epel/7/x86_64/ (15 more)
リポジトリーの期限         : 21,600 秒 (最終: Fri Sep  9 07:46:46 2016)
Repo ファイル名: /etc/yum.repos.d/epel.repo

repolist: 10,540

 

12.パッケージを検索する

パッケージ名、詳細から検索をする場合は、「yum search」コマンドで検索ができる。

yum search テキスト
[root@BS-PUB-CENT7-01 ~]# yum search bash
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
====================================== N/S matched: bash ======================================
bash-argsparse.noarch : An high level argument parsing library for bash
bash-completion.noarch : Programmable completion for Bash
bash-completion-extras.noarch : Additional programmable completions for Bash
bash-doc.x86_64 : Documentation files for bash
bashdb.noarch : BASH debugger, the BASH symbolic debugger
bashmount.noarch : A menu-driven bash script for mounting removable media
libguestfs-bash-completion.noarch : Bash tab-completion scripts for libguestfs tools
pcp-pmda-bash.x86_64 : Performance Co-Pilot (PCP) metrics for the Bash shell
python-django-bash-completion.noarch : bash completion files for Django
bash.x86_64 : The GNU Bourne Again shell
bats.noarch : Bash Automated Testing System
python-argcomplete.noarch : Bash tab completion for argparse
sys_basher.x86_64 : A multithreaded hardware exerciser

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

13.指定したファイル・コマンド名から、どのパッケージが提供しているものか確認する

特定のコマンドやファイルがどのパッケージからインストールされるものなのかを調べる場合は、以下のようにコマンドを実行する。

yum provides コマンド名・ファイルPATH
[root@BS-PUB-CENT7-01 ~]# yum provides nping
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
base/7/x86_64/filelists_db                                              | 6.2 MB  00:00:01
elasticsearch-2.x/filelists_db                                          | 8.1 kB  00:00:00
epel/x86_64/filelists_db                                                | 7.2 MB  00:00:23
extras/7/x86_64/filelists_db                                            | 426 kB  00:00:00
graylog/x86_64/filelists_db                                             | 3.5 kB  00:00:00
mongodb-org-3.2/7/filelists_db                                          | 6.2 kB  00:00:00
security/filelists_db                                                   |  586 B  00:00:00
updates/7/x86_64/filelists_db                                           | 4.4 MB  00:00:00
2:nmap-6.40-7.el7.x86_64 : Network exploration tool and security scanner
リポジトリー        : base
一致          :
ファイル名    : /usr/bin/nping


上の例では、nmapパッケージに含まれるnpingコマンドを検索している。
結果、ちゃんとnmapパッケージを提示してくれたことがわかる。

 

14.yumで過去に行った処理を確認する

yumでは、過去に行った処理についてちゃんと記録している。
以下のコマンドで、過去の処理について一覧を表示させることができる。

yum history
[root@BS-PUB-CENT7-01 ~]# yum history
読み込んだプラグイン:fastestmirror
ID     | ログイン ユーザー        | 日時             | 操作           | 変更
-------------------------------------------------------------------------------
    20 | root               | 2016-09-09 08:02 | Erase          |    1
    19 | root               | 2016-09-09 08:02 | Install        |    5
    18 | root               | 2016-09-08 23:51 | Erase          |    1
    17 | root               | 2016-09-08 23:49 | Downgrade      |    1  <
    16 | root               | 2016-09-03 10:26 | I, U           |    4 >
    15 | root               | 2016-09-03 09:43 | Install        |    4
    14 | root               | 2016-09-03 09:38 | Install        |    1
    13 | root               | 2016-09-02 07:47 | Install        |  177
    12 | root               | 2016-09-02 07:45 | Update         |    1  <
    11 | root               | 2016-09-01 21:15 | Install        |    4 >
    10 | root               | 2016-09-01 06:34 | Install        |    1
     9 | root               | 2016-09-01 06:32 | Install        |   33
     8 | root               | 2016-08-30 07:43 | Install        |    1
     7 | root               | 2016-08-30 07:43 | Install        |    1
     6 | root               | 2016-08-30 07:41 | Install        |    1 E<
     5 | root               | 2016-08-30 07:35 | Install        |    5 >
     4 | root               | 2016-08-30 07:22 | Install        |    1 E<
     3 | root               | 2016-08-30 07:08 | Install        |    1 >
     2 | root               | 2016-08-19 08:57 | I, U           |   84
     1 | システム <未設定>        | 2016-01-01 22:59 | Install        |  297
history list

 

とはいえ、これだけではまだ何とも詳細がわからない。
そこで、以下コマンドで対象の履歴番号を指定して実行することで、その詳細を確認する。

yum history info 履歴番号
[root@BS-PUB-CENT7-01 ~]# yum history info 16
読み込んだプラグイン:fastestmirror
トランザクション ID : 16
開始時間            : Sat Sep  3 10:26:43 2016
開始 rpmdb          : 531:1e2be643da9f69ee5ee6a71d1edce293e2a16457
終了時間            :            10:28:56 2016 (133 秒)
終了 rpmdb          : 532:090b2d84288ccfd0620dabff0ff67ea1ae2d9770
ユーザー            : root
終了コード          : 成功
コマンドライン      : --security update
トランザクションの実行:
    インストール rpm-4.11.3-17.el7.x86_64                      @anaconda
    インストール yum-3.4.3-132.el7.centos.0.1.noarch           @anaconda
    インストール yum-plugin-fastestmirror-1.1.31-34.el7.noarch @anaconda
切り替えたパッケージ:
    インストール kernel-3.10.0-327.28.3.el7.x86_64            @updates
    更新   kernel-tools-3.10.0-327.28.2.el7.x86_64      @updates
    更新                3.10.0-327.28.3.el7.x86_64      @updates
    更新   kernel-tools-libs-3.10.0-327.28.2.el7.x86_64 @updates
    更新                     3.10.0-327.28.3.el7.x86_64 @updates
    更新   python-perf-3.10.0-327.28.2.el7.x86_64       @updates
    更新               3.10.0-327.28.3.el7.x86_64       @updates
history info

 

15.yumで過去に行った処理を取り消す

yumで過去に行った処理を取り消すこともできる。
取り消す履歴番号を調べたあとに、以下のコマンドを実行する。

yum history undo 履歴番号
[root@BS-PUB-CENT7-01 ~]# yum history
読み込んだプラグイン:fastestmirror
ID     | ログイン ユーザー        | 日時             | 操作           | 変更
-------------------------------------------------------------------------------
    20 | root               | 2016-09-09 08:02 | Erase          |    1
    19 | root               | 2016-09-09 08:02 | Install        |    5
    18 | root               | 2016-09-08 23:51 | Erase          |    1
    17 | root               | 2016-09-08 23:49 | Downgrade      |    1  <
    16 | root               | 2016-09-03 10:26 | I, U           |    4 >
    15 | root               | 2016-09-03 09:43 | Install        |    4
    14 | root               | 2016-09-03 09:38 | Install        |    1
    13 | root               | 2016-09-02 07:47 | Install        |  177
    12 | root               | 2016-09-02 07:45 | Update         |    1  <
    11 | root               | 2016-09-01 21:15 | Install        |    4 >
    10 | root               | 2016-09-01 06:34 | Install        |    1
     9 | root               | 2016-09-01 06:32 | Install        |   33
     8 | root               | 2016-08-30 07:43 | Install        |    1
     7 | root               | 2016-08-30 07:43 | Install        |    1
     6 | root               | 2016-08-30 07:41 | Install        |    1 E<
     5 | root               | 2016-08-30 07:35 | Install        |    5 >
     4 | root               | 2016-08-30 07:22 | Install        |    1 E<
     3 | root               | 2016-08-30 07:08 | Install        |    1 >
     2 | root               | 2016-08-19 08:57 | I, U           |   84
     1 | システム <未設定>        | 2016-01-01 22:59 | Install        |  297
history list
[root@BS-PUB-CENT7-01 ~]# yum history info 20
読み込んだプラグイン:fastestmirror
トランザクション ID : 20
開始時間            : Fri Sep  9 08:02:42 2016
開始 rpmdb          : 537:d92e64f2f7ef42c9916e57a0498d3ca3855c7d89
終了時間            :            08:02:43 2016 (1 秒)
終了 rpmdb          : 536:964566783155d79ae1fe21b57d5315a296d60eab
ユーザー            : root
終了コード          : 成功
コマンドライン      : groups remove security-tools
トランザクションの実行:
    インストール rpm-4.11.3-17.el7.x86_64                      @anaconda
    インストール yum-3.4.3-132.el7.centos.0.1.noarch           @anaconda
    インストール yum-plugin-fastestmirror-1.1.31-34.el7.noarch @anaconda
切り替えたパッケージ:
    削除 scap-security-guide-0.1.25-3.el7.centos.0.1.noarch @base
history info
[root@BS-PUB-CENT7-01 ~]# yum history undo 20
読み込んだプラグイン:fastestmirror
Undoing transaction 20, from Fri Sep  9 08:02:42 2016
    削除 scap-security-guide-0.1.25-3.el7.centos.0.1.noarch @base
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ scap-security-guide.noarch 0:0.1.25-3.el7.centos.0.1 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

===============================================================================================
 Package                     アーキテクチャー
                                            バージョン                      リポジトリー  容量
===============================================================================================
インストール中:
 scap-security-guide         noarch         0.1.25-3.el7.centos.0.1         base         672 k

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

総ダウンロード容量: 672 k
インストール容量: 11 M
Is this ok [y/d/N]: y
Downloading packages:
scap-security-guide-0.1.25-3.el7.centos.0.1.noarch.rpm                  | 672 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : scap-security-guide-0.1.25-3.el7.centos.0.1.noarch             1/1
  検証中                  : scap-security-guide-0.1.25-3.el7.centos.0.1.noarch             1/1

インストール:
  scap-security-guide.noarch 0:0.1.25-3.el7.centos.0.1

完了しました!

 

上の例では、一度行ったアンインストールを取り消した結果、パッケージを再度インストールしている。

 

16.対話的にコマンドを実行する

「yum shell」というコマンドを使うことで、yumに関する処理を対話的に行えるモードに切り替えることができる。

yum shell

20160910_084131000000

 

17.パッケージをインストールせず、rpmファイルだけダウンロードだけする

yumからインストールをするのではなく、ネットワークから隔離された環境で使うためのrpmパッケージがほしい場合は、依存するパッケージを含めてそれらをまとめてダウンロードすることもできる。

yum install --downloadonly パッケージ名
yum install --downloadonly パッケージ名 --downloaddir=PATH

 

ただ、ちょっと問題があってこのコマンドを実行したマシンにすでにインストール済の場合、パッケージのダウンロードができない。
この場合は、「yum-utils」にある「yumdownloader」もしくは「repotrack」コマンドを利用する。「yum-utils」はそのままyumでインストールができる。

yum install yum-utils

 

で、yumdownloader、repotrackがインストールできたら、以下のコマンドでダウンロードする。
特にrepotrackはすごく、インストール済のパッケージでも依存パッケージ(それこそsystemdすら)とってくる。ただ、なぜかvimなどの一部パッケージについてはとってこれなかった。
yumdownloaderはコマンドを実行したOSでインストール済みのパッケージは持ってこれないので、使い分けだろう。

yumdownloader --resolve パッケージ名
repotrack パッケージ名
[root@BS-PUB-CENT7-01 test]# repotrack httpd
Downloading acl-2.2.51-12.el7.x86_64.rpm
Downloading apr-1.4.8-3.el7.x86_64.rpm
Downloading apr-util-1.5.2-6.el7.x86_64.rpm
Downloading audit-libs-2.4.1-5.el7.x86_64.rpm
Downloading audit-libs-2.4.1-5.el7.i686.rpm
Downloading basesystem-10.0-7.el7.centos.noarch.rpm
Downloading bash-4.2.46-20.el7_2.x86_64.rpm
Downloading binutils-2.23.52.0.1-55.el7.x86_64.rpm
Downloading bzip2-libs-1.0.6-13.el7.x86_64.rpm
Downloading bzip2-libs-1.0.6-13.el7.i686.rpm
Downloading ca-certificates-2015.2.6-70.1.el7_2.noarch.rpm
Downloading centos-logos-70.0.6-3.el7.centos.noarch.rpm
Downloading centos-release-7-2.1511.el7.centos.2.10.x86_64.rpm
Downloading chkconfig-1.3.61-5.el7_2.1.x86_64.rpm
Downloading coreutils-8.22-15.el7_2.1.x86_64.rpm
Downloading cpio-2.11-24.el7.x86_64.rpm
Downloading cracklib-2.9.0-11.el7.x86_64.rpm
Downloading cracklib-2.9.0-11.el7.i686.rpm
Downloading cracklib-dicts-2.9.0-11.el7.x86_64.rpm
Downloading cryptsetup-libs-1.6.7-1.el7.x86_64.rpm
Downloading curl-7.29.0-25.el7.centos.x86_64.rpm
Downloading cyrus-sasl-lib-2.1.26-20.el7_2.x86_64.rpm
Downloading cyrus-sasl-lib-2.1.26-20.el7_2.i686.rpm
Downloading dbus-1.6.12-14.el7_2.x86_64.rpm
Downloading dbus-libs-1.6.12-14.el7_2.x86_64.rpm
Downloading device-mapper-1.02.107-5.el7_2.5.x86_64.rpm
Downloading device-mapper-libs-1.02.107-5.el7_2.5.i686.rpm
Downloading device-mapper-libs-1.02.107-5.el7_2.5.x86_64.rpm
Downloading diffutils-3.3-4.el7.i686.rpm
Downloading diffutils-3.3-4.el7.x86_64.rpm
Downloading dracut-033-360.el7_2.1.x86_64.rpm
Downloading elfutils-libelf-0.163-3.el7.x86_64.rpm
Downloading elfutils-libelf-0.163-3.el7.i686.rpm
Downloading elfutils-libs-0.163-3.el7.x86_64.rpm
Downloading elfutils-libs-0.163-3.el7.i686.rpm
Downloading expat-2.1.0-8.el7.x86_64.rpm
Downloading filesystem-3.2-20.el7.x86_64.rpm
Downloading findutils-4.5.11-5.el7.x86_64.rpm
Downloading gawk-4.0.2-4.el7.x86_64.rpm
Downloading glib2-2.42.2-5.el7.i686.rpm
Downloading glib2-2.42.2-5.el7.x86_64.rpm
Downloading glibc-2.17-106.el7_2.8.i686.rpm
Downloading glibc-2.17-106.el7_2.8.x86_64.rpm
Downloading glibc-common-2.17-106.el7_2.8.x86_64.rpm
Downloading gmp-6.0.0-12.el7_1.i686.rpm
Downloading gmp-6.0.0-12.el7_1.x86_64.rpm
Downloading grep-2.20-2.el7.x86_64.rpm
Downloading gzip-1.5-8.el7.x86_64.rpm
Downloading hardlink-1.0-19.el7.x86_64.rpm
Downloading httpd-2.4.6-40.el7.centos.4.x86_64.rpm
Downloading httpd-tools-2.4.6-40.el7.centos.4.x86_64.rpm
Downloading info-5.1-4.el7.x86_64.rpm
Downloading keyutils-libs-1.5.8-3.el7.i686.rpm
Downloading keyutils-libs-1.5.8-3.el7.x86_64.rpm
Downloading kmod-20-5.el7.x86_64.rpm
Downloading kmod-libs-20-5.el7.x86_64.rpm
Downloading kpartx-0.4.9-85.el7_2.5.x86_64.rpm
Downloading krb5-libs-1.13.2-12.el7_2.i686.rpm
Downloading krb5-libs-1.13.2-12.el7_2.x86_64.rpm
Downloading libacl-2.2.51-12.el7.x86_64.rpm
Downloading libacl-2.2.51-12.el7.i686.rpm
Downloading libattr-2.4.46-12.el7.i686.rpm
Downloading libattr-2.4.46-12.el7.x86_64.rpm
Downloading libblkid-2.23.2-26.el7_2.3.i686.rpm
Downloading libblkid-2.23.2-26.el7_2.3.x86_64.rpm
Downloading libcap-2.22-8.el7.x86_64.rpm
Downloading libcap-2.22-8.el7.i686.rpm
Downloading libcap-ng-0.7.5-4.el7.i686.rpm
Downloading libcap-ng-0.7.5-4.el7.x86_64.rpm
Downloading libcom_err-1.42.9-7.el7.x86_64.rpm
Downloading libcom_err-1.42.9-7.el7.i686.rpm
Downloading libcurl-7.29.0-25.el7.centos.i686.rpm
Downloading libcurl-7.29.0-25.el7.centos.x86_64.rpm
Downloading libdb-5.3.21-19.el7.i686.rpm
Downloading libdb-5.3.21-19.el7.x86_64.rpm
Downloading libdb-utils-5.3.21-19.el7.x86_64.rpm
Downloading libffi-3.0.13-16.el7.i686.rpm
Downloading libffi-3.0.13-16.el7.x86_64.rpm
Downloading libgcc-4.8.5-4.el7.x86_64.rpm
Downloading libgcc-4.8.5-4.el7.i686.rpm
Downloading libgcrypt-1.5.3-12.el7_1.1.x86_64.rpm
Downloading libgcrypt-1.5.3-12.el7_1.1.i686.rpm
Downloading libgpg-error-1.12-3.el7.i686.rpm
Downloading libgpg-error-1.12-3.el7.x86_64.rpm
Downloading libidn-1.28-4.el7.i686.rpm
Downloading libidn-1.28-4.el7.x86_64.rpm
Downloading libmount-2.23.2-26.el7_2.3.i686.rpm
Downloading libmount-2.23.2-26.el7_2.3.x86_64.rpm
Downloading libpwquality-1.2.3-4.el7.i686.rpm
Downloading libpwquality-1.2.3-4.el7.x86_64.rpm
Downloading libselinux-2.2.2-6.el7.x86_64.rpm
Downloading libselinux-2.2.2-6.el7.i686.rpm
Downloading libsemanage-2.1.10-18.el7.x86_64.rpm
Downloading libsepol-2.1.9-3.el7.i686.rpm
Downloading libsepol-2.1.9-3.el7.x86_64.rpm
Downloading libssh2-1.4.3-10.el7_2.1.x86_64.rpm
Downloading libssh2-1.4.3-10.el7_2.1.i686.rpm
Downloading libstdc++-4.8.5-4.el7.i686.rpm
Downloading libstdc++-4.8.5-4.el7.x86_64.rpm
Downloading libtasn1-3.8-2.el7.x86_64.rpm
Downloading libuser-0.60-7.el7_1.i686.rpm
Downloading libuser-0.60-7.el7_1.x86_64.rpm
Downloading libutempter-1.1.6-4.el7.x86_64.rpm
Downloading libutempter-1.1.6-4.el7.i686.rpm
Downloading libuuid-2.23.2-26.el7_2.3.x86_64.rpm
Downloading libuuid-2.23.2-26.el7_2.3.i686.rpm
Downloading libverto-0.2.5-4.el7.i686.rpm
Downloading libverto-0.2.5-4.el7.x86_64.rpm
Downloading libxml2-2.9.1-6.el7_2.3.x86_64.rpm
Downloading lua-5.1.4-14.el7.x86_64.rpm
Downloading mailcap-2.1.41-2.el7.noarch.rpm
Downloading ncurses-5.9-13.20130511.el7.x86_64.rpm
Downloading ncurses-base-5.9-13.20130511.el7.noarch.rpm
Downloading ncurses-libs-5.9-13.20130511.el7.x86_64.rpm
Downloading ncurses-libs-5.9-13.20130511.el7.i686.rpm
Downloading nspr-4.11.0-1.el7_2.x86_64.rpm
Downloading nspr-4.11.0-1.el7_2.i686.rpm
Downloading nss-3.21.0-9.el7_2.x86_64.rpm
Downloading nss-3.21.0-9.el7_2.i686.rpm
Downloading nss-softokn-3.16.2.3-14.2.el7_2.x86_64.rpm
Downloading nss-softokn-3.16.2.3-14.2.el7_2.i686.rpm
Downloading nss-softokn-freebl-3.16.2.3-14.2.el7_2.i686.rpm
Downloading nss-softokn-freebl-3.16.2.3-14.2.el7_2.x86_64.rpm
Downloading nss-sysinit-3.21.0-9.el7_2.x86_64.rpm
Downloading nss-tools-3.21.0-9.el7_2.x86_64.rpm
Downloading nss-util-3.21.0-2.2.el7_2.i686.rpm
Downloading nss-util-3.21.0-2.2.el7_2.x86_64.rpm
Downloading openldap-2.4.40-9.el7_2.i686.rpm
Downloading openldap-2.4.40-9.el7_2.x86_64.rpm
Downloading openssl-libs-1.0.1e-51.el7_2.5.x86_64.rpm
Downloading openssl-libs-1.0.1e-51.el7_2.5.i686.rpm
Downloading p11-kit-0.20.7-3.el7.i686.rpm
Downloading p11-kit-0.20.7-3.el7.x86_64.rpm
Downloading p11-kit-trust-0.20.7-3.el7.x86_64.rpm
Downloading pam-1.1.8-12.el7_1.1.x86_64.rpm
Downloading pam-1.1.8-12.el7_1.1.i686.rpm
Downloading pcre-8.32-15.el7_2.1.i686.rpm
Downloading pcre-8.32-15.el7_2.1.x86_64.rpm
Downloading pkgconfig-0.27.1-4.el7.x86_64.rpm
Downloading pkgconfig-0.27.1-4.el7.i686.rpm
Downloading popt-1.13-16.el7.i686.rpm
Downloading popt-1.13-16.el7.x86_64.rpm
Downloading procps-ng-3.3.10-5.el7_2.x86_64.rpm
Downloading procps-ng-3.3.10-5.el7_2.i686.rpm
Downloading qrencode-libs-3.4.1-3.el7.x86_64.rpm
Downloading readline-6.2-9.el7.i686.rpm
Downloading readline-6.2-9.el7.x86_64.rpm
Downloading rpm-4.11.3-17.el7.x86_64.rpm
Downloading rpm-libs-4.11.3-17.el7.x86_64.rpm
Downloading sed-4.2.2-5.el7.x86_64.rpm
Downloading setup-2.8.71-6.el7.noarch.rpm
Downloading shadow-utils-4.1.5.1-18.el7.x86_64.rpm
Downloading shared-mime-info-1.1-9.el7.x86_64.rpm
Downloading sqlite-3.7.17-8.el7.i686.rpm
Downloading sqlite-3.7.17-8.el7.x86_64.rpm
Downloading systemd-219-19.el7_2.12.x86_64.rpm
Downloading systemd-libs-219-19.el7_2.12.x86_64.rpm
Downloading systemd-libs-219-19.el7_2.12.i686.rpm
Downloading tzdata-2016f-1.el7.noarch.rpm
Downloading ustr-1.0.4-16.el7.x86_64.rpm
Downloading util-linux-2.23.2-26.el7_2.3.x86_64.rpm
Downloading util-linux-2.23.2-26.el7_2.3.i686.rpm
Downloading xz-5.1.2-12alpha.el7.x86_64.rpm
Downloading xz-libs-5.1.2-12alpha.el7.x86_64.rpm
Downloading xz-libs-5.1.2-12alpha.el7.i686.rpm
Downloading zlib-1.2.7-15.el7.x86_64.rpm
Downloading zlib-1.2.7-15.el7.i686.rpm

 

18.ローカルにあるrpmファイルからインストール・アップデートを行う

前にこちらにも書いたのだが、ローカルにあるrpmファイルをインストールする際、rpmコマンドからだと依存関係に気を付けて順番通りにインストールするのは難しい。
yumのlocalinstallなら、ローカルのrpmファイルをふつうにインストールすることができる(ただし、すべてのパッケージを引数として指定する必要はある。)。

yum localinstall --nogpgcheck rpmパッケージ1 rpmパッケージ2 ...

 

また、ローカルのrpmファイルからパッケージのアップデートをする場合は、「localupdate」を用いる。

yum localupdate --nogpgcheck rpmパッケージ ...

 

19.パッケージに変更を加える前にファイルシステムのスナップショットを取得する

ファイルシステムがLVMかBtrfsならば、「yum-plugin-fs-snapshot」パッケージをインストールすることで、yumコマンドが何か変更を加える前に自動的にスナップショットを取得させるようにできる。
まず、以下のコマンドで「yum-plugin-fs-snapshot」をインストール。

yum install yum-plugin-fs-snapshot

 

次に、設定ファイルを編集して機能を有効にする。

sed -i '/[lvm]/,$s/^enabled = 0/enabled = 1/g;/#lvcreate_size_args/s/#//g' /etc/yum/pluginconf.d/fs-snapshot.conf

 

あとは、yumで変更処理を行うだけで勝手にスナップショットを取得してくれるようになる。
VGの空き領域がないとエラーになるので、なるべく余裕を持った容量を用意しておこう。

[root@BS-PUB-CENT7-01 test]# yum install httpd
読み込んだプラグイン:fastestmirror, fs-snapshot
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ httpd.x86_64 0:2.4.6-40.el7.centos.4 を インストール
--> 依存性の処理をしています: httpd-tools = 2.4.6-40.el7.centos.4 のパッケージ: httpd-2.4.6-40.el7.centos.4.x86_64
--> 依存性の処理をしています: libaprutil-1.so.0()(64bit) のパッケージ: httpd-2.4.6-40.el7.centos.4.x86_64
--> 依存性の処理をしています: libapr-1.so.0()(64bit) のパッケージ: httpd-2.4.6-40.el7.centos.4.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ apr.x86_64 0:1.4.8-3.el7 を インストール
---> パッケージ apr-util.x86_64 0:1.5.2-6.el7 を インストール
---> パッケージ httpd-tools.x86_64 0:2.4.6-40.el7.centos.4 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

===============================================================================================
 Package              アーキテクチャー
                                      バージョン                        リポジトリー      容量
===============================================================================================
インストール中:
 httpd                x86_64          2.4.6-40.el7.centos.4             updates          2.7 M
依存性関連でのインストールをします:
 apr                  x86_64          1.4.8-3.el7                       base             103 k
 apr-util             x86_64          1.5.2-6.el7                       base              92 k
 httpd-tools          x86_64          2.4.6-40.el7.centos.4             updates           83 k

トランザクションの要約
===============================================================================================
インストール  1 パッケージ (+3 個の依存関係のパッケージ)

合計容量: 3.0 M
インストール容量: 9.9 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
fs-snapshot: snapshotting / (/dev/centos/root): root_yum_20160910105209
  インストール中          : apr-1.4.8-3.el7.x86_64                                         1/4
  インストール中          : apr-util-1.5.2-6.el7.x86_64                                    2/4
  インストール中          : httpd-tools-2.4.6-40.el7.centos.4.x86_64                       3/4
  インストール中          : httpd-2.4.6-40.el7.centos.4.x86_64                             4/4
  検証中                  : httpd-tools-2.4.6-40.el7.centos.4.x86_64                       1/4
  検証中                  : apr-util-1.5.2-6.el7.x86_64                                    2/4
  検証中                  : httpd-2.4.6-40.el7.centos.4.x86_64                             3/4
  検証中                  : apr-1.4.8-3.el7.x86_64                                         4/4

インストール:
  httpd.x86_64 0:2.4.6-40.el7.centos.4

依存性関連をインストールしました:
  apr.x86_64 0:1.4.8-3.el7                             apr-util.x86_64 0:1.5.2-6.el7
  httpd-tools.x86_64 0:2.4.6-40.el7.centos.4

完了しました!
[root@BS-PUB-CENT7-01 test]# yum fssnap
読み込んだプラグイン:fastestmirror, fs-snapshot
Have 1 snapshots, using 4.6   space, from 1 origins.
fssnap summary done
[root@BS-PUB-CENT7-01 test]# yum fssnap list
読み込んだプラグイン:fastestmirror, fs-snapshot
List of 1 snapshosts:
Snapshot                         容量   Used   Free Origin Tags
centos/root_yum_20160910105209   44 M   4.7%    0     root yum_20160910105209
fssnap list done

 

実践!  CentOS 7 サーバー徹底構築 実践! CentOS 7 サーバー徹底構築

Linuxコンソール上で使えるバイナリエディタ「hexedit」

$
0
0

LinuxでCLIで使えるバイナリエディタを調べてたら、「hexedit」が結構使い勝手が良かったので忘れないように残しておく。
インストールは以下のコマンドで行える。

yum install hexedit #CentOS などRHEL系の場合
apt-get install hexedit # Debian/Ubuntu系の場合

インストールした後は、以下のコマンドでバイナリを編集できる。

hexedit バイナリファイル

20160911_172157000000

 

編集時の操作としては、とりあえず以下のショートカットキーを覚えておけば問題ないだろう。

  • F1 … ヘルプ
  • F2 … 保存
  • / … 検索
  • Ctrl + X … 保存して終了
  • Ctrl + C … 保存せずに終了

 

なんとなく、エディタとしてはvimとかよりnanoに似た操作感がある。
ちょっとバイナリをいじりたい、といったときには便利な感じだ。

0と1のコンピュータ世界 バイナリで遊ぼう! 0と1のコンピュータ世界 バイナリで遊ぼう!

Redmineのパスワード管理プラグイン「Valut」を使ってみる

$
0
0

チームで仕事をしていると、ドメインのレジストリやら契約しているWebサービスの管理画面にアクセスするためのIDやパスワードを共有しておく必要がある。
今まで仕事をしてて、よくExcelとかで管理してることが多かったのだけど、さすがにこの時代にExcelで管理というのはどうなのだろう…というのがあって、いろいろと管理ツールを探していたのだが、どうやらRedmineにパスワード管理用のプラグインとして「Valut」というのがあるようなので、入れてみることにした(redmine.orgでの紹介ページはこちら)。
なお、Redmineについてはインストールがいろいろと面倒くさいので、TurnkeyLinuxのものを使っている。

1.プラグインのインストール

インストールは簡単で、sshでアクセスして以下のコマンドを実行していくだけだ。

cd /var/www/redmine/plugins
wget https://noshutdown.ru/download/1063/vault.tar
tar xvf vault.tar
bundle install --without development test
rake redmine:plugins:migrate RAILS_ENV=production
systemctl restart apache2

 

インストール完了後、Webブラウザでアクセスするとプラグインが追加されていることが確認できる。

20160911_204352000000

 

2.初期設定

プラグイン一覧で「設定」をクリックして管理画面を開いたら、登録したパスワードなどを暗号化するためのパスワードを入力し、「Use Redmine Encryption」にチェックを入れて適用する。

20160911_205005000000

 

適用後、コンソールで以下のコマンドを実行する。

echo 'Rails.application.config.assets.precompile += %w( zeroclipboard.js )' >> /var/www/redmine/config/initializers/assets.rb
echo '  database_cipher_key: Redmineの暗号化パスワード' >> /var/www/redmine/config/configuration.yml
chown www-data:www-data /var/www/redmine/keys/

適用後、パスワードリストを管理するプロジェクトの設定画面で「Keys」にチェックを入れて「保存」。

20160911_205344000000

 

3.使ってみる

さて、Redmineのプロジェクトで機能の有効化ができたら、「Keys」タブを開いてみよう。
早速新しいパスワードを記録する場合は「New Keys」をクリックする。

20160911_210242000000

 

ID/パスワードのほか、鍵ファイルも設置できるようだ。
入力が終わったら保存する。

20160911_210518000000

 

登録されたリストにあるリンクをクリックすることで、鍵ファイルをダウンロードしたりパスワードをコピーしたりすることができる。

20160911_211519000000

 

もちろん、プロジェクトに参加していないユーザでは「Keys」タブが表示されないので情報が見れないようになっている。

20160911_211648000000

 

うーむ…Excelで管理するよりもよほどいいんじゃないだろうか。

すべてわかるセキュリティ大全2017 すべてわかるセキュリティ大全2017

CentOS 7にチームでのパスワード・鍵管理に便利な「RatticDB」をインストールする

$
0
0

仕事で、チームでのパスワードや鍵管理の方法について調べていて、それ専用のツールとして作られた「RatticDB」なるものを見かけたので、検証として使ってみることにした。
今回は、CentOS 7にこのツールをインストールして使ってみることにする。手順についてはこちらを参考に進め、DB用にデバイスを暗号化した領域を設ける(手順内で暗号化する)。

1.前提パッケージのインストール・設定

まずは、前提となるパッケージのインストールから…の前に、とりあえずSELinuxを無効化しておく。

setenforce 0
sed -i.bak "/SELINUX/s/enforcing/disabled/g" /etc/selinux/config

 

前提パッケージの導入のため、以下のコマンドを実行する。

yum install -y epel-release
yum update -y
yum upgrade -y
yum groupinstall -y development web-server
yum install -y gcc openldap-devel bzip2-devel sqlite-devel libxml2-devel libxslt-devel wget openssl-devel python-pip cryptsetup mod_wsgi vim tk-devel ncurses-devel readline-devel mysql-devel ntp httpd-devel python-devel mariadb-server mariadb
systemctl start ntpd
systemctl enable ntpd
systemctl start mariadb
systemctl enable mariadb

 

2.DBのセットアップ

次に、インストールしたMariaDBで最低限のセキュリティ設定を行う。

mysql_secure_installation
[root@BS-PUB-CENT7-01 ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: 行 379: find_mysql_client: コマンドが見つかりません

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

 

DBおよびユーザの作成を行う。

mysql -u root -p \
      -e 'CREATE DATABASE rattic;
          CREATE USER rattic@localhost identified by "RatticDB接続用パスワード";
          GRANT ALL ON rattic.* TO rattic;'

 

3.デバイスの暗号化&DBディレクトリの移動

次に、DBを格納するデバイスが暗号化されていないのはまずいので、ディスクを追加して暗号化する。

cryptsetup luksFormat /dev/sdb1
cryptsetup luksOpen /dev/sdb1 rattic_encrypted
pvcreate /dev/mapper/rattic_encrypted
vgcreate rattic_VG /dev/mapper/rattic_encrypted
lvcreate -l 100%VG -n rattic_LV rattic_VG
mkfs.ext4 /dev/mapper/rattic_VG-rattic_LV
mkdir -p /opt/apps/mysql
mount /dev/mapper/rattic_VG-rattic_LV /opt/apps/mysql
[root@BS-PUB-CENT7-01 ~]# cryptsetup luksFormat /dev/sdb1

WARNING!
========
This will overwrite data on /dev/sdb1 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter passphrase:
Verify passphrase:
[root@BS-PUB-CENT7-01 ~]# cryptsetup luksOpen /dev/sdb1 rattic_encrypted
Enter passphrase for /dev/sdb1:
[root@BS-PUB-CENT7-01 ~]# pvcreate /dev/mapper/rattic_encrypted
  Physical volume "/dev/mapper/rattic_encrypted" successfully created
[root@BS-PUB-CENT7-01 ~]# vgcreate rattic_VG /dev/mapper/rattic_encrypted
  Volume group "rattic_VG" successfully created
[root@BS-PUB-CENT7-01 ~]# lvcreate -l 100%VG -n rattic_LV rattic_VG
  Logical volume "rattic_LV" created.
[root@BS-PUB-CENT7-01 ~]# mkfs.ext4 /dev/mapper/rattic_VG-rattic_LV
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3276800 inodes, 13106176 blocks
655308 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2162163712
400 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

[root@BS-PUB-CENT7-01 ~]# mkdir -p /opt/apps/mysql
[root@BS-PUB-CENT7-01 ~]# mount /dev/mapper/rattic_VG-rattic_LV /opt/apps/mysql

 

デバイスを暗号化したら、先ほどインストールしたMariaDBの場所を移動する。

systemctl stop mariadb
cp -r /var/lib/mysql/* /opt/apps/mysql
mv /var/lib/mysql /var/lib/mysql.old
ln -s /opt/apps/mysql /var/lib/mysql
chown -R mysql:mysql /opt/apps/mysql/
sed -i.bk 's|/var/lib|/opt/apps|g' /etc/my.cnf
systemctl start mariadb

4.RatticDBをインストールする

さて、それではRatticDBをインストールしよう。
まず、以下のコマンドでソースのダウンロードと配置、その他細かい処理を行う。

cd /tmp
wget https://github.com/tildaslash/RatticWeb/archive/v1.3.1.tar.gz
tar -xzvf v1.3.1.tar.gz
mv RatticWeb-1.3.1 /opt/apps/RatticWeb
cd /opt/apps/RatticWeb
pip install -r requirements-mysql.txt -r requirements-dev.txt
mkdir -p /opt/apps/RatticWeb/static
useradd -c "RatticWeb" -m rattic
chown -R rattic:rattic /opt/apps/RatticWeb

 

次に、Ratticの設定ファイルを新規作成、編集する。

●/opt/apps/RatticWeb/conf/local.cfg

[ratticweb]
debug = False
secretkey = Ratticシークレットパスワード
hostname = ratticdb

[filepaths]
static = /opt/apps/RatticWeb/static

[database]
engine = django.db.backends.mysql
name = rattic
user = rattic
password = RatticDB接続用パスワード
host = localhost
port = 3306

 

ファイル作成後、所有者をratticにしておく。
また、環境にもよると思うが、念のためこちらの対応を行っておく。

chown rattic:rattic /opt/apps/RatticWeb/conf/local.cfg
rm -rf /usr/lib/python2.7/site-packages/kombu/transport/django/migrations/
rm -rf /usr/lib/python2.7/site-packages/djcelery/migrations/
mv /usr/lib/python2.7/site-packages/kombu/transport/django/{south_migrations,migrations}
mv /usr/lib/python2.7/site-packages/djcelery/{south_migrations,migrations}

 

最後に、以下のようにスクリプトを実行してデータベースへの書き込みなどの処理を行わせる。

cd /opt/apps/RatticWeb/
./manage.py syncdb --noinput
./manage.py migrate --all
./manage.py collectstatic -c --noinput
./manage.py demosetup

 

5.Apacheの設定

最後に、Apacheの設定をしておく。
以下のようなファイルを作成する。

●/etc/httpd/conf.d/rattic.conf

<VirtualHost *:80>
    ServerName ratticdb
    ServerAlias ratticdb
    Redirect permanent / https://ratticdb
</VirtualHost>
    Alias /robots.txt /opt/apps/RatticWeb/static/robots.txt
    Alias /favicon.ico /opt/apps/RatticWeb/static/favicon.ico
    AliasMatch ^/([^/]*\.css) /opt/apps/RatticWeb/static/styles/$1
    Alias /media/ /opt/apps/RatticWeb/media/
    Alias /static/ /opt/apps/RatticWeb/static/
<Directory /opt/apps/RatticWeb/static>
    #Order deny,allow
    #Allow from all
    Require all granted
</Directory>
<Directory /opt/apps/RatticWeb/media>
    #Order deny,allow
    #Allow from all
    Require all granted
</Directory>
#WSGISocketPrefix run/wsgi
WSGIScriptAlias / /opt/apps/RatticWeb/ratticweb/wsgi.py
WSGIPassAuthorization On
WSGIDaemonProcess rattic processes=2 threads=25 home=/opt/apps/RatticWeb/ python-path=/opt/apps/RatticWeb display-name=%{GROUP}
WSGIProcessGroup rattic
<Directory /opt/apps/RatticWeb/ratticweb>
    <Files wsgi.py>
        #Order deny,allow
        #Allow from all
        Require all granted
    </Files>
</Directory>

 

作業完了後、サービス再起動とファイアウォールのポートを開ける。

systemctl restart httpd
iptables -I INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT

6.実際に使ってみる

さて、それでは実際にブラウザからアクセスしてみよう。
「https://サーバ名」にアクセスし、ログインしてみよう。初期のID/PWは「admin/rattic」となっている。

20160912_003938000000

 

ログインすると、パスワード一覧のページが表示される。

20160912_004041000000

 

あとは、ユーザやその所属するグループを作成し、それらに応じた鍵の暗号化処理を行わせて、随時鍵を登録していけばよい。そんなに迷うようなことはないだろう。
まずは、用意されているデモページを触ってみることをお勧めする。

一応、LDAPとの連携もできるようなので、悪くないと思う。
また、(あんまりメンテナンスされてなさそうだけど)CLIのツールも用意されてたりするので、結構使えそうな気がする。

 

IT管理者のための情報セキュリティガイド (NextPublishing) IT管理者のための情報セキュリティガイド (NextPublishing)

CentOS7にチームでのパスワード管理マネージャ「TeamPass」をインストールする

$
0
0

チームでのパスワード・鍵ファイルの管理に使えそうなツールを探していたところ、WebベースでAD連携もできるパスワード管理ツール「TeamPass」というものを見かけたので、インストールして少し触ってみることにした。インストール先にはCentOS 7を用いる。

1.前提パッケージのインストール

まずは前提となるパッケージのインストール。
以下のコマンドを実行する。

yum install -y epel-release
yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
yum install -y --enablerepo=rpmforge,remi,remi-php55 httpd mariadb mariadb-server php php-mysql php-mcrypt php-json php-mbstring php-ldap php-bcmath php-iconv php-xml php-gd wget
systemctl start mariadb
systemctl enable mariadb
sed -i '/max_execution_time/s/30/60/g' /etc/php.ini

 

MariaDBで、最低限のセキュリティ設定を行っておく。

mysql_secure_installation

 

事前に、データベースの作成を行っておく。

mysql -u root -p \
      -e 'CREATE DATABASE teampass;
          CREATE USER teampass@localhost identified by "P@ssw0rd";
          GRANT ALL ON teampass.* TO teampass;'

 

最後に、検証なのでFirewalldとSELinuxについては適切な設定ではなく、プロセスの停止。
そのうえでhttpdの起動設定を行う。

setenforce 0
sed -i.bak "/SELINUX/s/enforcing/disabled/g" /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
systemctl start httpd
systemctl enable httpd

 

2.TeamPassのインストール

次に、TeamPassのインストールを行う。
まず、こちらから最新版のダウンロードリンクを調べておく。
とりあえず今回は2.1.26を指定する。

cd /opt
wget https://github.com/nilsteampassnet/TeamPass/archive/2.1.26.19.tar.gz
tar xzvf 2.1.26.19.tar.gz
ln -s /opt/TeamPass-* /var/www/html/teampass
chown -R apache:apache /opt/TeamPass-*

3.TeamPassの初期設定

ブラウザで、「http://IPアドレス/teampass/」にアクセスする。
Welcomeページが表示されるので、そのまま「Next」で次のページへ。

20160913_000405000000

 

「Server checks」で何も問題がなければ、「LAUNCH」をクリックする。
何も問題がなければ「NEXT」に変わるのでそのまま進む。

20160913_000415000000

20160913_001825000000

 

DBへの接続情報を設定する。
先ほど作成したDB、ユーザやパスワードの情報を入力して「LAUNCH」をクリック。
接続に問題なければ「NEXT」に変わるのでそのまま進む。

20160913_002022000000

20160913_002129000000

 

TeamPassにおける暗号化や管理者ユーザのパスワード設定を行う。
ランダムな値を払い出すならば「Generate」をクリックすればよい。「LAUNCH」クリック後は今までと同じなので割愛。

20160913_002414000000

 

テーブル作成処理が行われる。
すべて終わったらそのまま次へ。

20160913_002554000000

 

処理がすべて完了したら、そのまま進めていく。

20160913_002654000000

20160913_002702000000

20160913_002705000000

 

4.TeamPassを使ってみる

インストール処理がすべて終わったら、ログイン画面が表示される。
あとは、IDはadmin、パスワードは先ほど設定した管理者パスワードでログインする。
一応、右上の国旗のトコを選択したら日本語にもできるみたいだけど…なんか翻訳が怪しいので英語のまま進める。

20160913_003008000000

 

ログイン直後の画面。
フォルダを作る必要があるようなので、上のフォルダのアイコンをクリックして作成する。

20160913_003353000000

20160913_003536000000

 

Rollを作成するため、フォルダの隣にある帽子アイコンをクリックして作成する。

20160913_003712000000

 

ロール作成後、設定からメンテナンスモードを無効化することで使えるようになる。

20160913_003922000000

 

で、いろいろと触ってみた感想だが…
うーん…正直、RatticDBのほうがいろいろと見やすくて操作や設定も簡単だった気がする。
Redmineがある環境であれば、Valutでもいいかも…

パスワードを共有するという機能だけなら、正直ちゃんとしたユーザであればアクセスしやすい方がいいわけで、どこに何があるんだかわかりにくいことでセキュリティ性を上げてるような印象を受けるというか…別のものを使える状況であれば、あまりいらないかなぁ…というのが感想。わざわざ新しいサーバ立ち上げてまで構築するかといわれると、ちょっと悩む。
LDAP連携とかもできるし、ワンタイムパスワードでの認証も可能など、機能はいっぱいあるみたいなんだけど。もうちょっとUIが見やすくなるとうれしいなぁ…

 

IT管理者のための情報セキュリティガイド (NextPublishing) IT管理者のための情報セキュリティガイド (NextPublishing)

CentOS 7にPython3.4・pip3をインストールする

WordPressの脆弱性スキャンツール『wpscan』をUbuntu Server 16.04にインストールしてスキャンを行う

$
0
0

ブログを書く場合、かなりの確率でWordPressを利用していることが多いだろう。
ただ、利用者が多いということは、それだけ攻撃の標的になりやすくなるということでもある。

そうなるとちゃんとセキュリティの設定ができてるか、定期的に見直す必要がある。
そんなときに便利なのが、WordPress用の脆弱性スキャンツール『wpscan』だ。これは、外部から対象のWordPressブログに対してスキャンを実施し、脆弱性があるかどうかを確認するというものだ。
(当たり前だが、もちろん自分のブログ以外にこのツールを使用するとアタックとして扱われるので注意するように)

今回は、Ubuntu Server 16.04にこのツールをインストールし、実際にWordPressに対してスキャンを実施する。
なお、Kali LinuxPentooBlackArchLinuxといったセキュリティテスト用のディストリビューションには最初からインストールされているので、ただこのツールを使いたいだけであればそちらを利用すると楽だ。

1.前提パッケージのインストール

wpscanをインストールするには、以下の前提パッケージが必要となる。

  • Ruby >= 2.1.9 – Recommended: 2.3.1
  • Curl >= 7.21 – Recommended: latest – FYI the 7.29 has a segfault
  • RubyGems – Recommended: latest
  • Git

なので、以下のコマンドで前提となるパッケージをインストールをしておく。

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git ruby-dev ruby libxml2 libxml2-dev libxslt1-dev libcurl4-gnutls-dev ruby-dev build-essential

 

2.wpscanのインストール

次に、wpscanのインストールを行う。

cd /opt
sudo git clone https://github.com/wpscanteam/wpscan.git

 

gemインストールを行う。

cd wpscan
sudo gem install bundler && sudo bundle install --without test

 

最後に、脆弱性についてのアップデートを実施する。

sudo ruby wpscan.rb--update
blacknon@BS-PUB-UBUNTU-01:/opt/wpscan$ sudo ruby wpscan.rb --update
_______________________________________________________________
        __          _______   _____
        \ \        / /  __ \ / ____|
         \ \  /\  / /| |__) | (___   ___  __ _ _ __
          \ \/  \/ / |  ___/ \___ \ / __|/ _` | '_ \
           \  /\  /  | |     ____) | (__| (_| | | | |
            \/  \/   |_|    |_____/ \___|\__,_|_| |_|

        WordPress Security Scanner by the WPScan Team
                       Version 2.9.1
          Sponsored by Sucuri - https://sucuri.net
   @_WPScan_, @ethicalhack3r, @erwan_lr, pvdl, @_FireFart_
_______________________________________________________________

[i] Updating the Database ...
[i] Update completed.

 

これで、wpscanのインストールができた。
rubyコマンドから利用することができるようになる。

3.スキャンを行う

インストールができたら、実際にスキャンを行ってみよう。

 

3-1.情報の取得のみ行う

侵入は行わず、対象のWordPressブログの情報だけを取得する場合は以下のコマンドを実行する。

sudo ruby wpscan.rb --url http://対象URL

20160914_103724000000

blacknon@BS-PUB-UBUNTU-01:/opt/wpscan$ sudo ruby wpscan.rb --url http://bs-pub-wordpress-01.blacknon.local
_______________________________________________________________
        __          _______   _____
        \ \        / /  __ \ / ____|
         \ \  /\  / /| |__) | (___   ___  __ _ _ __
          \ \/  \/ / |  ___/ \___ \ / __|/ _` | '_ \
           \  /\  /  | |     ____) | (__| (_| | | | |
            \/  \/   |_|    |_____/ \___|\__,_|_| |_|

        WordPress Security Scanner by the WPScan Team
                       Version 2.9.1
          Sponsored by Sucuri - https://sucuri.net
   @_WPScan_, @ethicalhack3r, @erwan_lr, pvdl, @_FireFart_
_______________________________________________________________

[+] URL: http://bs-pub-wordpress-01.blacknon.local/
[+] Started: Wed Sep 14 10:36:36 2016

[+] robots.txt available under: 'http://bs-pub-wordpress-01.blacknon.local/robots.txt'
[+] Interesting entry from robots.txt: http://bs-pub-wordpress-01.blacknon.local/wp-admin/admin-ajax.php
[!] The WordPress 'http://bs-pub-wordpress-01.blacknon.local/readme.html' file exists exposing a version number
[+] Interesting header: LINK: <http://bs-pub-wordpress-01.blacknon.local/wp-json/>; rel="https://api.w.org/"
[+] Interesting header: SERVER: nginx/1.6.3
[+] Interesting header: X-POWERED-BY: PHP/7.0.10
[+] XML-RPC Interface available under: http://bs-pub-wordpress-01.blacknon.local/xmlrpc.php

[+] WordPress version 4.6.1 (Released on 2016-09-07) identified from advanced fingerprinting, meta generator, readme, links opml, stylesheets numbers

[+] WordPress theme in use: twentysixteen - v1.3

[+] Name: twentysixteen - v1.3
 |  Latest version: 1.3 (up to date)
 |  Location: http://bs-pub-wordpress-01.blacknon.local/wp-content/themes/twentysixteen/
 |  Readme: http://bs-pub-wordpress-01.blacknon.local/wp-content/themes/twentysixteen/readme.txt
 |  Style URL: http://bs-pub-wordpress-01.blacknon.local/wp-content/themes/twentysixteen/style.css
 |  Theme Name: Twenty Sixteen
 |  Theme URI: https://wordpress.org/themes/twentysixteen/
 |  Description: Twenty Sixteen is a modernized take on an ever-popular WordPress layout ― the horizontal masthe...
 |  Author: the WordPress team
 |  Author URI: https://wordpress.org/

[+] Enumerating plugins from passive detection ...
[+] No plugins found

[+] Finished: Wed Sep 14 10:36:41 2016
[+] Requests Done: 43
[+] Memory used: 10.762 MB
[+] Elapsed time: 00:00:05

 

3-2.ログインユーザ一覧を取得する

WordPressへのログインユーザ一覧を取得する場合は、以下のようにコマンドを実行する。

sudo ruby wpscan.rb --url http://対象URL -e u
blacknon@BS-PUB-UBUNTU-01:/opt/wpscan$ sudo ruby wpscan.rb --url http://bs-pub-wordpress-01.blacknon.local -e u
_______________________________________________________________
        __          _______   _____
        \ \        / /  __ \ / ____|
         \ \  /\  / /| |__) | (___   ___  __ _ _ __
          \ \/  \/ / |  ___/ \___ \ / __|/ _` | '_ \
           \  /\  /  | |     ____) | (__| (_| | | | |
            \/  \/   |_|    |_____/ \___|\__,_|_| |_|

        WordPress Security Scanner by the WPScan Team
                       Version 2.9.1
          Sponsored by Sucuri - https://sucuri.net
   @_WPScan_, @ethicalhack3r, @erwan_lr, pvdl, @_FireFart_
_______________________________________________________________

[+] URL: http://bs-pub-wordpress-01.blacknon.local/
[+] Started: Wed Sep 14 10:48:37 2016

[+] robots.txt available under: 'http://bs-pub-wordpress-01.blacknon.local/robots.txt'
[+] Interesting entry from robots.txt: http://bs-pub-wordpress-01.blacknon.local/wp-admin/admin-ajax.php
[!] The WordPress 'http://bs-pub-wordpress-01.blacknon.local/readme.html' file exists exposing a version number
[+] Interesting header: LINK: <http://bs-pub-wordpress-01.blacknon.local/wp-json/>; rel="https://api.w.org/"
[+] Interesting header: SERVER: nginx/1.6.3
[+] Interesting header: X-POWERED-BY: PHP/7.0.10
[+] XML-RPC Interface available under: http://bs-pub-wordpress-01.blacknon.local/xmlrpc.php

[+] WordPress version 4.6.1 (Released on 2016-09-07) identified from advanced fingerprinting, meta generator, readme, links opml, stylesheets numbers

[+] WordPress theme in use: twentysixteen - v1.3

[+] Name: twentysixteen - v1.3
 |  Latest version: 1.3 (up to date)
 |  Location: http://bs-pub-wordpress-01.blacknon.local/wp-content/themes/twentysixteen/
 |  Readme: http://bs-pub-wordpress-01.blacknon.local/wp-content/themes/twentysixteen/readme.txt
 |  Style URL: http://bs-pub-wordpress-01.blacknon.local/wp-content/themes/twentysixteen/style.css
 |  Theme Name: Twenty Sixteen
 |  Theme URI: https://wordpress.org/themes/twentysixteen/
 |  Description: Twenty Sixteen is a modernized take on an ever-popular WordPress layout ― the horizontal masthe...
 |  Author: the WordPress team
 |  Author URI: https://wordpress.org/

[+] Enumerating plugins from passive detection ...
[+] No plugins found

[+] Enumerating usernames ...
[+] Identified the following 2 user/s:
    +----+----------+----------+
    | Id | Login    | Name     |
    +----+----------+----------+
    | 1  | blacknon | blacknon |
    | 2  | test     | test     |
    +----+----------+----------+

[+] Finished: Wed Sep 14 10:48:44 2016
[+] Requests Done: 57
[+] Memory used: 12.027 MB
[+] Elapsed time: 00:00:07

 

確かに、ユーザ名の一覧が見れているようだ。
結構怖いなぁ…

 

3-3.ディクショナリアタック(辞書攻撃)によるパスワードの取得

ユーザ名がわかったら、ディクショナリアタック(辞書攻撃)でのログインが行えるかどうかのテストが行える。
この際、コマンド実行時に辞書ファイルを指定してやる。つまり、よく攻撃者が使うであろう辞書にパスワードが乗ってなければ(推測しやすい、キーワードなどを含む脆弱なパスワードでなければ)、この攻撃の影響は受けにくいということになる。今回は、テストのために意図的に脆弱なパスワード(password)を設定している。

sudo ruby wpscan.rb -u http://対象URL/ -w パスワードファイル(辞書ファイル) -U ユーザ名

 

なお、よく使われるキーワードを持つ辞書ファイルだが、John the Ripperの開発元であるOpenWallの配布している無料のパスワードリストでいいだろう。
以下のコマンドでダウンロード、展開しておく。

wget http://download.openwall.net/pub/wordlists/all.gz
gunzip all.gz
blacknon@BS-PUB-UBUNTU-01:/opt/wpscan$ sudo ruby wpscan.rb -u http://bs-pub-wordpress-01.blacknon.local -w all -U blacknon
[sudo] blacknon のパスワード:
_______________________________________________________________
        __          _______   _____
        \ \        / /  __ \ / ____|
         \ \  /\  / /| |__) | (___   ___  __ _ _ __
          \ \/  \/ / |  ___/ \___ \ / __|/ _` | '_ \
           \  /\  /  | |     ____) | (__| (_| | | | |
            \/  \/   |_|    |_____/ \___|\__,_|_| |_|

        WordPress Security Scanner by the WPScan Team
                       Version 2.9.1
          Sponsored by Sucuri - https://sucuri.net
   @_WPScan_, @ethicalhack3r, @erwan_lr, pvdl, @_FireFart_
_______________________________________________________________

[+] URL: http://bs-pub-wordpress-01.blacknon.local/
[+] Started: Thu Sep 15 08:35:02 2016

[+] robots.txt available under: 'http://bs-pub-wordpress-01.blacknon.local/robots.txt'
[+] Interesting entry from robots.txt: http://bs-pub-wordpress-01.blacknon.local/wp-admin/admin-ajax.php
[!] The WordPress 'http://bs-pub-wordpress-01.blacknon.local/readme.html' file exists exposing a version number
[+] Interesting header: LINK: <http://bs-pub-wordpress-01.blacknon.local/wp-json/>; rel="https://api.w.org/"
[+] Interesting header: SERVER: nginx/1.6.3
[+] Interesting header: X-POWERED-BY: PHP/7.0.10
[+] XML-RPC Interface available under: http://bs-pub-wordpress-01.blacknon.local/xmlrpc.php

[+] WordPress version 4.6.1 (Released on 2016-09-07) identified from advanced fingerprinting, meta generator, readme, links opml, stylesheets numbers

[+] WordPress theme in use: twentysixteen - v1.3

[+] Name: twentysixteen - v1.3
 |  Latest version: 1.3 (up to date)
 |  Location: http://bs-pub-wordpress-01.blacknon.local/wp-content/themes/twentysixteen/
 |  Readme: http://bs-pub-wordpress-01.blacknon.local/wp-content/themes/twentysixteen/readme.txt
 |  Style URL: http://bs-pub-wordpress-01.blacknon.local/wp-content/themes/twentysixteen/style.css
 |  Theme Name: Twenty Sixteen
 |  Theme URI: https://wordpress.org/themes/twentysixteen/
 |  Description: Twenty Sixteen is a modernized take on an ever-popular WordPress layout ― the horizontal masthe...
 |  Author: the WordPress team
 |  Author URI: https://wordpress.org/

[+] Enumerating plugins from passive detection ...
[+] No plugins found
[+] Starting the password brute forcer
  [+] [SUCCESS] Login : blacknon Password : password

  Brute Forcing 'blacknon' Time: 00:00:14 < > (100 / 5014959)  0.00%  ETA: ??:??:??
  +----+----------+------+----------+
  | Id | Login    | Name | Password |
  +----+----------+------+----------+
  |    | blacknon |      | password |
  +----+----------+------+----------+

[+] Finished: Thu Sep 15 08:35:22 2016
[+] Requests Done: 149
[+] Memory used: 18.555 MB
[+] Elapsed time: 00:00:20

 

これを見ると、辞書のパスワードを総当たりでアタックすることを考えたら相応の時間がかかると思われるが、それでも脆弱なパスワードが危険だということがわかる。
ある程度複雑性を持ったパスワードを設定するようにしよう。

 

3-4.インストールされているテーマの情報を取得

WordPressにインストールされているテーマについて情報を取得する場合は、以下のコマンドを実行する。

sudo ruby wpscan.rb -u http://対象URL/ -e t # テーマの情報を取得
sudo ruby wpscan.rb -u http://対象URL/ -e vt # 脆弱性のあるテーマのみ抽出
sudo ruby wpscan.rb -u http://対象URL/ -e at # すべてのテーマをスキャンする

 

基本的には、脆弱性のあるテーマのみを抽出して確認してやればいいだろう。

 

3-5.インストールされているプラグインの情報を取得

テーマ情報と同じように、プラグインについても調査をすることができる。

sudo ruby wpscan.rb -u http://対象URL/ -e p # プラグインの情報を取得
sudo ruby wpscan.rb -u http://対象URL/ -e vp # 脆弱性のあるプラグインのみ抽出
sudo ruby wpscan.rb -u http://対象URL/ -e ap # すべてのプラグインをスキャンする

 

テーマよりは、こちらのほうが引っ掛かりやすいだろうと思う。
定期的なプラグインのアップデートをしよう。

 

とまぁ、結構簡単に脆弱性診断が行えるのだが、裏を返せばそれだけ簡単に攻撃が行えるということで、WordPressを使っている人はセキュリティに気を付けて運営しよう。

現場でかならず使われているWordPressデザインのメソッド[アップデート版] 現場でかならず使われているWordPressデザインのメソッド[アップデート版]
Viewing all 1028 articles
Browse latest View live