zabbixインストール

zabbixでWebサーバの監視をトライすることにした。

  1. mysql-5.5のインストール
    • まず、/usr/local/etc/pkgtools.conf に以下の記述を追加
       MAKE_ARGS = {
              'databases/mysql55-*' => [
                      'WITH_CHARSET=utf8',
                      'WITH_XCHARSET=all',
                      'WITH_OPENSSL=yes',
                      ],
        }
    • portsでmysqlのインストール
      # portinstall mysql-server-5.5\*
    • /etc/rc.conf に以下を追加
      mysql_enable="YES"
      mysql_dbdir="/usr/local/mysql/data"
    • テンプレートを利用してconfig fileを作成
      # cp /usr/local/share/mysql/my-medium.cnf /etc/my.cnf
      # chmod 640 /etc/my.cnf
    • my.cnfを編集し、次の内容を追加
      [mysqld]
      skip-character-set-client-handshake #←追加(クライアントの文字コードに依存しない)
      default-character-set = utf8 #←追加(デフォルト文字コードをUTF-8とする)
      
      [mysql]
      default-character-set = utf8 #←追加
    • mysqlの設定をする
      # mysql -u root
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 1
      Server version: 5.5.31 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> use mysql;
      Database changed
      mysql> set password for root@localhost=password('hogehoge');
      Query OK, 0 rows affected (0.00 sec)
    • 不要なユーザとテーブルの削除
      mysql> select user,host from mysql.user;
      +------+--------------+
      | user | host         |
      +------+--------------+
      | root | 127.0.0.1    |
      | root | ::1          |
      |      | localhost    |
      | root | localhost    |
      |      | olive.jan.nu |
      | root | olive.jan.nu |
      +------+--------------+
      6 rows in set (0.00 sec)
      
      mysql> delete from mysql.user where user='';
      Query OK, 2 rows affected (0.00 sec)
      
      mysql> show databases;
      +--------------------+
      | Database           |
      +--------------------+
      | information_schema |
      | mysql              |
      | performance_schema |
      | test               |
      +--------------------+
      4 rows in set (0.00 sec)
      
      mysql> drop database test;
      Query OK, 0 rows affected (0.04 sec)
    • 参考:http://www.bugbearr.jp/?FreeBSD%2FMySQL
    • 参考:http://server-setting.info/freebsd/freebsd_mysql.html
  2. portでzabbixをインストール
    # portinstall zabbix2-server
    # portinstall zabbix2-frontend
    # echo 'zabbix_server_enable="YES"' >> /etc/rc.conf
  3. mysql関係の設定
    1. データベースの作成とユーザの作成
      # mysql -u root -p
      Enter password:
      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 3
      Server version: 5.5.31 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> create database zabbix;
      Query OK, 1 row affected (0.01 sec)
      
      mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
      Query OK, 0 rows affected (0.00 sec)
      
      mysql> flush privileges;
      Query OK, 0 rows affected (0.00 sec)
      
      mysql> quit;
      Bye
    2. 初期データベースのインポート。image.sqlのあとにdata.sqlを読み込ませないとエラーになります。
      # cd /usr/local/share/zabbix2/server/database/mysql/
      # mysql -uzabbix -pXXXXXXXX zabbix < schema.sql
      # mysql -uzabbix -pXXXXXXXX zabbix < data.sql
      ERROR 1452 (23000) at line 2690: Cannot add or update a child row: a foreign key constraint fails (`zabbix`.`sysmaps_elements`, CONSTRAINT `c_sysmaps_elements_2` FOREIGN KEY (`iconid_off`) REFERENCES `images` (`imageid`))
      # mysql -uzabbix -pXXXXXXXX zabbix < images.sql
      # mysql -uzabbix -pXXXXXXXX zabbix < data.sql
  4. zabbix_server.confの設定
    # cd /usr/local/share/zabbix2/
    # cp zabbix_server.conf.sample  zabbix_server.conf

    以下の設定を追加

    LogFile=/var/log/zabbix/zabbix_server.log
    PidFile=/var/run/zabbix/zabbix_server.pid
    DBName=zabbix
    DBUser=zabbix
    DBPassword=XXXXXXXX
    FpingLocation=/usr/local/sbin/fping
    ListenIP=127.0.0.1
  5. ディレクトリの設定をしておく
    # mkdir /var/run/zabbix /var/log/zabbix
    # chown zabbix:zabbix /var/run/zabbix /var/log/zabbix
  6. /etc/sysctl.conf に以下の設定を追加する必要があるらしい
    kern.ipc.shmall=40960000
    kern.ipc.shmmax=204800000
  7. 起動してみた
    # /usr/local/etc/rc.d/zabbix_server start
    Starting zabbix_server.
  8. 次はWeb Frontendの設定
    1. Apacheの設定に、以下の設定を追加
      Alias /zabbix/ "/usr/local/www/zabbix2/"
      
      <Directory "/usr/local/www/zabbix2">
         require         valid-user
         AllowOverride   None
         Options None
         Order   allow,deny
         Allow   from 192.168.XXX.YYY/24
         DirectoryIndex index.php
      
         satisfy         any
         AuthUserFile    /usr/local/etc/.htpasswd-zabbix
         AuthType        basic
         AuthName        "Please enter username and password"
      </Directory>
    2. phpにtimezoneの設定が必要なので、/usr/local/etc/php.ini に以下の設定を追加・修正。
      date.timezone = Asia/Tokyo
      post_max_size = 16M
      max_execution_time = 300
      max_input_time = 300
    3. ブラウザからアクセスをして設定をする
      • phpの設定等で問題がないことを確認。項目全体でOKが出ていれば良い。
      • MySQLの設定をして、Test Connection をクリック。OKが出れば良い。
      • zabbix serverの設定はdefaultでいいはず。
      • /usr/local/www/zabbix2/conf/zabbix.conf.php の生成に失敗する。そこで、ダウンロードして、/usr/local/www/zabbix2/conf/zabbix.conf.php としてサーバに保存し、Retry をする。
      • Finish で完了!
    4. さあ、ログインをしよう。admin/zabbixで初期は入れる
    5. 言語を日本語にする
      • Administration ⇒ Users ⇒ Admin ⇒ Language で Japaneseを選択
    6. グラフの凡例の文字が化けるのはfont関係に問題がある模様。そのうち調べて直すことにしよう。
カテゴリー: FreeBSD, Install パーマリンク

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です