【zabbix简介】
- zabbix(音同 zæbix)是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
- zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
- zabbix由2部分构成,zabbix server与可选组件zabbix agent。
- zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上
【zabbix安装】
- 系统:CentOS Linux release 7.1.1503 (Core)
- 用户:普通用户aspire
- 所用软件包: apr-1.4.6.tar.gz httpd-2.4.4.tar.gz mariadb-5.5.30-linux-x86_64.tar.gz php-5.4.14.tar.gz apr-util-1.5.2.tar.gz libmcrypt-2.5.7.tar.gz pcre-8.32.tar.gz zabbix.tar.gz
编译安装lamp环境
vim /etc/security/limits.conf 添加如下内容:
* soft nproc 65535* hard nproc 65535* soft nofile 65535* hard nofile 65535
vim etcsysctl.conf 添加如下内容:
net.ipv4.tcp_max_tw_buckets = 6000net.core.wmem_default = 8388608net.core.rmem_default = 8388608net.core.rmem_max = 16777216net.core.wmem_max = 16777216net.core.netdev_max_backlog = 262144net.core.somaxconn = 262144 net.ipv4.tcp_max_orphans = 3276800net.ipv4.tcp_max_syn_backlog = 262144net.ipv4.tcp_timestamps = 0net.ipv4.tcp_synack_retries = 1net.ipv4.tcp_syn_retries = 1net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_mem = 94500000 915000000 927000000net.ipv4.tcp_fin_timeout = 1net.ipv4.tcp_keepalive_time = 30net.ipv4.ip_local_port_range = 1024 65000fs.file-max = 65535
使用root用户安装如下包:
yum -y install setuptool ntsysv system-config-securitylevel-tui system-config-network-tui system-config-keyboard vim libxslt-devel lua-devel libatomic_ops fontconfig-devel make gcc gcc-c++ bzip2 bzip2-devel curl-devel perl freetype freetype-devel gd gd-devel libpng libiconv libjpeg libpng-devel libjpeg-devel libxml2 zlib zlib-devel libxml2-devel libmcrypt libmcrypt-devel fontconfig libXpm libXpm-devel libX11 libX11-devel openssl dstat libtool php-bcmath net-snmp-devel
使用root账户按照如下次序安装
tar zxvf libmcrypt-2.5.7.tar.gz cd libmcrypt-2.5.7 && ./configure --prefix=/usr && make && make install
使用普通用户依次安装
tar zxvf apr-1.4.6.tar.gzcd apr-1.4.6 && ./configure --prefix=$HOME/apps/apr && make && make installtar zxvf apr-util-1.5.2.tar.gzcd apr-util-1.5.2 && ./configure --prefix=$HOME/apps/apr-util --with-apr=$HOME/apps/apr && make && make installtar zxvf pcre-8.32.tar.gzcd pcre-8.32 && ./configure --prefix=$HOME/apps/pcre && make && make install
安装mariadb
-
解压
tar zxvf mariadb-5.5.30-linux-x86_64.tar.gz mv mariadb-5.5.30-linux-x86_64 ~/apps/mysql cd /home/aspire/apps/mysql cp support-files/my-innodb-heavy-4G.cnf my.cnf
-
修改my.cnf配置
default-storage-engine = INNODB datadir = /home/aspire/apps/mysql/data log-bin=/home/aspire/apps/mysql/logs/mysql-bin slow_query_log slow_query_log_file=/home/aspire/apps/mysql/logs
-
安装数据库
./scripts/mysql_install_db --defaults-file=/home/aspire/apps/mysql/my.cnf
-
启动mysql
./bin/msyqld_safe &
-
设置mysql的密码
./bin/mysqladmin -u root password "123456"
-
连接测试
[aspire@BJ-YZ-103R-81-6 mysql]$ ./bin/mysql -uroot -p123456 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 5.5.30-MariaDB-log MariaDB Server Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
编译安装httpd
tar zxvf httpd-2.4.4.tar.gz cd httpd-2.4.4 ./configure --prefix=$HOME/apps/apache --with-mpm=prefork --with-ssl=/usr/local/apache/openssl --enable-ssl --enable-module=setenvif --enable-module=so --enable-rewrite --enable-dav --enable-dav-fs --enable-suexec --enable-headers --enable-deflate --enable-expires --enable-proxy --enable-proxy-connect --enable-proxy-ftp --enable-proxy-http --with-apr=$HOME/apps/apr --with-apr-util=$HOME/apps/apr-util --with-pcre=$HOME/apps/pcre --enable-cgi --enable-cgidmake && make install
php前置配置 安装php过程中出现找不到libXpm.(ao)及libgd.(ao)的情况
ln -s /usr/lib64/libgd.so.2.0.0 /usr/lib/libgd.soln -s /usr/lib64/libXpm.so.4.11.0 /usr/lib/libXpm.so
编辑/usr/include/gd_io.h
typedef struct gdIOCtx{ int (getC) (struct gdIOCtx ); int (getBuf) (struct gdIOCtx , void , int); void (putC) (struct gdIOCtx , int); int (putBuf) (struct gdIOCtx , const void , int); seek must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek! int (seek) (struct gdIOCtx , const int); long (tell) (struct gdIOCtx ); void (gd_free) (struct gdIOCtx ); void (data * ); 添加这里}gdIOCtx;
安装支持apache的php安装目录为php5
tar php-5.4.14.tar.gzcd php-5.4.14./configure --prefix=$HOME/apps/php5 --with-config-file-path=$HOME/apps/php5/etc --with-apxs2=$HOME/apps/apache/bin/apxs --with-mysql=$HOME/apps/mysql --with-mysqli=$HOME/apps/mysql/bin/mysql_config --with-pdo-mysql=$HOME/apps/mysql --with-gd=/usr --with-jpeg-dir=/usr --with-png-dir=/usr --with-freetype-dir=/usr --with-openssl --with-bz2 --with-zlib --with-xmlrpc --with-curl --with-gettext --with-iconv-dir=/usr --with-curlwrappers --with-mcrypt=$HOME/apps/lib/mcrypt --with-kerberos --with-imap-ssl --with-mhash --enable-pdo --enable-mbstring --enable-mbregex --enable-ctype --enable-json --enable-gd-native-ttf --enable-sockets --enable-calendar --enable-soap --enable-ftp --enable-fileinfo --enable-exif --enable-zip --disable-debug --with-xpm-dir=/usr --with-libxml-dir --without-pdo-sqlite --disable-ipv6 --enable-simplexml --enable-bcmath #启用bcmatch(公元前风格精度数学)
设置apache及php 拷贝php源安装文件夹里的php.ini-development到$HOME/apps/php5/etc/php.ini 修改php.ini文件里的
post_max_size = 16Mmax_execution_time = 300date.timezone = Asia/Shanghaiinclude_path = /home/aspire/apps/php5/lib/php
建立连接
cd /binln -s /home/aspire/apps/php5/bin/php php
修改httpd.conf文件添加
Listen 8080LoadModule socache_shmcb_module modulesmod_socache_shmcb.soLoadModule slotmem_shm_module modulesmod_slotmem_shm.soLoadModule rewrite_module modulesmod_rewrite.soAddType application/x-httpd-php .phpAddType applicaiton/x-httpd-php-source .phpsInclude confvhosts.conf
添加/usr/lib及/usr/lib64到/etc/ld.so.conf文件中
#vim /etc/ld.so.confinclude ld.so.conf.d/*.conf/usr/lib/usr/lib64/lib/lib64#ldconfig
server,agent安装(服务端)
./configure --prefix=/home/aspire/apps/zabbix --enable-server --enable-agent --with-mysql=/home/aspire/apps/mysql/bin/mysql_config --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2make && make install
tail -4 /etc/services(尾部追加)zabbix-agent 10050/tcp #Zabbix Agentzabbix-agent 10050/udp #Zabbix Agentzabbix-server 10051/tcp #zabbix Trapperzabbix-server 10051/udp #zabbix Trapper
导入数据库
# mysql -uroot -pmysql> create database zabbix character set utf8;mysql> grant all on zabbix.* to zabbix@localhost identified by 'zabbix';# mysql -uzabbix -pzabbix zabbix<./database/mysql/schema.sql# mysql -uzabbix -pzabbix zabbix<./database/mysql/images.sql# mysql -uzabbix -pzabbix zabbix<./database/mysql/data.sql
编辑服务端配置文件
[aspire@BJ-YZ-103R-81-6 ~]$ vim apps/zabbix/etc/zabbix_server.confLogFile=/home/aspire/logs/zabbix/zabbix_server.log #日志路径PidFile=/home/aspire/apps/zabbix/run/zabbix_server.pidDBName=zabbix #数据库名DBUser=zabbix #数据库用户DBPassword=zabbix #数据库密码DBSocket=/home/aspire/apps/mysql/tmp/mysql.sock #连接数据库的socket
安装客户端
cd srctar -zxvf zabbix-3.0.7.tar.gzcd zabbix-3.0.7 ./configure --prefix=/home/aspire/apps/zabbix --enable-agent make && make installmkdir -p $HOME/apps/zabbix/runmkdir -p $HOME/logs/zabbix && touch $HOME/logs/zabbix/zabbix_agentd.log
客户端的配置文件格式
PidFile=/home/aspire/apps/zabbix/run/zabbix_agentd.pidLogFile=/home/aspire/logs/zabbix/zabbix_agentd.logServer=192.168.81.6,192.168.81.204 #server端的地址,客户端处于被动模式时,只允许所列的IP访问客户端ServerActive=192.168.81.6 #主动模式时客户端会向此server ip主动发送数据Hostname=192.168.81.4RefreshActiveChecks=60UnsafeUserParameters=1Include=/home/aspire/apps/zabbix/etc/zabbix_agentd.conf.d/
启动服务端
$HOME/apps/zabbix/sbin/zabbix_server -c $HOME/apps/zabbix/etc/zabbix_server.conf
现在登录服web界面进入zabbix的世界吧 修改zabbix server配置文件
注意:设置是php可能会显示无法连接mysql,是因为php默认用/tmp/mysql.sock 连接数据库。只需要将/home/aspire/apps/mysql/tmp/mysql.sock连接过去即可
ln -s /home/aspire/apps/mysql/tmp/mysql.sock /tmp/mysql.sock