LoginSignup
3
3

More than 5 years have passed since last update.

YumでZabbixセットアップ

Last updated at Posted at 2015-07-06

忘備録
【OS】
今回はCentOS6.6_x86_64版を使用。詳細は以下を参照。
http://centos.server-manual.com/
事前準備
セットアップに必要なパッケージを事前に設定しておく必要がある。以下を全て設定する。
システム変更が発生するので管理者権限が必須。rootにsuしておく事。
また、httpd.confやphp.iniを変更するので、予めバックアップしておく事。

【YUMパッケージ管理】
yum -y install yum-plugin-fastestmirror
yum -y update
yum -y groupinstall "Base" "Development tools" "Japanese Support"
[RPMforgeリポジトリ追加]
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
rpm -ivh http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
[EPELリポジトリ追加]
rpm --import http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[ELRepoリポジトリ追加]
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm
[Remiリポジトリ追加]
rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
[Zabbixリポジトリ追加]
rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm

【SELinux無効化】
getenforce
Enforcing ←SELinux有効
setenforce 0
getenforce
Permissive ←SELinux無効
vi /etc/sysconfig/selinux
SELINUX=enforcing
SELINUX=disabled ←変更(起動時に無効にする)

【iptablesでHTTPを許可】
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT ←追加
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
Iptables再起動
service iptables restart

【Apache設定】
yum -y install httpd httpd-devel
ウェルカムページ削除
rm -f /etc/httpd/conf.d/welcome.conf
デフォルトエラーページ削除
rm -f /var/www/error/noindex.html
confファイルバックアップ
cp /etc/httpd/conf/httpd.conf httpd.conf.org
confファイル設定
vi /etc/httpd/conf/httpd.conf


"# 44行目:変更
ServerTokens Prod
"# 76行目:キープアライブオン
KeepAlive On
"# 338行目:変更
AllowOverride All
"# 276行目:コメント解除しサーバー名指定
ServerName www.server.world:80
"# 402行目:ディレクトリ名のみでアクセスできるファイル名を追加
DirectoryIndex index.html index.htm index.php
"# 536行目:変更
ServerSignature Off
"# 759行目:コメント化
AddDefaultCharset UTF-8

Apache起動
/etc/rc.d/init.d/httpd start
自動起動on
chkconfig httpd on

【PHP設定】
yum -y install --enablerepo=remi gd-last ←これを先に入れないとphpが入らない
yum -y install --enablerepo=remi-php56 php php-mysql php-mbstring php-ldap php-imap php-zip php-gd php-xml php-bcmath php-pear
iniファイルバックアップ
cp /etc/php.ini php.ini.org
iniファイル設定
vi /etc/php.ini


"# 202行目:変更
short_open_tag = On
"# 366行目:変更
expose_php = Off
"# 375行目:変更
max_execution_time = 300
"# 663行目:変更
post_max_size = 20M
"# 683行目:変更
default_charset = "UTF-8"
"# 705行目:変更
always_populate_raw_post_data = -1
"# 811行目:変更
upload_max_filesize = 20M
"# 890行目:変更
date.timezone = Asia/Tokyo
"# 1661行目:変更
mbstring.language = Japanese
"# 1668行目:変更
mbstring.internal_encoding = UTF-8
"# 1676行目:変更
mbstring.http_input = UTF-8
"# 1686行目:変更
mbstring.http_output = pass
"# 1694行目:変更
mbstring.encoding_translation = On
"# 1699行目:変更
mbstring.detect_order = auto
"# 1704行目:変更
mbstring.substitute_character = none;

Apache再起動
service httpd restart
PHP確認
echo "<?php phpinfo(); ?>" > /var/www/html/info.php
ブラウザで確認

image

【MySQL設定】
CentOS構築時にデフォルトでインストールされたバージョンをアンインストール。
yum erase mysql*
rpmの追加
yum install http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
MySQL5.6のインストール
yum install mysql mysql-devel mysql-server mysql-utilities
確認
mysql –-version
mysql Ver 14.14 Distrib 5.6.15, for Linux (x86_64) using EditLine wrapper

デフォルトキャラクタセットをutf8に設定
vi /etc/my.cnf


[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
character-set-server=utf8
;任意設定
innodb_file_per_table
query-cache-size=16M
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql]
default-character-set=utf8

起動・自動起動設定
service mysqld start
chkconfig mysqld on

MySQL初期設定


[root@www ~]# mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter

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 MySQL
root user without the proper authorisation.

root パスワードを設定

Set root password? [Y/n] y 
New password: # 設定するパスワードを入力
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

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? [Y/n] 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? [Y/n] 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? [Y/n] 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.

特権情報リロード

Reload privilege tables now? [Y/n] y 
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

root で接続確認

[root@www ~]# mysql -u root -p 
Enter password:# 設定したパスワードで認証
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

ユーザ一覧表示

mysql> select user,host,password from mysql.user; 
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | ***************************************** |
| root | 127.0.0.1 | ***************************************** |
+------+-----------+-------------------------------------------+
2 rows in set (0.00 sec)

データベース一覧表示

mysql> show databases; 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.00 sec)

mysql> exit
Bye

Zabbix用設定
mysql -u root -p パスワード
create database zabbix default character set utf8;
grant all on zabbix.* to zabbix@localhost identified by '**';←パスワード設定
flush privileges;
exit;

【Zabbixインストール】
rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-web-japanese zabbix-agent zabbix-get

Zabbix用のDBスキーマとデータをインポート
mysql -uroot -p zabbix < /usr/share/doc/zabbix-server-mysql-2.4.5/create/schema.sql
mysql -uroot -p zabbix < /usr/share/doc/zabbix-server-mysql-2.4.5/create/images.sql
mysql -uroot -p zabbix < /usr/share/doc/zabbix-server-mysql-2.4.5/create/data.sql

Zabbix用設定
vi /etc/zabbix/zabbix_server.conf


'#DBPassword='
DBPassword=<パスワード>

Zabbixサーバの起動
service zabbix-server start

Zabbixサーバの自動起動を設定
chkconfig zabbix-server on

Apacheも念のため再起動しておきます
service httpd restart

また、動作を確認するため、Zabbixエージェントも起動しておきます
service zabbix-agent start
chkconfig zabbix-agent on

Zabbixエージェントの動作確認
zabbix_get -s 127.0.0.1 -p 10050 -k agent.version
——————————
2.4.5
——————————
上のように、Zabbixのバージョンが表示されれば、起動しています

初期設定
ブラウザで下記URLを開き、初期設定を開始(ホスト名はご自分の環境に読替え)
http://localhost/zabbix/
「Next」をクリック
image
すべて「OK」であれば「Next」をクリック
image
「User」に「zabbix」を 「Password」に、MySQLで設定したパスワードを入力し、
「Test connection」をクリック
image
「OK」と表示されれば、正しくMySQLと接続できています。続けて「Next」をクリック
image
そのまま「Next」をクリック
image
そのまま「Next」をクリック
image
「Finish」をクリックすれば、初期設定完了
image
設定が終了すると、Zabbixのログイン画面が表示されますので、初期ユーザでログイン
Username:admin
Password:zabbix
image
パスワードと言語の変更
[Administration]→[Users] をクリック
image
Members列の「Admin (Zabbix Administrator)」をクリック
image
Userタブを選択し、「Change password」をクリック
image
パスワードの入力欄が表示されますので、パスワードを入力し、
「Language」を「Japanese(ja_JP)」に変更したら「Update」をクリック
image
一度ブラウザをリロードすると日本語表示になります
image

3
3
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
3
3