基於Docker搭建zabbix監控服務php
操做系統:centos6.5 html
Docker version 1.7.1java
Docker的安裝以及pull鏡像這裏暫且不介紹mysql
[root@gmdai ~]# docker p_w_picpathsnginx
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEc++
centos6-lamp latest 601481552a9d 4 minutesago 1.498 GBweb
centos6-ssh-mysql latest 8fe2459b59e5 16 hoursago 464 MBsql
tomcat latest 430e8c6b6fad 6 days ago 357.3 MBdocker
nginx latest c0e6aba9c87a 6 daysago 182.6 MB數據庫
centos7 latest 0e0217391d41 7 weeksago 196.6 MB
consol/tomcat-7.0 latest 1439b1fbf911 10 months ago 601.2 MB
centos6-ssh latest b78c71c001db 20 monthsago 296.9 MB
本人是拿pull下來的centos6一鍵yum安裝的lamp環境而後commit爲一個新的鏡像
yum -y install gcc gcc-c++ autoconf httpd php mysql mysql-server php-mysqlhttpd-manual mod_ssl
mod_perl mod_auth_mysql php-gd php-xml php-mbstring php-ldapphp-pear php-xmlrpc php-bcmath
mysql-connector-odbc mysql-devel libdbi-dbd-mysqlnet-snmp-devel curl-devel unixODBC-devel OpenIPMI-devel java-devel
[root@gmdai ~]# docker run -itd --name zabbix -v /mnt/:/mnt/ -p10050:10050 -p 10051:10051 centos6-lamp
fae23d1c5f1c64670ea50bc91f5a444c54ffd823b194187deff279a5ba4ea469
[root@gmdai ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fae23d1c5f1c centos6-lamp "/bin/sh-c '/usr/sb 14 seconds ago Up 11 seconds 22/tcp, 0.0.0.0:10050-10051->10050-10051/tcp zabbix
[root@gmdai ~]# cp zabbix-2.0.15.tar.gz /mnt/
[root@gmdai ~]# docker exec -it zabbix /bin/bash //進入docker容器
bash-4.1# cp /mnt/zabbix-2.0.15.tar.gz /root/
bash-4.1# cd root/
bash-4.1# ls
zabbix-2.0.15.tar.gz
bash-4.1# tar -xzvf zabbix-2.0.15.tar.gz
bash-4.1# groupadd zabbix -g 201
bash-4.1# useradd -g zabbix -u 201 -m zabbix
bash-4.1# yum install php-pecl-ssh2.x86_64libssh2-devel.x86_64 openldap openldap-devel
bash-4.1# tar -xzvf zabbix-2.0.15.tar.gz
bash-4.1#./configure --prefix=/usr --sysconfdir=/etc/zabbix--enable-server --enable-proxy --enable-agent
--enable-ipv6 --with-mysql=/usr/bin/mysql_config--with-net-snmp --with-libcurl --with-openipmi
--with-unixodbc --with-ldap --with-ssh2 --enable-java //配置
bash-4.1# make && make install //編譯&安裝
bash-4.1# mysqladmin -uroot password "root"
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock' (111)'
Check that mysqld is running and that the socket:'/var/lib/mysql/mysql.sock' exists! //這個錯誤提示mysql服務是否啓動
bash-4.1# service mysqld status
mysqld dead but pid file exists //說mysql服務已死,重啓就好了
bash-4.1# service mysqld restart
Stopping mysqld: [FAILED]
Starting mysqld: [ OK ]
bash-4.1# service mysqld status
mysqld (pid 8224) isrunning...
bash-4.1# mysqladmin -uroot password "root" //更改root密碼
bash-4.1# mysql -uroot -proot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. Allrights reserved.
Oracle is a registered trademark of Oracle Corporation and/orits
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the currentinput statement.
mysql> create database zabbix character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* tozabbix@localhost identified by "zabbix";
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
bash-4.1# mysql -uzabbix -pzabbix zabbix <database/mysql/schema.sql
bash-4.1# mysql -uzabbix -pzabbix zabbix <database/mysql/p_w_picpaths.sql
bash-4.1# mysql -uzabbix -pzabbix zabbix <database/mysql/data.sql
拷貝zabbix服務啓動腳本到/etc/init.d,並受權
bash-4.1# cp misc/init.d/fedora/core/zabbix_* /etc/init.d/
bash-4.1# chmod 755 /etc/init.d/zabbix_*
bash-4.1# sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/#g"/etc/init.d/zabbix_server
bash-4.1# sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/#g"/etc/init.d/zabbix_agentd
bash-4.1# mkdir /var/log/zabbix
bash-4.1# chown zabbix:zabbix/var/log/zabbix/
vim /etc/php.ini (修改這些參數的目的是zabbix 的web 代碼要求要這麼配置才能正
常運行,因此,不修改餓後果就是安裝沒法得到正常的環境,關於php.ini 這些參數的具體
意思,請讀者自行參考php 相關資料)
date.timezone = Asia\/Shanghai
max_execution_time = 300
post_max_size = 32M
max_input_time = 300
memory_limit = 128M
mbstring.func_overload = 0
sed -i "s/;date.timezone =/date.timezone =Asia\/Shanghai/g" /etc/php.ini
sed -i "s#max_execution_time = 30#max_execution_time =300#g" /etc/php.ini
sed -i "s#post_max_size = 8M#post_max_size = 32M#g"/etc/php.ini
sed -i "s#max_input_time = 60#max_input_time =300#g" /etc/php.ini
sed -i "s#memory_limit = 128M#memory_limit =128M#g" /etc/php.ini
sed -i "/;mbstring.func_overload =2/ambstring.func_overload = 0\n" /etc/php.ini
chkconfig mysqld on
chkconfig httpd on
service mysqld start
service httpd start
SED更改
sed -i"s/DBUser\=root/DBUser\=zabbix/g"/etc/zabbix/zabbix_server.conf
sed -i "/#DBPassword=/aDBPassword=zabbix\n"/etc/zabbix/zabbix_server.conf
sed -i" s#tmp/zabbix_server.log#var/log/zabbix/zabbix_server.log#g"/etc/zabbix/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/var/lib/mysql/mysql.sock
Sed配置
sed -i "s/Server\=127.0.0.1/Server\=127.0.0.1,192.168.1.89/g"
/etc/zabbix/zabbix_agentd.conf
sed -i"s/ServerActive\=127.0.0.1/ServerActive\=192.168.1.89:10051/g"
/etc/zabbix/zabbix_agentd.conf
sed -i"s#tmp/zabbix_agentd.log#var/log/zabbix/zabbix_agentd.log#g"
/etc/zabbix/zabbix_agentd.conf
sed -i"#UnsafeUserParameters=0#aUnsafeUserParameters=1\n"
/etc/zabbix/zabbix_agentd.conf
vim /etc/zabbix/zabbix_agentd.conf
LogFile=/var/log/zabbix/zabbix_agentd.log
EnableRemoteCommands=0
Server=127.0.0.1,192.168.1.89
StartAgents=8
ServerActive=192.168.1.89:10051
Hostname=nat.kx1d.com
Timeout=30
Include=/etc/zabbix/zabbix_agentd.conf.d/
UnsafeUserParameters=1
bash-4.1# cp -r frontends/php/* /var/www/html/
bash-4.1# /etc/init.d/zabbix_server start
Starting zabbix_server: [ OK ]
bash-4.1# /etc/init.d/zabbix_agentd start
Starting zabbix_agentd: zabbix_agentd [8376]:/usr/local/etc/zabbix_agentd.userparams.conf: [2] No such file or directory
[ OK ]
[root@gmdai ~]# docker commit zabbix centos6-zabbix-v1
8567daabbc620ac4314135412385ffa017eb3f96a04c43a854c6733f269de86a
[root@gmdai ~]# docker p_w_picpaths
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos6-zabbix-v1 latest 8567daabbc62 43 secondsago 1.693 GB
[root@gmdai ~]# docker rm -f zabbix
Zabbix //刪除原來的zabbix容器,由於容器名字是惟一的,不刪除會報錯
root@gmdai ~]# docker run -itd --name zabbix -v /mnt/:/mnt/ -p10050:10050 -p 80:80 centos6-lamp
cb65aed2b86af4d7d8fad75fd97f37c38249dc5387e2effc53003ee7d101f2a7
[root@gmdai ~]# docker exec -it zabbix /bin/bash
重啓mysqld httpd這些服務,修改zabbix-agentd-conf參數爲Server=127.0.0.1,192.168.1.89 ServerActive=192.168.1.89:10051新容器啓動時的ip地址
重啓zabbix-server zabbix-agentd服務
再次訪問進行配置就好了
配置zabbix時出現date(): Itis not safe to rely on the system's timezone settings的報錯,網上找了答案是在php.ini中設置date.timezone的值爲PRC,設置好之後的爲:date.timezone=PRC,同時取消這一行代碼的註釋,即去掉前面的分號就能夠了。
遺留問題docker容器的ip不是固定的每次重啓都會從新分配