zabbix v3.0安装及使用
学习资料: ITIL培训基地专家讲堂直播 300期视频回放
关于zabbix及相关服务软件版本Linux:centos 6.6nginx:1.9.15MySQL:5.5.49PHP:5.5.35安装nginx
[*]安装依赖包
$ yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel
[*]创建用户
$ useradd nginx -s /sbin/nologin -M
[*]下载nginx软件包并进入到目录中
$ wget download/nginx-1.9.15.tar.gz && tar xvf nginx-1.9.15.tar.gz && cd nginx-1.9.15
[*]编译安装
$ ./configure --prefix=/usr/local/product/nginx1.9.14 --user=www --group=www --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre$ make && make install$ ln -s /usr/local/product/nginx1.9.14 /usr/local/nginx // 创建软链接
[*]参数解释
--with-http_stub_status_module:支持nginx状态查询 --with-http_ssl_module:支持https --with-http_spdy_module:支持google的spdy,想了解请百度spdy,这个必须有ssl的支持 --with-pcre:为了支持rewrite重写功能,必须制定pcre安装PHP
[*]下载PHP安装包
$ wget get/php-5.5.35.tar.gz/from/this/mirror
[*]解压并编译
$ mv mirror php-5.5.35.tar.gz && tar xvf php-5.5.35.tar.gz && cd php-5.5.35$ ./configure --prefix=/usr/local/product/php-5.5.35 --with-config-file-path=/usr/local/product/php-5.5.35/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath$ make && make install$ ln -s /usr/local/product/php-5.5.35 /usr/local/php$ cp php.ini-production /usr/local/php/etc/php.ini$ cd /usr/local/php/etc/$ cp php-fpm.conf.default php-fpm.conf
[*]修改php.ini参数:(zabbix环境需要修改的参数)
max_execution_time = 300memory_limit = 128Mpost_max_size = 16Mupload_max_filesize = 2Mmax_input_time = 300date.timezone = PRC安装MySQL
[*]添加mysql用户,创建mysql的数据目录
$ groupadd mysql$ mkdir -pv /data/mysql$ useradd -r -g mysql -d /data/mysql -s /sbin/nologin mysql$ chown -R mysql.mysql /data/mysql
[*]安装cmake及依赖
$ yum install cmake gcc* ncurses-devel -y
[*]下载MySQL安装包
$ wget get/Downloads/MySQL-5.5/mysql-5.5.49.tar.gz
[*]编译安装MySQL
$ tar -xvf mysql-5.5.49.tar.gz && cd mysql-5.5.49$ cmake -DCMAKE_INSTALL_PREFIX=/usr/local/product/mysql5.5.49 -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DDEFAULT_COLLATION=utf8_general_ci$ make && make install$ ln -s /usr/local/product/mysql5.5.49 /usr/local/mysql$ chown -R mysql.mysql /usr/local/mysql
[*]拷贝mysql的配置文件
$ cd /usr/local/mysql/support-files/$ cp my-medium.cnf /data/mysql/my.cnf$ cp mysql.server /etc/init.d/mysqld$ chmod +x /etc/init.d/mysqld
[*]初始化MySQL
$ cd /usr/local/mysql/scripts$ ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/
[*]修改MySQL配置文件my.cnf中数据目录
datadir=/data/mysql/
[*]启动MySQL
$ /etc/init.d/mysqld start
[*]登录数据库,创建zabbix数据库及用户名和密码
mysql> create database zabbix default charset utf8;Query OK, 1 row affected (0.00 sec)mysql> grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix';Query OK, 0 rows affected (0.03 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)
[*]如果登录数据库出现问题
$ mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)解决办法:$ ln -s /tmp/mysql.sock /var/lib/mysql/
[*]为数据库的root创建密码
$ mysqladmin -uroot password"zabbix"安装zabbix server
[*]下载安装包
$ wget projects/zabbix/files/ZABBIX%20Latest%20Stable/3.0.3/zabbix-3.0.3.tar.gz
[*]安装zabbix
$ tar zxf zabbix-3.0.3.tar.gz && cd zabbix-3.0.3$ ./configure --prefix=/usr/local/zabbix-3.0.3/ --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2$ make && make install
[*]编译过程中如果有报错
故障1:checking for mysql_config... noconfigure: error: MySQL library not found解决: $ yum install mysql-devel -y故障2:checking for net-snmp-config... noconfigure: error: Invalid Net-SNMP directory - unable to find net-snmp-config解决: $ yum install net-snmp-devel -y
[*]创建zabbix用户
$ groupadd zabbix$ useradd zabbix -s /sbin/nologin -M -g zabbix
[*]zabbix server需要导入3个sql文件
$ mysql -uroot -pzabbix zabbix < database/mysql/schema.sql $ mysql -uroot -pzabbix zabbix < database/mysql/images.sql$ mysql -uroot -pzabbix zabbix < database/mysql/data.sqlzabbix管理网站配置(nginx)
[*]创建项目目录
$ mkdir /data/web/-p$ mkdir /data/logs/zabbix -p
[*]将前端文件拷贝到项目目录下
$ cp -rp frontends/php/* /data/web/ /
[*]编辑nginx虚拟主机
$ pwd /usr/local/nginx/conf$ cd extra/$ vim zabbix.confserver {listen 16888;server_name ;access_log /data/logs/zabbix/zabbix.lifec.com.access.log main;index index.html index.php index.html;root /data/web/zabbix.lifec.com;location /{ try_files $uri $uri/ /index.php?$args;}location ~ ^(.+.php)(.*)$ { fastcgi_split_path_info ^(.+.php)(.*)$; include fastcgi.conf; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param PATH_INFO $fastcgi_path_info;}}
[*]编辑nginx.conf配置文件
$ vim nginx.confusernginx;worker_processes1;#error_loglogs/error.log warning;#error_loglogs/error.lognotice;#error_loglogs/error.loginfo;pid logs/nginx.pid;events { worker_connections1024;}http { include mime.types; default_typeapplication/octet-stream; log_formatmain'$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_loglogs/access.logmain; sendfile on; #tcp_nopush on; #keepalive_timeout0; keepalive_timeout65; #gzipon; include extra/*.conf;}
[*]编辑zabbix_server.conf文件
$ vim etc/zabbix_server.confLogFile=/tmp/zabbix_server.logPidFile=/tmp/zabbix_server.pidDBHost=localhostDBName=zabbixDBUser=zabbixDBPassword=zabbix启动服务
[*]启动nginx
$ /usr/local/nginx/sbin/nginx
[*]启动PHP
$ /usr/local/php/sbin/php-fpm
[*]启动zabbix server
$ /usr/local/zabbix-3.0.3/sbin/zabbix_server如果启动的时候报错:$ /usr/local/zabbix-3.0.2/sbin/zabbix_server /usr/local/zabbix-3.0.2/sbin/zabbix_server: error while loa** shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory$ ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
[*]添加/etc/hosts文件
10.0.0.1
[*]将服务加入开机自启动
$ echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local$ echo "/usr/local/php/sbin/php-fpm" >>/etc/rc.local $ echo "/etc/init.d/mysqld start" >>/etc/rc.local$ echo "/usr/local/zabbix-3.0.3/sbin/zabbix_server" >>/etc/rc.localweb端配置zabbix
[*]浏览器安装:http://10.0.0.1:16888
[*]
[*]
[*]
[*]
[*]
[*]需要下载文件,上传到指定的服务器目录中并修改属组
$ pwd /data/web/ /conf$ chown 1000:1000 zabbix.conf.php
[*]使用用户名(Admin)和密码(zabbix)登录
[*]修改界面为中文界面
$ vim /data/web/ /include/locales.inc.php'zh_CN' => ['name' => _('Chinese (zh_CN)'), 'display' => true],$ unzip yaheiFont_CHS.zip //文件在git的fonts目录里 $ rz msyh.ttf$ cd /data/web/ /fonts$ mv DejaVuSans.ttf DejaVuSans_bak$ mv msyh.ttf DejaVuSans.ttf$ chown 1000:1000 DejaVuSans.ttf//重启服务即可zabbix-agent 安装
[*]下载
$ rpm -Uvh zabbix/3. ... .3-1.el6.x86_64.rpm
[*]问题报错
error: Failed dependencies: libodbc.so.2()(64bit) is needed by zabbix-agent-3.0.3-1.el6.x86_64解决办法:$ yum -y install unixODBC
[*]修改配置配置文件
$ vim /etc/zabbix/zabbix_agentd.conf PidFile=/var/run/zabbix/zabbix_agentd.pidLogFile=/var/log/zabbix/zabbix_agentd.logLogFileSize=0Server=10.0.0.1ServerActive=10.0.0.1Hostname=8.8.8.8Include=/etc/zabbix/zabbix_agentd.d/自动注册和自动发现
[*]区别
[*]自动发现: 适用于提供相同服务的Server群组,因为自动发现是批量添加Discovery Host的,你可以让所有主机链接同一个模板,并且让他们提供相同的服务。没错,如果你学过Shell,并且能写出批量部署服务的脚本,那么这个自动发现再适合你不过了。
[*]自动注册: 自动注册呢,它是比较灵活的,根据HostMetadata的value来匹配规则,并且通过不同的值来执行不同的操作。
也就是说,如果是普通Server,你只要把value设置为Linux,并且让它链接普通的模板
如果是MysqlServer,你可以把value设置为Mysql,并且让它链接Mysql和普通的模板。
[*]自动发现
[*]主机自动发现
ii.端口自动发现
[*]先创建自动发现脚本:vim /etc/zabbix/zabbix_scripts/disc_port.sh
自定义key值:vim /etc/zabbix/zabbix_agentd.d/disc_port.conf
添加需要自动发现的端口描述文件:vim /etc/zabbix/zabbix_scripts/dport_check.d/tes.conf
$ cat /etc/zabbix/zabbix_scripts/dport_check.d/tes.conf127.0.0.1:12066:docker_tes//#IP:#PORT:#DESC
[*]自动注册 (跟自动发现异曲同工,这里就不做详情说明)
[*]原创: Zline
页:
[1]