[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Low cost] Wasabi object storage construction and operation service

[Low cost] Wasabi object storage construction and operation service

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “beSIM”

[Compatible with over 200 countries] Global eSIM “beSIM”

[Compatible with Chinese corporations] Chinese cloud / server construction, operation and maintenance

[Compatible with Chinese corporations] Chinese cloud / server construction, operation and maintenance

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

etckeeperで/etc配下をgit管理してみよう

インフラエンジニアの伊藤です。
Linuxサーバの運用をする上で、設定ファイルの書き換えは日常で行われます。

設定を変更する際はファイルの最後に日付名をつけたりして、バックアップすることが多いかと思います。

こんな感じに。

# ls -al |grep httpd.conf
-rw-r--r--  1 root root 16730 Jan 25 22:59 httpd.conf
-rw-r--r--  1 root root 16730 Jan 25 22:59 httpd.conf_20151225
-rw-r--r--  1 root root 16730 Jan 25 22:59 httpd.conf_20160120

ただし、設定変更するごとにバックアップファイルを取っていたら、ファイルが散乱してしまいます。
ファイルが多いってことはそれだけミスが起こる可能性が増えてきます。これってかなり精神衛生上よくないですよね。

そんなときは、etckeeperという VCS(バージョン管理システム)を使って管理するのがオススメです!

etckeeperは、もちろん手動でコミットしてくれますが、以下のタイミングでも自動でコミットしてくれます。
・yumコマンド実行時
・日付が変わったタイミング

とりあえずインストールする

etckeeperをインストールしてみます。
先ほど軽く触れたように、VCSが必要になります。今回はgitをインストールします。

#yum install git

epelリポジトリからetckeeperをインストールします。

#yum install --enablerepo=epel etckeeper

無事インストールされました。

# rpm -qa |grep etckeeper
etckeeper-0.64-1.el5.rf

使ってみる

まずはリポジトリを作成します。

# etckeeper init
Initialized empty Git repository in /etc/.git/

コミットしてみます。

# etckeeper commit "First commit"
[master (root-commit) 970f0b3] First commit
 Author: vagrant <vagrant@cli>
 1174 files changed, 122593 insertions(+), 0 deletions(-)
 create mode 100755 .etckeeper
 create mode 100644 yum/version-groups.conf

コミットのログを確認します。
etckeeper vcs~にて、gitのコマンドが使用可能です。

# etckeeper vcs log
commit 970f0b335acdf586e099d57f1bc95d442bff853f
Author: vagrant <vagrant@cli>
Date:   Fri Jan 29 21:02:33 2016 +0900

    First commit

試しにApacheをインストールしてみます。
途中でetckeeperがコミットしてくれます。

#yum install httpd
(中略)
etckeeper: pre transaction commit
  Updating   : httpd-tools-2.2.15-47.el6.centos.1.x86_64                                          1/4
  Updating   : httpd-2.2.15-47.el6.centos.1.x86_64                                                2/4
  Cleanup    : httpd-2.2.15-47.el6.centos.x86_64                                                  3/4
  Cleanup    : httpd-tools-2.2.15-47.el6.centos.x86_64                                            4/4
etckeeper: post transaction commit
  Verifying  : httpd-tools-2.2.15-47.el6.centos.1.x86_64                                          1/4
  Verifying  : httpd-2.2.15-47.el6.centos.1.x86_64                                                2/4
  Verifying  : httpd-tools-2.2.15-47.el6.centos.x86_64                                            3/4
  Verifying  : httpd-2.2.15-47.el6.centos.x86_64                                                  4/4
(中略)

試しにhttpd.confを編集してコミットしたときのログを確認してみます。

# etckeeper vcs log
commit a6cee87ff14bcf90587e98017d8a737777bcc5c0
Author: vagrant <vagrant@cli>
Date:   Fri Jan 29 22:43:53 2016 +0900

    edit httpd.conf

commit 970f0b335acdf586e099d57f1bc95d442bff853f
Author: vagrant <vagrant@cli>
Date:   Fri Jan 29 21:02:33 2016 +0900

    First commit

どの部分を編集したか、diffの確認をしてみます。

# etckeeper vcs diff 970f0b335acdf586e099d57f1bc95d442bff853f 66aefb8e71a7526988c0b3d3863fd6e7e3ec0b54
diff --git a/httpd/conf/httpd.conf b/httpd/conf/httpd.conf
index 579d194..5870596 100644
--- a/httpd/conf/httpd.conf
+++ b/httpd/conf/httpd.conf
@@ -1,3 +1,4 @@
+#test
 #
 # This is the main Apache server configuration file.  It contains the
 # configuration directives that give the server its instructions.

ある地点に戻してみます。

# etckeeper vcs revert a6cee87ff14bcf90587e98017d8a737777bcc5c0
Finished one revert.
# On branch master
nothing to commit (working directory clean)

使い方としてはざっとこんな感じですかね。
/etc/配下の設定ファイルが大量にあることが避けられていい感じですね!

ということで、etckeeperの使い方でした。
etckeeperを使って、/etc配下を美しく管理しましょう!

この記事がお役に立てば【 いいね 】のご協力をお願いいたします!
0
読み込み中...
0 票, 平均: 0.00 / 10
2,472
X facebook はてなブックマーク pocket
[2024.6.30 CentOS support ended] CentOS server migration solution

[2024.6.30 CentOS support ended] CentOS server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author