Public Repository

Last pushed: 2 years ago
Short Description
Short description is empty for this repo.
Full Description

Full description is empty for this repo.

Docker Pull Command
Owner
xiongli

Comments (1)
xiongli
2 years ago

1.安装环境
docker Ubuntu 14.10

2.安装步骤

wget http://repo.zabbix.com/zabbix/2.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_2.4-1+trusty_all.deb

dpkg -i zabbix-release_2.4-1+trusty_all.deb

apt-get update

apt-get install zabbix-server-mysql zabbix-frontend-php

3.系统环境
docker CentOS 7

4.步骤
zabbix 下载地址
http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.4.2/zabbix-2.4.2.tar.gz

docker run -t -i centos /bin/bash

bash-4.2# cat /etc/issue
\S
Kernel \r on an \m

yum upgrade -y

yum -y install curl curl-devel net-snmp net-snmp-devel perl-DBI php-gd php-xml php-bcmath php-mysql php-mbstring mariadb mariadb-server mariadb-devel wget tar

yum install gcc gcc-c++ autoconf make

yum install httpd mariadb mariadb-server php

wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.4.2/zabbix-2.4.2.tar.gz

tar zxvf zabbix-2.4.2.tar.gz

cd zabbix-2.4.2

mkdir /mysql

vi /etc/passwd

mysql:x:27:27:MariaDB Server:/mysql:/sbin/nologin

chown -R mysql:mysql /mysql

bash-4.2# vi /etc/my.cnf
[mysqld]
port = 3306
socket = /mysql/mysql.sock
pid-file = /mysql/mysqld.pid
datadir = /mysql
back_log = 50
character_set_server=utf8
expire_logs_days = 15
log_bin_trust_function_creators = 1
binlog-ignore-db = mysql
binlog-ignore-db = test
binlog-ignore-db = information_schema
skip-name-resolve
external-locking = FALSE
skip-external-locking
max_connections = 10240
max_connect_errors = 3072
table_open_cache = 2048
max_allowed_packet = 16M
binlog_cache_size = 1M
max_heap_table_size = 64M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 8
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 4M
ft_min_word_len = 4
thread_stack = 192K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 64M

#log-bin=mysql-bin

#binlog_format=mixed
concurrent_insert = 2
max_binlog_cache_size = 8M
slow_query_log
long_query_time = 2
server-id = 1
key_buffer_size = 128M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 8G
innodb_data_file_path = ibdata1:10M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 1
[mysqld_safe]
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192

mysql_install_db --user=mysql --datadir=/mysql

启动 mysql

mysqld_safe --datadir='/mysql' &

ln -s /mysql/mysql.sock /var/lib/mysql/mysql.sock

mysql -uroot -p -h127.0.0.1

create database zabbix;
grant all on zabbix.* to zabbix@localhost identified by 'zabbix';
flush privileges;

mysql -uroot zabbix < database/mysql/schema.sql

mysql -uroot zabbix <database/mysql/images.sql

mysql -uroot zabbix < database/mysql/data.sql

./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-proxy --with-mysql --with-net-snmp --with-libcurl

make && make install

mkdir -p /var/www/html

mkdir -p /var/log/httpd

chown apache:apache /var/www/html /var/log/httpd

cp -r frontends/php /var/www/html/zabbix

配置 zabbix

cd /etc/zabbix

cp -r ./conf/* /etc/zabbix/

cp misc/init.d/fedora/core5/zabbix_server /etc/init.d/

cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/

chmod a+x /etc/init.d/zabbix_server

chmod a+x /etc/init.d/zabbix_agentd

vi /etc/init.d/zabbix_server

ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server"

vi /etc/init.d/zabbix_agentd

ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"

#vi /etc/zabbix/zabbix_server.conf
DBName=zabbix
DBUser=zabbix
DBUDBPassword=zabbix

cd /usr/local/zabbix/bin/

for i in *;do ln -s /usr/local/zabbix/bin/${i} /usr/bin/${i};done

cd /usr/local/zabbix/sbin/

for i in *;do ln -s /usr/local/zabbix/sbin/${i} /usr/sbin/${i};done

vi /etc/php.ini

max_input_time = 600
max_execution_time = 300
date.timezone = Asia/Shanghai
post_max_size = 32M
memory_limit = 128M

mbstring.func_overload = 2

启动
httpd
监听端口改成 0.0.0.0:80

访问

curl -v 172.17.0.3/zabbix

启动 zabbix_server 和 zabbix_agentd 时会提示很多错误,大多是文件夹没有,一一创建并授权就行
zabbix_agentd.conf
zabbix_server.conf
允许 root 启动

AllowRoot=0

AllowRoot=1

保存容器
bash-4.2# hostname
f0c4804d5a7c

docker commit f0c4804d5a7c xiongli/zabbix

启动容器,以端口为80启动
不能启动

docker run -d -p 80:80 --name=zabbix xiongli/zabbix /bin/sh -c "/usr/bin/mysqld_safe --datadir='/mysql' && /usr/sbin/httpd && /etc/init.d/zabbix_server start && /etc/init.d/zabbix_agentd start && while true; do sleep 999999; done"

vi /etc/init.d/start_zabbix

#!/bin/bash
/usr/sbin/httpd
sleep 10
/etc/init.d/zabbix_server start
sleep 10
/etc/init.d/zabbix_agentd start
sleep 10
/usr/bin/mysqld_safe --datadir='/mysql' &
sleep 10
ln -s /mysql/mysql.sock /var/lib/mysql/mysql.sock

docker run -d -p 80:80 --name=zabbix xiongli/zabbix /bin/sh -c "/etc/init.d/start_zabbix && while true; do sleep 999999; done"

访问:
http://ip/zabbix
配置 web
加入本主机的监控

uctest:

docker run -d -p 10081:80 --name=zabbix xiongli/zabbix /bin/sh -c "/etc/init.d/start_zabbix && while true; do sleep 999999; done"

5.zabbix 对 linux主机的监控
docker CentOS 7
root@docker:/home/docker# docker run -i -t centos /bin/bash
bash-4.2# cat /etc/issue
\S
Kernel \r on an \m

bash-4.2# uname -r
3.16.0-23-generic
二进制内核不匹配,只能选择源码安装了

这里不做升级,直接安装 zabbix_agents

yum install wget tar -y

mkdir -p /usr/local/zabbix_agentd/

cd /root

wget http://www.zabbix.com/downloads/2.4.1/zabbix_agents_2.4.1.linux2_6_23.amd64.tar.gz

tar zxvf zabbix_agents_2.4.1.linux2_6_23.amd64.tar.gz -C /usr/local/zabbix_agentd/

chmod a+x /usr/local/zabbix_agentd -R

groupadd zabbix

useradd -g zabbix -m zabbix

chown -R zabbix:zabbix /usr/local/zabbix_agentd

cd /usr/local/zabbix_agentd

vi conf/zabbix_agent.conf

Server=0.0.0.0

cp -r conf/* /usr/local/etc

启动

./sbin/zabbix_agentd start

bash-4.2# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :10050 :*

源码安装 zabbix_agentd

yum install wget tar gcc gcc-c++ make autoconf

wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.4.2/zabbix-2.4.2.tar.gz

tar zxvf zabbix-2.4.2.tar.gz

cd zabbix-2.4.2

./configure --prefix=/usr/local/zabbix --enable-agent

make all

make install

cp misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/

chmod a+x /etc/init.d/zabbix_agentd

vi /etc/init.d/zabbix_agentd

ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"

cd /usr/local/zabbix/bin/

for i in *;do ln -s /usr/local/zabbix/bin/${i} /usr/bin/${i};done

cd /usr/local/zabbix/sbin/

for i in *;do ln -s /usr/local/zabbix/sbin/${i} /usr/sbin/${i};done

vi /usr/local/zabbix/etc/zabbix_agent.conf

Server=0.0.0.0