0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CentOS 6でZabbixエージェントをrootユーザーで起動するには

Posted at

0. 事象

CentOSにZabbixエージェントをインストールし、起動を行うとZabbixエージェントのプロセスが「zabbix」ユーザーにて起動される。

# ps -ef | grep zabbix | grep -v grep
zabbix    1900     1  0 05:13 ?        00:00:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
zabbix    1901  1900  0 05:13 ?        00:00:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix    1902  1900  0 05:13 ?        00:00:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix    1903  1900  0 05:13 ?        00:00:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix    1904  1900  0 05:13 ?        00:00:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix    1905  1900  0 05:13 ?        00:00:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]

今回はこのZabbixエージェントのプロセスをrootユーザーにて起動する方法を、備忘録として纏めていきます。

1. なぜrootユーザーで起動する必要があるのか

Zabbixの監視項目にはログファイル監視というものがある。
これはエージェントを導入したサーバ上のログファイルを監視(読み込み)し、監視対象の文字列がログファイルに書き込まれたら、エージェントがZabbixマネージャに通知する仕組みとなっている。
監視する対象のログファイルは自由に選べるが、「/var/log/messages」などのファイルはrootユーザーでしか読み込むことが出来ないため、これらのファイルを監視対象としたい場合はエージェントをrootユーザーにて起動する必要がある。

2. CentOS 7以降での設定

Zabbixの公式ドキュメントを見ると、systemdのユニット定義ファイルの[Service]ディレクティブの内容をrootに書き替えることでrootユーザーにてエージェントを起動することが出来ると書かれている。
Zabbix Documentation 5.4
└8 Running agent as root

[Service]
User=root
Group=root

しかしsystemdはCentOS 7以降で使われているサービス管理アーキテクチャであるため、CentOS 6以前のOSでは別の方法で設定を行う必要がある。

3. CentOS 6以前での設定方法

/etc/sysconfigディレクトリ配下にzabbix-agentファイルが存在するため、このファイルの内容を下記に書き換える。

/etc/sysconfig/zabbix-agent
ZABBIX_AGENT_USER=zabbix
↓変更後
ZABBIX_AGENT_USER=root

次にZabbixエージェントの設定ファイルのroot起動設定を許可を行う。
これに関してはOSのバージョンが7以降でも一緒の手順である。

/etc/zabbix/zabbix_agentd.conf
# AllowRoot=0
↓変更後
AllowRoot=1

一連の設定が完了したら、Zabbixエージェントの再起動を行う。
そして起動プロセスを確認してみると、実行ユーザーがrootに変更されていることが確認できます。

# service zabbix-agent restart
Shutting down Zabbix agent:                                [  OK  ]
Starting Zabbix agent:                                     [  OK  ]
# ps -ef | grep zabbix | grep -v grep
root     24431     1  0 07:06 ?        00:00:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
root     24432 24431  0 07:06 ?        00:00:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
root     24433 24431  0 07:06 ?        00:00:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
root     24434 24431  0 07:06 ?        00:00:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
root     24435 24431  0 07:06 ?        00:00:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
root     24436 24431  0 07:06 ?        00:00:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]

これにて設定は完了となります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?