PROXMOX上に新規に作成したコンテナにZABBIXを入れてサーバを監視する。
そのときのZABBIXインストール用コピペチート。
コンテナを作る & OSの最低限の設定
PROXMOXにログインして、
1, CTを新規作成する
2, スペックはそんなに必要ないのでメモリ1024MB、SWAP 2048MBのCPU1コア。
3, テンプレートはCentOS7を利用
4, NICはeth0として固定IPを設定
そして起動したらSSHログインが可能になるように最低限のことを実施する。
PROXMOXのコンソールから以下投入
[アップデート]
# yum -y update
[一応再起動]
# reboot
[SSHServerのインストールと起動]
# yum -y install openssh-server
# systemctl start sshd
# systemctl enable sshd
[firewalldが起動していれば一旦停止する]
# systemctl stop firewalld
利用するリポジトリのインストール
ここからは通常の他のマシンからsshで接続して作業する
ZABBIXはこの記事を作成した時点では4.2が最新ですが、
4.2は4.4が出るまでのつなぎであるため、ここでは安定版の4.0をインストールします。
4.0は長期サポートなので長く使うのであれば最適なバージョンです。
[EPELリポジトリのインストール]
# yum -y install epel-release
# yum -y update
[Remiリポジトリのインストール]
ZABBIXはPHP7を必要としているのでRemiでインストールします。
# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
# rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
[MySQL8.0リポジトリのインストール]
MariaDBでもいいのですがMySQLが推奨っぽいのでこれを利用します。
# rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
[ZABBIX4.0リポジトリのインストール]
# rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
利用するミドルウェアのインストール
これで全てのリポジトリを用意出来たのでいよいよ必要なものをインストールしていきます。
[Apacheのインストール]
yum -y install httpd
[PHP7.2のインストール]
# yum --enablerepo=remi-safe -y install php72-php php72-php-mysqlnd php72-php-bcmath php72-php-ldap php72-php-xml php72-php-gd
[MySQLのインストール]
# yum -y install mysql-community-devel
# yum -y install mysql-community-server
[ZABBIXのインストール]
# yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-web-japanese
# yum -y install zabbix-agent
# yum -y install zabbix-get
日本語でWEB表示するために”zabbix-web-japanese”をインストールしています。
これで全てのインストールは完了です。
Config等の設定
ここからは起動に必要な最低限の設定を行います。
[Apacheの設定]
# vi /etc/httpd/conf/httpd.conf
ServerAdmin root@localhost
-> ServerAdmin root@example.com
# ServerName www.example.com:80
-> ServerName zabbix.example.com:80
Options Indexes FollowSymLinks
-> Options FollowSymLinks
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
-> AllowOverride All
最終行にKeepAliveを有効にするためのキーを追加
KeepAlive On
なんとなくバージョン情報とかが表示されるのは好ましくないので、最終行に下記を追記
# Apache version Hide
ServerTokens ProductOnly
ServerSignature off
次にZABBIX用のconfを少し手直しする
# /etc/httpd/conf.d/zabbix.conf
<IfModule mod_php5.c> <<---- <IfModule mod_php7.c> に変更
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value max_input_vars 10000
php_value always_populate_raw_post_data -1
# php_value date.timezone Europe/Riga <<---- #を取って php_value date.timezone Asia/Tokyo に変更
</IfModule>
[PHPの設定]
PHPの設定を変更しておきます。
# vi /etc/php.ini
date.timezone = Asia/Tokyo
post_max_size = 8M -> 16M
max_execution_time = 30-> 300
max_input_time = 60 -> 300
Apacheを起動する、また恒久的に起動するように設定しておく
# systemctl start httpd
# systemctl enable httpd
ここで一旦Apacheが正しく起動した確認のためにブラウザから、
http://server-ip でアクセスしてApacheのテストページが表示されることを確認してください。
表示が出来たら成功なのでテストページはセキュリティ上削除しておきます。
# rm -f /etc/httpd/conf.d/welcome.conf
# rm -f /var/www/error/noindex.html
confを削除したのでApacheもリスタートしておきます。
# systemctl restart httpd
[MySQLの設定]
# vi /etc/my.cnf
【変更前】
#default-authentication-plugin=mysql_native_password
【変更後】
default-authentication-plugin=mysql_native_password
MySQLを起動する
# systemctl start mysqld
ここで内部的に初期設定が実行されるので少し時間がかかるので気長に待つ
恒久的に起動するように設定しておく
# systemctl enable mysqld
MySQL5.xと違ってrootパスワードは自動的に生成されるので生成されたパスワードを確認する
# cat /var/log/mysqld.log | grep password
2019-06-25T05:55:34.779515Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: AAA123BBB
この結果だとパスワードは”AAA123BBB”になる。
生成されたパスワードを使って任意のパスワードを設定します。
# mysql_secure_installation --use-default
Securing the MySQL server deployment.
Enter password for user root: ここに生成されたパスワードを入力
The existing password for the user account root has expired. Please set a new password.
New password: 新しいパスワード
Re-enter new password: もう一度新しいパスワード
... Failed! Error: Your password does not satisfy the current policy requirements
あれ、怒られた・・・。
どうやらパスワードポリシーがあるみたいです。
条件は
- 8文字以上
- 大文字、小文字両方必要
- 数字を含む
- 記号を含む
New password: 上記を満たすパスワードを入力
Re-enter new password: もう一度入力
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
rootユーザーで遠隔ログインは危険なのでローカルに限定しておきます
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL 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? (Press y|Y for Yes, any other key for No) : y
- 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.
privilegeテーブルを再読込するので”y”でOK
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
これで初期設定は完了です。
[ZABBIX用のデータベースを作成する]
# mysql -u root -p
Enter password: 先程設定したrootユーザのパスワードを入力
ここからSQL文を書いていきます。
データベース名は”zabbix”で文字コードはUTF8を指定します。
mysql> create database zabbix character set utf8 collate utf8_bin;
データベース”zabbix”のユーザーを作成します。ここではユーザー名を”zabbix”、パスワードは”Passw0rd!!”にします。
mysql> create user zabbix@localhost identified by 'Passw0rd!!';
作成したユーザーにzabbixデータベースへのアクセスを付与する
mysql> grant all on zabbix.* to zabbix@localhost;
MySQLを終了する
mysql> quit
次にZABBIX標準のツールを使ってDBのスキーマ等を作る
# cd /usr/share/doc/zabbix-server-mysql-4*/
# gzip -dc create.sql.gz | mysql -u zabbix -p zabbix
Enter password: ここで先程作ったZABBIX用のパスワードを入力
少し時間がかかるので気長に待つ
[ZABBIXの設定]
# vi /etc/zabbix/zabbix_server.conf
ここに先程作成したZABBIX用データベースのユーザー名等を記載する
DBName=zabbix
DBUser=zabbix
DBPassword=Passw0rd!!
[ZABBIXサービスを起動する]
サーバの起動、自動起動設定
# systemctl start zabbix-server
# systemctl enable zabbix-server
エージェントの起動、自動起動設定
# systemctl start zabbix-agent
# systemctl enable zabbix-agent
おつかれさまでした。
あとは、ブラウザから下記にアクセスして設定を終わらせましょう。
”http://server-ip/zabbix”