奥德赛F9 发表于 2017-12-31 15:03:44

CentOS 6.5安装zabbix

zabbix是一个基于web界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供报警的通知机制以让管理员能快速的定位/及时解决存在的各种问题  http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.2.9/zabbix-2.2.9.tar.gz
  zabbix由2部分构成,zabbix server与可选组件zabbix agent。
  zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。
  无论安装什么软件程序,最好是安装稳定版,不能只是为了一味追求最新版本,忽略了软件程序的稳定性,我个人的安装习惯是在最新版本的基础上往前推一两个版本,安装它的稳定版。
  1.编译安装nginx。
  1)编译安装pcre,nginx安装需要pcre的支持。
# mkdir -p /taokey/tools
# cd /taokey/tools/
# yum install -y gcc gcc-c++
# tar -zxf pcre-8.33.tar.gz
# cd pcre-8.33
# ./configure
# make && make install
# cd ..
  2)创建nginx普通用户,下载并解压nginx源码包。
# useradd nginx -s /sbin/nologin -M
# wget http://nginx.org/download/nginx-1.6.3.tar.gz
# tar -zxf nginx-1.6.3.tar.gz
# cd nginx-1.6.3
# yum -y install openssl openssl-devel
  3)编译安装nginx,然后启动nginx。
# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
# make && make install
# echo /usr/local/lib >>/etc/ld.so.conf
# ldconfig
# /usr/local/nginx/sbin/nginx -t
  nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
# /usr/local/nginx/sbin/nginx
# ps -ef | grep nginx
  root   11456   10 14:39 ?      00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
  nginx    11457 114560 14:39 ?      00:00:00 nginx: worker process
  root   1145917940 14:39 pts/1    00:00:00 grep nginx
  2.yum安装MySQL,启动MySQL。
# yum install -y mysql-server mysql-devel mysql
# /etc/init.d/mysqld start
# ps -ef | grep mysql
  root   11567   10 14:41 pts/1    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
  mysql    11669 115671 14:41 pts/1    00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
  root   1169317940 14:42 pts/1    00:00:00 grep mysql
# netstat -anpt | grep 3306
  tcp      0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      11669/mysqld
  3.yum安装PHP。
# yum install -y php php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel php-fpm php-pecl*
# sed -i 's/^user =.*/user = nginx/g' /etc/php-fpm.d/www.conf
# sed -i 's/^group =.*/group = nginx/g' /etc/php-fpm.d/www.conf
# /etc/init.d/php-fpm start
  正在启动 php-fpm:[确定]
# ps -ef | grep php
  root   11746   10 14:45 ?      00:00:00 php-fpm: master process (/etc/php-fpm.conf)
  nginx    11747 117460 14:45 ?      00:00:00 php-fpm: pool www
  nginx    11748 117460 14:45 ?      00:00:00 php-fpm: pool www
  nginx    11749 117460 14:45 ?      00:00:00 php-fpm: pool www
  nginx    11750 117460 14:45 ?      00:00:00 php-fpm: pool www
  nginx    11751 117460 14:45 ?      00:00:00 php-fpm: pool www
  root   1175417940 14:45 pts/1    00:00:00 grep php
  4.配置nginx,结合php环境。
  vi /usr/local/nginx/conf/nginx.conf
  server {
  listen       80;
  server_namelocalhost;
  location / {
  root   html;
  indexindex.html index.htm index.php;
  }
  location ~ \.php$ {
  root         html;
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_indexindex.php;
  fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
  include      fastcgi_params;
  include      fastcgi.conf;
  }
  }
# /usr/local/nginx/sbin/nginx -t
  nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
# /usr/local/nginx/sbin/nginx -s reload
  5.测试一下php环境是否可以正常运行。(测试如图,php环境没有问题)
# cat > /usr/local/nginx/html/index.php<<EOF
  <?php
  phpinfo();
  ?>
  EOFzabbix由2部分构成,zabbix server与可选组件zabbix agent。
  zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。
  无论安装什么软件程序,最好是安装稳定版,不能只是为了一味追求最新版本,忽略了软件程序的稳定性,我个人的安装习惯是在最新版本的基础上往前推一两个版本,安装它的稳定版。
  1.编译安装nginx。
  1)编译安装pcre,nginx安装需要pcre的支持。
# mkdir -p /taokey/tools
# cd /taokey/tools/
# yum install -y gcc gcc-c++
# tar -zxf pcre-8.33.tar.gz
# cd pcre-8.33
# ./configure
# make && make install
# cd ..
  2)创建nginx普通用户,下载并解压nginx源码包。
# useradd nginx -s /sbin/nologin -M
# wget http://nginx.org/download/nginx-1.6.3.tar.gz
# tar -zxf nginx-1.6.3.tar.gz
# cd nginx-1.6.3
# yum -y install openssl openssl-devel
  3)编译安装nginx,然后启动nginx。
# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
# make && make install
# echo /usr/local/lib >>/etc/ld.so.conf
# ldconfig
# /usr/local/nginx/sbin/nginx -t
  nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
# /usr/local/nginx/sbin/nginx
# ps -ef | grep nginx
  root   11456   10 14:39 ?      00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
  nginx    11457 114560 14:39 ?      00:00:00 nginx: worker process
  root   1145917940 14:39 pts/1    00:00:00 grep nginx
  2.yum安装MySQL,启动MySQL。
# yum install -y mysql-server mysql-devel mysql
# /etc/init.d/mysqld start
# ps -ef | grep mysql
  root   11567   10 14:41 pts/1    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
  mysql    11669 115671 14:41 pts/1    00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
  root   1169317940 14:42 pts/1    00:00:00 grep mysql
# netstat -anpt | grep 3306
  tcp      0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      11669/mysqld
  3.yum安装PHP。
# yum install -y php php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel php-fpm php-pecl*
# sed -i 's/^user =.*/user = nginx/g' /etc/php-fpm.d/www.conf
# sed -i 's/^group =.*/group = nginx/g' /etc/php-fpm.d/www.conf
# /etc/init.d/php-fpm start
  正在启动 php-fpm:[确定]
# ps -ef | grep php
  root   11746   10 14:45 ?      00:00:00 php-fpm: master process (/etc/php-fpm.conf)
  nginx    11747 117460 14:45 ?      00:00:00 php-fpm: pool www
  nginx    11748 117460 14:45 ?      00:00:00 php-fpm: pool www
  nginx    11749 117460 14:45 ?      00:00:00 php-fpm: pool www
  nginx    11750 117460 14:45 ?      00:00:00 php-fpm: pool www
  nginx    11751 117460 14:45 ?      00:00:00 php-fpm: pool www
  root   1175417940 14:45 pts/1    00:00:00 grep php
  4.配置nginx,结合php环境。
  vi /usr/local/nginx/conf/nginx.conf
  server {
  listen       80;
  server_namelocalhost;
  location / {
  root   html;
  indexindex.html index.htm index.php;
  }
  location ~ \.php$ {
  root         html;
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_indexindex.php;
  fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
  include      fastcgi_params;
  include      fastcgi.conf;
  }
  }
# /usr/local/nginx/sbin/nginx -t
  nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
# /usr/local/nginx/sbin/nginx -s reload
  5.测试一下php环境是否可以正常运行。(测试如图,php环境没有问题)
# cat > /usr/local/nginx/html/index.php<<EOF
  <?php
  phpinfo();
  ?>
  EOF

6.安装zabbix server端软件包。  1)安装相应的库和软件包,并且创建zabbix用户。
# yum -y install libcurl-devel net-snmp-devel
# useradd zabbix -s /sbin/nologin
  2)下载zabbix源码包,编译安装zabbix。
# #wgethttp://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.2.9/zabbix-2.2.9.tar.gz# tar -zxf zabbix-2.2.9.tar.gz
# cd zabbix-2.2.9
# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl
# make install
  7.在MySQL中创建zabbix所需数据库,以及账号密码。
# mysql
  Welcome to the MySQL monitor.Commands end with ; or \g.
  Your MySQL connection id is 2
  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> create database zabbix character set utf8;
  Query OK, 1 row affected (0.00 sec)
  mysql> grant all privileges on zabbix.* to zabbix@'%' identified by 'zabbix';
  Query OK, 0 rows affected (0.01 sec)
  mysql> delete from mysql.user where user="";
  Query OK, 2 rows affected (0.00 sec)
  mysql> flush privileges;
  Query OK, 0 rows affected (0.00 sec)
  8.zabbix数据导入创建好的zabbix数据库中。
# mysql -uzabbix -pzabbix -h127.0.0.1 zabbix < database/mysql/schema.sql
# mysql -uzabbix -pzabbix -h127.0.0.1 zabbix < database/mysql/images.sql
# mysql -uzabbix -pzabbix -h127.0.0.1 zabbix < database/mysql/data.sql
  9.拷贝zabbix服务端和客户端的启动文件。
# cp misc/init.d/fedora/core/zabbix_server /etc/init.d/
# cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
  10.修改配置文件及启动文件。
# sed -i 's/^DBUser=.*$/DBUser=zabbix/g' /usr/local/zabbix/etc/zabbix_server.conf
# sed -i 's/^.*DBPassword=.*$/DBPassword=zabbix/g' /usr/local/zabbix/etc/zabbix_server.conf
# sed -i 's/^.*DBHost=.*$/DBHost=127.0.0.1/g' /usr/local/zabbix/etc/zabbix_server.conf
# sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_server
# sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_agentd
  11.在/etc/services文件中,添加zabbix服务端口。
# cat >>/etc/services <<EOF
  zabbix-agent   10050/tcp       #Zabbix Agent
  zabbix-agent   10050/udp       #Zabbix Agent
  zabbix-trapper   10051/tcp       #Zabbix Trapper
  zabbix-trapper   10051/udp       #Zabbix Trapper
  EOF
# tail -4 /etc/services
  zabbix-agent    10050/tcp               #Zabbix Agent
  zabbix-agent    10050/udp               #Zabbix Agent
  zabbix-trapper10051/tcp               #Zabbix Trapper
  zabbix-trapper10051/udp               #Zabbix Trapper
  12.复制zabbix程序文件端到nginx的指定web目录下,并且设置相应权限。
# cp -ra frontends/php/ /usr/local/nginx/html/zabbix
# chown -R nginx.nginx /usr/local/nginx/html/zabbix
  13.启动zabbix server和zabix agent。
# /etc/init.d/zabbix_server start
# /etc/init.d/zabbix_agentd start
# netstat -anpt | grep 10050
  tcp      0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      19850/zabbix_agentd
# netstat -anpt | grep 10051
  tcp      0      0 0.0.0.0:10051               0.0.0.0:*                   LISTEN      19786/zabbix_server
  tcp      0      0 127.0.0.1:10051             127.0.0.1:37229             TIME_WAIT   -
  14.在浏览器输入: http://10.10.21.15/zabbix/setup.php 安装zabbix server的web界面。

  点击Next:

  php安装会遇到几个报错,解决方法:
  15.修改php配置满足zabbix安装要求。
# sed -i 's/^\(.*\)date.timezone =.*$/date.timezone = Asia\/Shanghai/g' /etc/php.ini
# sed -i 's/^\(.*\)post_max_size =.*$/post_max_size = 16M/g' /etc/php.ini
# sed -i 's/^\(.*\)max_execution_time =.*$/max_execution_time = 300/g' /etc/php.ini
# sed -i 's/^\(.*\)max_input_time =.*$/max_input_time = 300/g' /etc/php.ini
# /etc/init.d/php-fpm restart
  修改完之后,然后再重新刷新页面,如图所示:

  然后再点击Next,进行下一步:

端口:3306帐号:zabbix密码:zabbix  输入相应的数据库信息,然后测试连接, 没有问题,继续下一步:

  此页面,可以设置成默认的Host和Port,然后点击下一步:

  继续点击下一步 Next:

  安装到这里,说明已经安装完成了,最后点击Finish,完成安装即可。

  Zabbix默认的账号admin,默认密码是zabbix,咱们登陆进去。

zabbix2.2.9安装之后语言选项中没有Chinese (zh_CN) 选项,虽然不建议使用这个汉化版本,但是对于有日文选项而没有中文来说。还是有些不爽,好了,修改方式如下:  在zabbix服务端的安装目录下找到/usr/local/nginx/html/zabbix/include/locales.inc.php 把false修改成true,然后保存退出即可。
# vim /usr/local/nginx/html/zabbix/include/locales.inc.php +58
  'zh_CN' => array('name' => _('Chinese (zh_CN)'),      'display' => true),
  此时,刷新页面,就可以找到中文版本。
注意:!!!    1.替换监控图像上系统默认的字体 #默认字体不支持中文,如果不替换,图像上会显示乱码 :在Windows系统中的C:\Windows\Fonts目录中复制出一个中文字体文件,例如simhei.ttf    把字体文件simhei.ttf上传到zabbix站点根目录下fonts文件夹中 例如:/usr/local/nginx/html/zabbix/fonts备份默认的字体文件:DejaVusSans.ttf-bak 修改 simhei.ttf 名称为DejaVusSans.ttf   就能解决图形乱码的问题

  保存之后,就成为了汉化版本的zabbix页面。

  zabbix客户端安装步骤:
  1)编译安装zabbix。
# mkdir -p /taokey/tools
# useradd zabbix -s /sbin/nologin -M
# tar -zxf zabbix-2.2.9.tar.gz
# cd zabbix-2.2.9
# ./configure --prefix=/usr/local/zabbix --enable-agent
# make && make install
  2)修改zabbix_agentd.conf和/etc/init.d/zabbix_agentd的配置文件。
# cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
# vim /usr/local/zabbix/etc/zabbix_agentd.conf +81
  Server=10.10.21.15    #修改客户端配置文件的Server为zabbix服务器的IP地址。
# vim /etc/init.d/zabbix_agentd
  # Variables
  # Edit these to match your system settings
  # Zabbix-Directory
  BASEDIR=/usr/local/zabbix
  3)启动zabbix_agentd。
# /etc/init.d/zabbix_agentd start
  Starting zabbix_agentd:[确定]
# ps -ef | grep zabbix
  zabbix    9030   10 14:30 ?      00:00:00 /usr/local/zabbix/sbin/zabbix_agentd
  zabbix    903190300 14:30 ?      00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: collector
  zabbix    903290300 14:30 ?      00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: listener #1
  zabbix    903390300 14:30 ?      00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: listener #2
  zabbix    903490300 14:30 ?      00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: listener #3
  zabbix    903590300 14:30 ?      00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: active checks #1
  root      904089840 14:31 pts/0    00:00:00 grep zabbix
# netstat -anpt | grep zabbix
  tcp      0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      9030/zabbix_agentd
  4)设置zabbix客户端开机自启动。
# chkconfig --add zabbix_agentd
# chkconfig zabbix_agentd on
# chkconfig --list zabbix_agentd
  zabbix_agentd   0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
  对客户端的监控图形:

页: [1]
查看完整版本: CentOS 6.5安装zabbix