【第一回Ansible】Ansible建ててみました
はじめに
運用を自動化する遊びをしたいと思っているので、今日はAnsibleの構築をいたしました。
今回はこちらのサイトを参考にさせていただきました。
CentOS7の初期設定
- CentOS7をインストールし、ユーザ追加、パスワード設定、IPアドレス、デフォルトゲートウェイ、DNS、NTP、パーティション、Swapなどの設定を行います。 細かい所は割愛します。(要は外部からSSHアクセス出来て、yumが使える状態にしてます)
※ 以下作業は全てrootで行ってます。
パッケージインストール
Ansibleをインストールします。
# yum install ansible
設定の変更
ターゲットとなるホストの情報を設定します。
# vi /etc/ansible/hosts
差分はこんな感じです。
# diff /etc/ansible/hosts /etc/ansible/hosts.org 45,46d44 < [ansible_test] < 192.168.100.110
動作確認
SSH Keyの準備をします。
# ssh-keygen -t rsa
ターゲットとなるホストに公開鍵を渡します。
# ssh-copy-id user@192.168.100.110
以下のコマンドでAnsibleからターゲットとなるホストにテストファイルを作らせます。
# ansible ansible_test -u user -m command -a "touch test" [WARNING]: Consider using file module with state=touch rather than running touch 192.168.100.110 | SUCCESS | rc=0 >>
以下のコマンドでテストファイルが出来ていることを確認させます。
# ansible ansible_test -u user -m command -a "ls" 192.168.100.110 | SUCCESS | rc=0 >> test
testファイルが出来ているようなので、成功していそうです。
次回はより細かい設定とplaybookの作成などをやっていきたいと思います。
各バージョン
# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) # ansible --version ansible 2.4.2.0 config file = /etc/ansible/ansible.cfg configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/site-packages/ansible executable location = /bin/ansible python version = 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
【第一回PowerDNS】PowerDNSを建ててみました
はじめに
個人的需要があったのでとりあえず立ててみました。 構築はこちらのサイトを参考にさせていただきました。 内容は目新しいものはありません、自分の作業の記録メモです。
CentOS7の初期設定
- CentOS7をインストールし、ユーザ追加、パスワード設定、IPアドレス、デフォルトゲートウェイ、DNS、NTP、パーティション、Swapなどの設定を行います。 細かい所は割愛します。(要は外部からSSHアクセス出来て、yumが使える状態にしてます)
- 動作確認ようにdigを使いたかったのでbind-utilsも入れときましたが、無くてもOKだとは思います。
※ 以下作業は全てrootで行ってます。
パッケージインストール
MariaDBのインストール
MariaDBをインストールします。
# yum install mysql-community-server
EPEL リポジトリの追加
そのままだとPworeDNSのパッケージがyumで入らないので、EPELリポジトリを追加します。
# yum install epel-release
PowerDNSのインストール
PowerDNS関連のパッケージをインストールします。
# yum install pdns pdns-backend-mysql pdns-tools
順番としては、MariaDB入れる前にEPELリポジトリの追加が良かったような気がしますのが、このままやってみます。
MariaDB設定
MariaDBの自動起動の設定と起動
MariaDBをサーバ起動時に自動起動するように設定します。
# systemctl enable mariadb.service
MariaDBを手動起動させときます。
# systemctl start mariadb.service
MariaDB初期設定
MariaDBの初期設定をやっていきます
# mysql_secure_installation
上記コマンドを打ったら、対話形式で設定が進みます。
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] 【Enter押下】 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]【Enter押下】 ... 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]【Enter押下】 ... 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]【Enter押下】 - 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]【Enter押下】 ... 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!
一通り終わるとお礼を言ってくれます、こういうの地味にうれしいです。
データベース、ユーザ、テーブルの作成
今回は参考にさせていただいたサイトと同様に以下のパラメータで設定したといことにしておきます。
項目 | 値 |
---|---|
データベース名 | powerdns |
ユーザ名 | powerdns |
パスワード | password |
MariaDBにログインします。
# mysql -u root -p
データベースを作成します。
CREATE DATABASE powerdns;
ユーザを作成します。
GRANT ALL ON powerdns.* TO 'powerdns'@'localhost' IDENTIFIED BY 'password'; FLUSH PRIVILEGES;
テーブルを作成します。
考えるのが面倒なので、参考にさせていただいたサイトからそのままコピペしました。
use powerdns; CREATE TABLE domains ( id INT AUTO_INCREMENT, name VARCHAR(255) NOT NULL, master VARCHAR(128) DEFAULT NULL, last_check INT DEFAULT NULL, type VARCHAR(6) NOT NULL, notified_serial INT DEFAULT NULL, account VARCHAR(40) DEFAULT NULL, PRIMARY KEY (id) ) Engine=InnoDB; CREATE UNIQUE INDEX name_index ON domains(name); CREATE TABLE records ( id INT AUTO_INCREMENT, domain_id INT DEFAULT NULL, name VARCHAR(255) DEFAULT NULL, type VARCHAR(10) DEFAULT NULL, content VARCHAR(64000) DEFAULT NULL, ttl INT DEFAULT NULL, prio INT DEFAULT NULL, change_date INT DEFAULT NULL, disabled TINYINT(1) DEFAULT 0, ordername VARCHAR(255) BINARY DEFAULT NULL, auth TINYINT(1) DEFAULT 1, PRIMARY KEY (id) ) Engine=InnoDB; CREATE INDEX nametype_index ON records(name,type); CREATE INDEX domain_id ON records(domain_id); CREATE INDEX recordorder ON records (domain_id, ordername); CREATE TABLE supermasters ( ip VARCHAR(64) NOT NULL, nameserver VARCHAR(255) NOT NULL, account VARCHAR(40) NOT NULL, PRIMARY KEY (ip, nameserver) ) Engine=InnoDB; CREATE TABLE comments ( id INT AUTO_INCREMENT, domain_id INT NOT NULL, name VARCHAR(255) NOT NULL, type VARCHAR(10) NOT NULL, modified_at INT NOT NULL, account VARCHAR(40) NOT NULL, comment VARCHAR(64000) NOT NULL, PRIMARY KEY (id) ) Engine=InnoDB; CREATE INDEX comments_domain_id_idx ON comments (domain_id); CREATE INDEX comments_name_type_idx ON comments (name, type); CREATE INDEX comments_order_idx ON comments (domain_id, modified_at); CREATE TABLE domainmetadata ( id INT AUTO_INCREMENT, domain_id INT NOT NULL, kind VARCHAR(32), content TEXT, PRIMARY KEY (id) ) Engine=InnoDB; CREATE INDEX domainmetadata_idx ON domainmetadata (domain_id, kind); CREATE TABLE cryptokeys ( id INT AUTO_INCREMENT, domain_id INT NOT NULL, flags INT NOT NULL, active BOOL, content TEXT, PRIMARY KEY(id) ) Engine=InnoDB; CREATE INDEX domainidindex ON cryptokeys(domain_id); CREATE TABLE tsigkeys ( id INT AUTO_INCREMENT, name VARCHAR(255), algorithm VARCHAR(50), secret VARCHAR(255), PRIMARY KEY (id) ) Engine=InnoDB; CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm);
MariaDBから出ます。
quit
PowerDNS設定
設定ファイルの編集
PowerDNSの設定ファイルを編集します。
vi /etc/pdns/pdns.conf
diff で差分を取るとこんな感じ。(pdns.conf.orgは編集前のファイル)
# diff /etc/pdns/pdns.conf /etc/pdns/pdns.conf.org 3,16c3 < launch=gmysql < gmysql-host=localhost < gmysql-user=powerdns < gmysql-password=password < gmysql-dbname=powerdns < gmysql-dnssec=yes < loglevel=10 < log-dns-queries=1 < recursor=8.8.8.8 < allow-recursion=0.0.0.0/0 < log-dns-details=on < loglevel=3 < logging-facility=0 < --- > launch=bind
PowerDNSをサーバ起動時に自動起動するように設定します。
# systemctl enable pdns.service
PowerDNSを手動起動させときます。
# systemctl start pdns.service
動作確認
digコマンドでgoogleさんのタイムサーバの名前解決をしてみます。
# dig time1.google.com @127.0.0.1 ; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> time1.google.com @127.0.0.1 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51556 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 512 ;; QUESTION SECTION: ;time1.google.com. IN A ;; ANSWER SECTION: time1.google.com. 3599 IN A 216.239.35.0 ;; Query time: 47 msec ;; SERVER: 127.0.0.1#53(127.0.0.1) ;; WHEN: 月 6月 25 22:38:40 JST 2018 ;; MSG SIZE rcvd: 61
いけたかな?
試しにPowerDNSのサービスを停めてみました。
# systemctl stop pdns.service
同じように、digで引いてみると・・・
# dig time1.google.com @127.0.0.1 ; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> time1.google.com @127.0.0.1 ;; global options: +cmd ;; connection timed out; no servers could be reached
返ってこないですね。
どうやら無事PowerDNSの設定が出来てそうです。
次回は、WebGUIの導入をやれたらやってみたいと思います。 最終的には権威DNSにして、閉じたネットワークで独自ドメインを管理させるつもりです。
各バージョンなど
# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) # rpm -qa | grep -i mariadb mariadb-5.5.56-2.el7.x86_64 mariadb-libs-5.5.56-2.el7.x86_64 mariadb-server-5.5.56-2.el7.x86_64 # rpm -qa | grep -i pdns pdns-3.4.11-4.el7.x86_64 pdns-backend-mysql-3.4.11-4.el7.x86_64 pdns-tools-3.4.11-4.el7.x86_64
今日の補習
用語 | 説明 |
---|---|
bind-utils | digなどを使うためのパッケージ |
bash-completion | 入力補完のためのパッケージ |
vim-enhanced | vim用のパッケージ |