2016年12月14日水曜日

zabbix3.2をCentOS7.3 にインストール

CentOSをダウンロード
http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1611.iso

サーバ(GUI使用)でインストール。


OS      CentOS Linux release 7.3.1611 (Core)
Zabbix    Zabbix 3.2.3              Red Hat Enterprixe Linux
                         CentOS
                         Oracle Linux 用
Apache     Apache/2.4.6 (CentOS)          CentOS標準
PHP      PHP 5.4.16              CentOS 標準
mysql     5.7.17


1)LAMP環境インストール
Webアプリケーション開発環境(Linux/Apache/MySQL/PHP(perl,python))を次の順で構

築する。
1.エンタープライズLiux用拡張パッケージのインストール(EPEL)
2.レポジトリの追加
3.PHPのインストール
4.Apacheのインストール
5.mysqlのインストール
6.サーバの起動
 
# yum install epel-release
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
# yum -y install php php-mysql
# yum -y install httpd
# yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
# yum info mysql-community-server
# yum -y install mysql-community-server


# systemctl enable httpd.service
# systemctl enable mysqld.service

# systemctl start httpd.service
# systemctl start mysqld.service

【参考】バージョン確認方法。
# cat /etc/redhat-release
# httpd -v
# php –v
# mysql –u root –p
mysql> select version();


※mysql57は、上記コマンドでエラーが発生。
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 次のコマンドで仮パスワードを検索して入力する。
# cat /var/log/mysqld.log | grep 'password is generated'
新しいパスワードに更新。
mysql> set password= 'xxxxxxxxx';


■mysqlパスワードを忘れてしまった場合。(mysql 5.7まで)
# vi /etc/my.cnf
skip-grant-tables           <-最後に追加

# systemctl restart mysqld
# mysql -u root
mysql> use mysql
Database changed
mysql> update user set authentication_string=password('New_Password') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye

# vi /etc/my.cnf
skip-grant-tables           <-削除
# systemctl restart mysqld
# mysql -u root -p

■mysqlパスワードを忘れてしまった場合(mysql8.0)
微妙に変わっている。
# vi /etc/my.cnf
skip-grant-tables
# mysql -u root
mysql> use mysql
mysql> UPDATE mysql.user SET authentication_string=null WHERE User='root';
mysql> flush privileges;

エラー発生、設定できない。
Column count of mysql.user is wrong. Expected 50, found 49. Created with MySQL 80012, now running 80013. Please use mysql_upgrade to fix this error.

# mysql_upgrade -u root で直た。

以降通常モードで、

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassword';


2) zabbixインストール

zabbixリポジトリ追加

# rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm

# yum search zabbix       (確認)


# yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-web-japanese
# yum -y install zabbix-agent
# yum -y install zabbix-get
 



【参考】RPMパッケージをダウンロードしてインストールする場合。
# wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-server-mysql-3.2.3-1.el7.x86_64.rpm
# wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-web-3.2.3-1.el7.noarch.rpm
# wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-web-japanese-3.2.3-1.el7.noarch.rpm
# wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-agent-3.2.3-1.el7.x86_64.rpm
# wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-get-3.2.3-1.el7.x86_64.rpm
# rpm –ivh zabbix-server-mysql-3.2.3-1.el7.x86_64.rpm zabbix-web-3.2.3-1.el7.noarch.rpm zabbix-web-japanese-3.2.3-1.el7.noarch.rpm
# rpm –ivh zabbix-agent-3.2.3-1.el7.x86_64.rpm
# rpm –ivh zabbix-get-3.2.3-1.el7.x86_64.rpm



3)Zabbix DBとユーザ作成

# mysql -uroot -p
   create database zabbix character set utf8;
   grant all on zabbix.* to zabbix@localhost identified by '<パスワード>';
   quit;

# cd /usr/share/doc/zabbix-server-mysql-3.2.4/
# zcat create.sql.gz | mysql -uzabbix -p zabbix
Enter password:<パスワード>

数分で終了。


※mysql 完全バックアップとリロード

# systemctl stop zabbix-server
# mysqldump -uroot -p zabbix >zabbix.dump

# mysql -uroot -p
mysql> create database zabbix character set utf8;
mysql> grant all on zabbix.* to zabbix@localhost identified by '<パスワード>';

# mysql -uroot -p zabbix <zabbix.dump

【mysql に接続して確認】
mysql> show databases;
mysql> show tables from zabbix;


# vi /etc/zabbix/zabbix_server.conf
DBName=zabbix
DBUser=zabbix
DBPassword=<パスワード>
DBSocket=/var/lib/mysql/mysql.sock


# vi /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/Tokyo

# firewall-cmd --add-service=http --zone=public --permanent
# firewall-cmd --add-port=10050/tcp --zone=public --permanent
# firewall-cmd --add-port=10051/tcp --zone=public --permanent
# firewall-cmd --reload

# systemctl restart firewalld
# firewall-cmd --list-all

4) Zabbix サーバーの起動と自動起動設定
# systemctl start zabbix-server
# systemctl enable zabbix-server

# systemctl start zabbix-agent
# systemctl enable zabbix-agent

# systemctl restart httpd

http://localhost/zabbix
データベースパスワードを入力して起動。(あとは、デフォルト)
admin/zabbixでログイン

Administration->General->Defaulttheme : Dark
Administration->Users->Create user takahab

※入力項目は、/etc/zabbix/web/zabbix.conf.phpに格納される。

Zabbix エージェントの動作確認
# zabbix_get -s 127.0.0.1 -k agent.version
3.2.4


5) SElinux有効時

SELinux通知ブラウザを使用して設定。

# ausearch -c 'zabbix_server' --raw | audit2allow -M my-zabbixserver
# semodule -i my-zabbixserver.pp

# ausearch -c 'zabbix_agentd' --raw | audit2allow -M my-zabbixagentd
# semodule -i my-zabbixagentd.pp


# setsebool -P httpd_can_connect_zabbix on
# setsebool -P zabbix_can_network on
# getsebool -a|grep zabbix
無効にする場合は、 
# setenforce 0
永久offは、
vi /etc/selinux/config
 
 
※ZABBIXデータベースの移行
# mysqldump -uzabbix -p zabbix >zabbix-dump.sql  →zabbixDBのパスワード
 
# mysql -uroot -p zabbix< zabbix-dump.sql        →rootのパスワード


※zabbix マップで文字化け

# cd /etc/alternatives

ln -s /usr/share/fonts/dejavu/DejaVuSans.ttf zabbix-web-font
ln -s /usr/share/fonts/vlgothic/VL-Gothic-Regular.ttf zabbix-web-font



 
 

0 件のコメント:

コメントを投稿

シャットダウン時の後処理 (shutdown)

# vi /etc/systemd/system/drop.service [Unit] Description= stop httpgwd DefaultDependencies=no Before=shutdown.target RefuseManualStart=true ...