怎样安装部署及使用zabbix v3.0
学习资料:IT运维管理社区专家讲堂直播300期视频回放
关于zabbix及相关服务软件版本Linux:centos6.6nginx:1.9.15MySQL:5.5.49PHP:5.5.35安装nginx
[*]安装依赖包
$yum-yinstallgccgcc-c++autoconfautomakezlibzlib-developensslopenssl-develpcre*makegd-devellibjpeg-devellibpng-devellibxml2-develbzip2-devellibcurl-devel
[*]创建用户
$useraddnginx-s/sbin/nologin-M
[*]下载nginx软件包并进入到目录中
$wgetdownload/nginx-1.9.15.tar.gz&&tarxvfnginx-1.9.15.tar.gz&&cdnginx-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&&makeinstall$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安装包
$wgetget/php-5.5.35.tar.gz/from/this/mirror
[*]解压并编译
$mvmirrorphp-5.5.35.tar.gz&&tarxvfphp-5.5.35.tar.gz&&cdphp-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&&makeinstall$ln-s/usr/local/product/php-5.5.35/usr/local/php$cpphp.ini-production/usr/local/php/etc/php.ini$cd/usr/local/php/etc/$cpphp-fpm.conf.defaultphp-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的数据目录
$groupaddmysql$mkdir-pv/data/mysql$useradd-r-gmysql-d/data/mysql-s/sbin/nologinmysql$chown-Rmysql.mysql/data/mysql
[*]安装cmake及依赖
$yuminstallcmakegcc*ncurses-devel-y
[*]下载MySQL安装包
$wgetget/Downloads/MySQL-5.5/mysql-5.5.49.tar.gz
[*]编译安装MySQL
$tar-xvfmysql-5.5.49.tar.gz&&cdmysql-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&&makeinstall$ln-s/usr/local/product/mysql5.5.49/usr/local/mysql$chown-Rmysql.mysql/usr/local/mysql
[*]拷贝mysql的配置文件
$cd/usr/local/mysql/support-files/$cpmy-medium.cnf/data/mysql/my.cnf$cpmysql.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/mysqldstart
[*]登录数据库,创建zabbix数据库及用户名和密码
mysql>createdatabasezabbixdefaultcharsetutf8;QueryOK,1rowaffected(0.00sec)mysql>grantallprivilegesonzabbix.*tozabbix@'localhost'identifiedby'zabbix';QueryOK,0rowsaffected(0.03sec)mysql>flushprivileges;QueryOK,0rowsaffected(0.00sec)
[*]如果登录数据库出现问题
$mysqlERROR2002(HY000):Can'tconnecttolocalMySQLserverthroughsocket'/var/lib/mysql/mysql.sock'(2)解决办法:$ln-s/tmp/mysql.sock/var/lib/mysql/
[*]为数据库的root创建密码
$mysqladmin-urootpassword"zabbix"安装zabbixserver
[*]下载安装包
$wgetprojects/zabbix/files/ZABBIX%20Latest%20Stable/3.0.3/zabbix-3.0.3.tar.gz
[*]安装zabbix
$tarzxfzabbix-3.0.3.tar.gz&&cdzabbix-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&&makeinstall
[*]编译过程中如果有报错
故障1:checkingformysql_config...noconfigure:error:MySQLlibrarynotfound解决:$yuminstallmysql-devel-y故障2:checkingfornet-snmp-config...noconfigure:error:InvalidNet-SNMPdirectory-unabletofindnet-snmp-config解决:$yuminstallnet-snmp-devel-y
[*]创建zabbix用户
$groupaddzabbix$useraddzabbix-s/sbin/nologin-M-gzabbix
[*]zabbixserver需要导入3个sql文件
$mysql-uroot-pzabbixzabbix<database/mysql/schema.sql$mysql-uroot-pzabbixzabbix<database/mysql/images.sql$mysql-uroot-pzabbixzabbix<database/mysql/data.sqlzabbix管理网站配置(nginx)
[*]创建项目目录
$mkdir/data/web/-p$mkdir/data/logs/zabbix-p
[*]将前端文件拷贝到项目目录下
$cp-rpfrontends/php/*/data/web//
[*]编辑nginx虚拟主机
$pwd/usr/local/nginx/conf$cdextra/$vimzabbix.confserver{listen16888;server_name;access_log/data/logs/zabbix/zabbix.lifec.com.access.logmain;indexindex.htmlindex.phpindex.html;root/data/web/zabbix.lifec.com;location/{try_files$uri$uri//index.php?$args;}location~^(.+.php)(.*)${fastcgi_split_path_info^(.+.php)(.*)$;includefastcgi.conf;fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramPATH_INFO$fastcgi_path_info;}}
[*]编辑nginx.conf配置文件
$vimnginx.confusernginx;worker_processes1;#error_loglogs/error.logwarning;#error_loglogs/error.lognotice;#error_loglogs/error.loginfo;pidlogs/nginx.pid;events{worker_connections1024;}http{includemime.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;sendfileon;#tcp_nopushon;#keepalive_timeout0;keepalive_timeout65;#gzipon;includeextra/*.conf;}
[*]编辑zabbix_server.conf文件
$vimetc/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
[*]启动zabbixserver
$/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:errorwhileloa**sharedlibraries:libmysqlclient.so.18:cannotopensharedobjectfile:Nosuchfileordirectory$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/mysqldstart">>/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$chown1000:1000zabbix.conf.php
[*]使用用户名(Admin)和密码(zabbix)登录
[*]修改界面为中文界面
$vim/data/web//include/locales.inc.php'zh_CN'=>['name'=>_('Chinese(zh_CN)'),'display'=>true],$unzipyaheiFont_CHS.zip//文件在git的fonts目录里$rzmsyh.ttf$cd/data/web//fonts$mvDejaVuSans.ttfDejaVuSans_bak$mvmsyh.ttfDejaVuSans.ttf$chown1000:1000DejaVuSans.ttf//重启服务即可zabbix-agent安装
[*]下载
$rpm-Uvhzabbix/3.....3-1.el6.x86_64.rpm
[*]问题报错
error:Faileddependencies:libodbc.so.2()(64bit)isneededbyzabbix-agent-3.0.3-1.el6.x86_64解决办法:$yum-yinstallunixODBC
[*]修改配置配置文件
$vim/etc/zabbix/zabbix_agentd.confPidFile=/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群组,因为自动发现是批量添加DiscoveryHost的,你可以让所有主机链接同一个模板,并且让他们提供相同的服务。没错,如果你学过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]