环境说明
主机名 | 角色 | IP地址 |
zabbix.contoso.com | zabbix server | 192.168.49.129 |
zabbix-db.contoso.com | MysqL server | 192.168.49.133 |
一、环境准备
以其中一台为例,两台都需要完成以下准备工作:
#关闭iptables [root@zabbix~]#iptables-L-n ChainINPUT(policyACCEPT) targetprotoptsourcedestination ChainFORWARD(policyACCEPT) targetprotoptsourcedestination ChainOUTPUT(policyACCEPT) targetprotoptsourcedestination #禁用selinux [root@zabbix~]#getenforce Disabled #添加时间同步定时任务 [root@zabbix~]#crontab-l 0****/usr/sbin/ntpdate210.72.145.4464.147.116.229time.nist.gov #修改主机名 [root@zabbix~]#hostname zabbix.contoso.com #安装必要的依赖包 yum-yinstallgccgcc-c++autoconflibjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-devellibxml2libxml2-develzlibzlib-develglibcglibc-develglib2glib-develbzip2bzip2-develncursesncurses-develcurlcurl-devele2fsprogse2fsprogs-develkrbkrb5-devellibidnlibidn-developensslopenssl-devel
二、编译安装zabbix
以下操作在zabbix server(zabbix.contoso.com)上完成:
mkdir-p/opt/tools cd/opt/tools/ wgethttp://prdownloads.sourceforge.net/zabbix/zabbix-2.4.8.tar.gz?download tar-zxfzabbix-2.4.8.tar.gz cdzabbix-2.4.8 ./configure--prefix=/usr/local/zabbix--enable-server--enable-agent--with-net-snmp--with-MysqL--with-libcurl
如果编译中出现下面的错误:
1)configure: error: MysqL library not found
解决方法:yum install MysqL-devel -y
2)configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config
解决方法:yum install net-snmp-devel -y
另外,编译成功的标志是,结尾出现下面的字样:
*********************************************************** *Nowrun'makeinstall'* ** *ThankyouforusingZabbix!* *<http://www.zabbix.com>* ***********************************************************
最后,使用make install进行安装:
make&&makeinstall
以下操作在MysqL server(zabbix-db.contoso.com)上进行:
1、安装MysqL 5.6.16
yum-yinstallmakegcc-c++cmakebison-develncurses-devel mkdir-p/opt/tools cd/opt/tools/ wgetwgethttp://dev.MysqL.com/get/Downloads/MysqL-5.6/MysqL-5.6.16.tar.gz tar-zxfMysqL-5.6.16.tar.gz cdMysqL-5.6.16 cmake\ >-DCMAKE_INSTALL_PREFIX=/usr/local/MysqL\ >-DMysqL_DATADIR=/usr/local/MysqL/data\ >-DSYSCONFDIR=/etc\ >-DWITH_MYISAM_STORAGE_ENGINE=1\ >-DWITH_INNOBASE_STORAGE_ENGINE=1\ >-DWITH_MEMORY_STORAGE_ENGINE=1\ >-DWITH_READLINE=1\ >-DMysqL_UNIX_ADDR=/var/lib/MysqL/MysqL.sock\ >-DMysqL_TCP_PORT=3306\ >-DENABLED_LOCAL_INFILE=1\ >-DWITH_PARTITION_STORAGE_ENGINE=1\ >-DEXTRA_CHARSETS=all\ >-DDEFAULT_CHARSET=utf8\ >-DDEFAULT_COLLATION=utf8_general_ci make&&makeinstall
#创建用户并授权 groupaddMysqL useradd-gMysqLMysqL chown-RMysqL:MysqL/usr/local/MysqL #运行初始化脚本进行初始化 [root@zabbix-dbMysqL-5.6.16]#/usr/local/MysqL/scripts/MysqL_install_db--basedir=/usr/local/MysqL--datadir=/usr/local/MysqL/data--user=MysqL #数据库配置和启动脚本修改 [root@zabbix-dbMysqL-5.6.16]#mv/etc/my.cnf/etc/my.cnf.bak#如果不把/etc/my.cnf改名,后面启动编译安装的MysqL会出错 [root@zabbix-dbMysqL-5.6.16]#cp/usr/local/MysqL/support-files/MysqL.server/etc/init.d/MysqLd [root@zabbix-dbMysqL-5.6.16]#chmod+x/etc/init.d/MysqLd
3、启动MysqL服务
[root@zabbix-dbMysqL-5.6.16]#/etc/init.d/MysqLdstart StartingMysqL....SUCCESS! [root@zabbix-dbMysqL-5.6.16]#ps-ef|grepMysqL root169251005:24pts/000:00:00/bin/sh/usr/local/MysqL/bin/MysqLd_safe--datadir=/usr/local/MysqL/data--pid-file=/usr/local/MysqL/data/zabbix-db.contoso.com.pid MysqL1703316925405:24pts/000:00:01/usr/local/MysqL/bin/MysqLd--basedir=/usr/local/MysqL--datadir=/usr/local/MysqL/data--plugin-dir=/usr/local/MysqL/lib/plugin--user=MysqL--log-error=/usr/local/MysqL/data/zabbix-db.contoso.com.err--pid-file=/usr/local/MysqL/data/zabbix-db.contoso.com.pid root170641050005:25pts/000:00:00grepMysqL [root@zabbix-dbMysqL-5.6.16]#netstat-lnt|grep3306 tcp00:::3306:::*LISTEN [root@zabbix-dbMysqL-5.6.16]#lsof-i:3306 COMMANDPIDUSERFDTYPEDEVICESIZE/OFFNODENAME MysqLd17033MysqL10uIPv6600270t0TCP*:MysqL(LISTEN)
echo'exportPATH=/usr/local/MysqL/bin:$PATH'>>/etc/profile source/etc/profile
MysqLadmin-urootpassword"123456"#给MysqL中的root用户设置密码
2)将zabbix安装文件中的MysqL数据拷贝到MysqL server(zabbix-db.contoso.com)中
注:该步骤要在zabbix.contoso.com上完成
[root@zabbixzabbix-2.4.8]#cd/opt/tools/zabbix-2.4.8/database/MysqL/ [root@zabbixMysqL]#ll total2988 -rw-r--r--110001000972946Apr2005:57data.sql -rw-r--r--1100010001978341Apr2005:51images.sql -rw-r--r--110001000104816Apr2005:57schema.sql [root@zabbixMysqL]#scpdata.sqlimages.sqlschema.sqlroot@192.168.49.133:/tmp/ Theauthenticityofhost'192.168.49.133(192.168.49.133)'can'tbeestablished. RSAkeyfingerprintisf9:ce:14:5d:cd:bb:3c:b4:0d:0b:fc:21:3a:92:43:6b. Areyousureyouwanttocontinueconnecting(yes/no)?yes Warning:Permanentlyadded'192.168.49.133'(RSA)tothelistofknownhosts. root@192.168.49.133'spassword: data.sql100%950KB950.1KB/s00:00 images.sql100%1932KB1.9MB/s00:00 schema.sql100%102KB102.4KB/s00:00
[root@zabbix-dbMysqL-5.6.16]#MysqL-uroot-p123456 Warning:Usingapasswordonthecommandlineinterfacecanbeinsecure. WelcometotheMysqLmonitor.Commandsendwith;or\g. YourMysqLconnectionidis2 Serverversion:5.6.16Sourcedistribution Copyright(c)2000,2014,Oracleand/oritsaffiliates.Allrightsreserved. OracleisaregisteredtrademarkofOracleCorporationand/orits affiliates.Othernamesmaybetrademarksoftheirrespective owners. Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement. MysqL>showdatabases; +--------------------+ |Database| +--------------------+ |information_schema| |MysqL| |performance_schema| |test| +--------------------+ 4rowsinset(0.04sec) MysqL>createdatabasezabbix; QueryOK,1rowaffected(0.03sec) MysqL>usezabbix; Databasechanged MysqL>source/tmp/schema.sql; QueryOK,0rowsaffected(0.48sec) ... MysqL>source/tmp/images.sql; QueryOK,1rowaffected(0.03sec) ... MysqL>source/tmp/data.sql; QueryOK,0rowsaffected(0.00sec) ... MysqL>showtables; +-----------------------+ |Tables_in_zabbix| +-----------------------+ |acknowledges| |actions| |alerts| |application_template| |applications| |auditlog| |auditlog_details| |autoreg_host| |conditions| |config| |dbversion| |dchecks| |dhosts| |drules| |dservices| |escalations| |events| |expressions| |functions| |globalmacro| |globalvars| |graph_discovery| |graph_theme| |graphs| |graphs_items| |group_discovery| |group_prototype| |groups| |history| |history_log| |history_str| |history_text| |history_uint| |host_discovery| |host_inventory| |hostmacro| |hosts| |hosts_groups| |hosts_templates| |housekeeper| |httpstep| |httpstepitem| |httptest| |httptestitem| |icon_map| |icon_mapping| |ids| |images| |interface| |interface_discovery| |item_condition| |item_discovery| |items| |items_applications| |maintenances| |maintenances_groups| |maintenances_hosts| |maintenances_windows| |mappings| |media| |media_type| |opcommand| |opcommand_grp| |opcommand_hst| |opconditions| |operations| |opgroup| |opmessage| |opmessage_grp| |opmessage_usr| |optemplate| |profiles| |proxy_autoreg_host| |proxy_dhistory| |proxy_history| |regexps| |rights| |screens| |screens_items| |scripts| |service_alarms| |services| |services_links| |services_times| |sessions| |slides| |slideshows| |sysmap_element_url| |sysmap_url| |sysmaps| |sysmaps_elements| |sysmaps_link_triggers| |sysmaps_links| |timeperiods| |trends| |trends_uint| |trigger_depends| |trigger_discovery| |triggers| |user_history| |users| |users_groups| |usrgrp| |valuemaps| +-----------------------+ 104rowsinset(0.08sec) MysqL>GRANTALLONzabbix.*TO'zbxuser'@'192.168.49.%'IDENTIFIEDBY'zbx@123456'; QueryOK,0rowsaffected(0.09sec) MysqL>FLUSHPRIVILEGES; QueryOK,0rowsaffected(0.02sec) MysqL>quit Bye
四、安装PHP和apache
[root@zabbixMysqL]#yum-yinstallPHPPHP-develcurlcurl-develnet-snmpnet-snmp-develperl-DBIPHP-MysqLPHP-mbstringPHP-gdPHP-xmlPHP-bcmathhttpd
五、配置zabbix server
1、创建zabbix用户
[root@zabbixMysqL]#useraddzabbix [root@zabbixMysqL]#idzabbix uid=500(zabbix)gid=500(zabbix)groups=500(zabbix)
2、编辑zabbix server配置文件
[root@zabbixMysqL]#cp/usr/local/zabbix/etc/zabbix_server.conf/usr/local/zabbix/etc/zabbix_server.conf.bak [root@zabbixMysqL]#vi/usr/local/zabbix/etc/zabbix_server.conf [root@zabbixMysqL]#diff/usr/local/zabbix/etc/zabbix_server.conf.bak/usr/local/zabbix/etc/zabbix_server.conf 68c68 <#DBHost=localhost --- >DBHost=192.168.49.133#修改数据库主机(可以是IP或主机名),前提是数据库和zabbix不在同一台server上 92c92 <#DBUser= --- >DBUser=zbxuser#修改默认的数据库授权用户 94c94 <DBUser=root --- >#DBUser=root 102c102 <#DBPassword= --- >DBPassword=zbx@123456#填写数据库用户的密码 109a110 >DBSocket=/var/lib/MysqL/MysqL.sock#指定MysqL的socket文件位置 117c118 <#DBPort=3306 --- >DBPort=3306#修改MysqL端口号
3、拷贝zabbix前端web目录到apache目录
[root@zabbixMysqL]#cp-r/opt/tools/zabbix-2.4.8/frontends/PHP/var/www/html/ [root@zabbixMysqL]#mv/var/www/html/PHP/var/www/html/zabbix [root@zabbixMysqL]#chown-Rapache:apache/var/www/html/
#从zabbix安装文件的目录中拷贝脚本到/etc/init.d/下 [root@zabbixMysqL]#cp-r/opt/tools/zabbix-2.4.8/misc/init.d/fedora/core/*/etc/init.d/ #因为脚本中的zabbix根目录是/usr/local,所以需要修改为/usr/local/zabbix [root@zabbixMysqL]#sed-i's#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g'/etc/init.d/zabbix_server [root@zabbixMysqL]#sed-i's#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g'/etc/init.d/zabbix_agentd
5、启动zabbix server并检查状态
[root@zabbixMysqL]#/etc/init.d/zabbix_serverstart Startingzabbix_server:[OK] [root@zabbixMysqL]#ps-ef|grepzabbix zabbix172741007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server zabbix1727517274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:configurationsyncer[waiting60secforprocesses] zabbix1727617274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:dbwatchdog[syncedalertsconfigin0.040259sec,idle60sec] zabbix1727717274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:poller#1[got0valuesin0.000003sec,idle5sec] zabbix1727817274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:poller#2[got0valuesin0.000006sec,idle5sec] zabbix1727917274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:poller#3[got0valuesin0.000005sec,idle5sec] zabbix1728017274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:poller#4[got0valuesin0.000003sec,idle5sec] zabbix1728117274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:poller#5[got0valuesin0.000002sec,idle5sec] zabbix1728217274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:unreachablepoller#1[got0valuesin0.000003sec,idle5sec] zabbix1728317274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:trapper#1[processeddatain0.000000sec,waitingforconnection] zabbix1728417274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:trapper#2[processeddatain0.000000sec,waitingforconnection] zabbix1728517274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:trapper#3[processeddatain0.000000sec,waitingforconnection] zabbix1728617274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:trapper#4[processeddatain0.000000sec,waitingforconnection] zabbix1728717274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:trapper#5[processeddatain0.000000sec,waitingforconnection] zabbix1728817274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:icmppinger#1[got0valuesin0.000008sec,idle5sec] zabbix1728917274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:alerter[sentalerts:0success,0failin0.001585sec,idle30sec] zabbix1729017274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:housekeeper[startupidlefor30minutes] zabbix1729117274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:timer#1[processed0triggers,0eventsin0.000000sec,0maintenancesin0.000000sec,idle30sec] zabbix1729217274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:httppoller#1[got0valuesin0.001478sec,idle5sec] zabbix1729317274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:discoverer#1[processed0rulesin0.000770sec,idle60sec] zabbix1729417274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:historysyncer#1[synced0itemsin0.000003sec,idle5sec] zabbix1729517274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:historysyncer#2[synced0itemsin0.000002sec,idle5sec] zabbix1729617274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:historysyncer#3[synced0itemsin0.000001sec,idle5sec] zabbix1729717274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:historysyncer#4[synced0itemsin0.000003sec,idle5sec] zabbix1729817274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:escalator[processed0escalationsin0.001206sec,idle3sec] zabbix1729917274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:proxypoller#1[exchangeddatawith0proxiesin0.000006sec,idle5sec] zabbix1730017274007:52?00:00:00/usr/local/zabbix/sbin/zabbix_server:self-monitoring[processeddatain0.000007sec,idle1sec] root173021069007:52pts/000:00:00grepzabbix [root@zabbixMysqL]#netstat-lnt|grep10051 tcp000.0.0.0:100510.0.0.0:*LISTEN [root@zabbixMysqL]#lsof-i:10051 COMMANDPIDUSERFDTYPEDEVICESIZE/OFFNODENAME zabbix_se17274zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17275zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17276zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17277zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17278zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17279zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17280zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17281zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17282zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17283zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17284zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17285zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17286zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17287zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17288zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17289zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17290zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17291zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17292zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17293zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17294zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17295zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17296zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17297zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17298zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17299zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN) zabbix_se17300zabbix4uIPv4337700t0TCP*:zabbix-trapper(LISTEN)
6、启动httpd服务
[root@zabbixMysqL]#/etc/init.d/httpdstart Startinghttpd:httpd:apr_sockaddr_info_get()Failedforzabbix.contoso.com httpd:Couldnotreliablydeterminetheserver'sfullyqualifieddomainname,using127.0.0.1forServerName [OK]
7、设置开机启动
#zabbix-db上设置开机启动MysqL [root@zabbix-dbMysqL-5.6.16]#chkconfig--addMysqLd [root@zabbix-dbMysqL-5.6.16]#chkconfigMysqLdon [root@zabbix-dbMysqL-5.6.16]#chkconfig--list|grepMysqLd MysqLd0:off1:off2:on3:on4:on5:on6:off #zabbixserver上设置开机启动zabbix_server和httpd服务 [root@zabbixMysqL]#chkconfig--addzabbix_server [root@zabbixMysqL]#chkconfigzabbix_serveron [root@zabbixMysqL]#chkconfig--list|grepzabbix zabbix_server0:off1:off2:on3:on4:on5:on6:off [root@zabbixMysqL]#chkconfighttpdon [root@zabbixMysqL]#chkconfig--list|grephttpd httpd0:off1:off2:on3:on4:on5:on6:off
六、在浏览器中进行图形界面配置zabbix
打开浏览器,输入http://zabbix_server_ip/zabbix,如果上面的步骤无误就会出现上面的画面。
这里是必要安装条件检查,上面有一些PHP的参数默认是不正确的,需要进行调整,至于调整的值都有显示。修改的方法如下:
[root@zabbixMysqL]#cp/etc/PHP.ini/etc/PHP.ini.bak$(date+%F) [root@zabbixMysqL]#vi/etc/PHP.ini [root@zabbixMysqL]#diff/etc/PHP.ini.bak2016-10-06/etc/PHP.ini 440c440 <max_execution_time=30 --- >max_execution_time=300 449c449 <max_input_time=60 --- >max_input_time=300 729c729 <post_max_size=8M --- >post_max_size=16M 946a947 >date.timezone=Asia/Shanghai
注意,PHP.ini修改完成后,上面的错误刷新之后仍然存在,需要重启httpd和zabbix server服务。
[root@zabbix-dbMysqL-5.6.16]#/etc/init.d/MysqLdrestart ShuttingdownMysqL....SUCCESS! StartingMysqL.....SUCCESS! [root@zabbix-dbMysqL-5.6.16]# [root@zabbixMysqL]#/etc/init.d/httpdrestart Stoppinghttpd:[OK] Startinghttpd:httpd:apr_sockaddr_info_get()Failedforzabbix.contoso.com httpd:Couldnotreliablydeterminetheserver'sfullyqualifieddomainname,using127.0.0.forServerName [OK]
再次进行必要条件检查,可以看到目前所有的条件都已经满足,全部都是OK就可以进行下一步了。
配置数据库连接,根据需要输入数据库的相关信息,然后点击下面的按钮进行连接测试,如果测试通过,再进行下一步。
这一步是zabbix server的详细信息,可以根据实际情况进行修改,但是注意端口一定要正确。
配置结束,给出安装前的配置总结,确认就开始安装了。
安装的过程会比较快,这是安装完成的画面。
原文链接:https://www.f2er.com/centos/380492.html