详解Zabbix安装部署实践
前言
Zabbix是目前最为主流的开源监控方案之一,部署本身并不困难,难的是深入理解。根据在生产环境的实践从新版Zabbix4.0LTS开始全部使用Docker部署,我相信未来越来越多的开源组件都会以容器化的形式呈现在我们面前。
操作系统:
[root@mysql~]#cat/etc/redhat-release CentOSLinuxrelease7.5.1804(Core)
Mysql:版本5.7.23192.168.75.251
ZabbixServer:版本3.4.12192.168.75.250
一、安装Mysql
1.1下载mysql
关闭防火墙
#systemctlstopfirewalld #systemctldisablefirewalld vi/etc/selinux/config SELINUX=enforcing改为SELINUX=disabled
Centos7默认数据库为mariadb,先卸载
rpm–qa|grepmariadb mariadb-libs-5.5.56-2.el7.x86_64 rpm-e--nodepsmariadb-libs-5.5.56-2.el7.x86_64
这个版本需要boost1.9,也要下载
[root@mysqlsoft]#ll total132444 -rw-r--r--1rootroot83709983Aug1010:26boost_1_59_0.tar.gz -rw-r--r--1rootroot51907462Aug1010:26mysql-5.7.23.tar.gz
添加mysql用户,
groupaddmysql useradd-gmysql-s/sbin/nologinmysql
1.2安装依赖包
yuminstall-ycmakebisonbison-devellibaio-develgccgcc-c++gitncurses-devel
1.3编译
解压mysql,把boost的压缩版放到解压后的mysql目录内
tarxzvfmysql-5.7.23.tar.gz mvboost_1_59_0.tar.gzmysql-5.7.23
进入MySQL源文件目录,新建configure做为编译目录,并进入该目
cdmysql-5.7.23 mkdirconfigure cdconfigure
使用cmake进行生成编译环境,
cmake..-DBUILD_CONFIG=mysql_release\ -DINSTALL_LAYOUT=STANDALONE\ -DCMAKE_BUILD_TYPE=RelWithDebInfo\ -DENABLE_DTRACE=OFF\ -DWITH_EMBEDDED_SERVER=OFF\ -DWITH_INNODB_MEMCACHED=ON\ -DWITH_SSL=bundled\ -DWITH_ZLIB=system\ -DWITH_PAM=ON\ -DCMAKE_INSTALL_PREFIX=/var/mysql/\ -DINSTALL_PLUGINDIR="/var/mysql/lib/plugin"\ -DDEFAULT_CHARSET=utf8\ -DDEFAULT_COLLATION=utf8_general_ci\ -DWITH_EDITLINE=bundled\ -DFEATURE_SET=community\ -DCOMPILATION_COMMENT="MySQLServer(GPL)"\ -DWITH_DEBUG=OFF\ -DWITH_BOOST=..
安装
make&&makeinstall
修改配置文件
vim/etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/mysql/mysql.sock port=3306 log_error=/var/mysql/log/error.log basedir=/var/mysql/ [client] socket=/var/mysql/mysql.sock chownmysql.mysql/etc/my.cnf
创建日志文件
mkdir-p/var/mysql/log touch/var/mysql/log/error.log touch/var/mysql/mysql.sock chown-Rmysql.mysql/var/mysql/
1.4初始化
#/var/mysql/bin/mysqld--initialize--user=mysql
查看数据文件是否生成
#ll/var/lib/mysql total110628 -rw-r-----1mysqlmysql56Aug1011:06auto.cnf -rw-r-----1mysqlmysql417Aug1011:06ib_buffer_pool -rw-r-----1mysqlmysql12582912Aug1011:06ibdata1 -rw-r-----1mysqlmysql50331648Aug1011:06ib_logfile0 -rw-r-----1mysqlmysql50331648Aug1011:06ib_logfile1 drwxr-x---2mysqlmysql4096Aug1011:06mysql drwxr-x---2mysqlmysql8192Aug1011:06performance_schema drwxr-x---2mysqlmysql8192Aug1011:06sys
查看日志文件是否生成
#ll/var/mysql/log
临时密码生成放在error.log中
#cat/var/mysql/log/error.log 2019-11-18T09:06:22.922254Z0[Warning]TIMESTAMPwithimplicitDEFAULTvalueisdeprecated.Pleaseuse--explicit_defaults_for_timestampserveroption(seedocumentationformoredetails). 2019-11-18T09:06:24.600401Z0[Warning]InnoDB:Newlogfilescreated,LSN=45790 2019-11-18T09:06:24.853258Z0[Warning]InnoDB:Creatingforeignkeyconstraintsystemtables. 2019-11-18T09:06:24.915246Z0[Warning]NoexistingUUIDhasbeenfound,soweassumethatthisisthefirsttimethatthisserverhasbeenstarted.GeneratinganewUUID:5dbf9eac-9c4a-11e8-8768-000c29a48522. 2019-11-18T09:06:24.916709Z0[Warning]Gtidtableisnotreadytobeused.Table'mysql.gtid_executed'cannotbeopened. 2019-11-18T09:06:24.917772Z1[Note]Atemporarypasswordisgeneratedforroot@localhost:NS0+>RzwvHWl
1.5启动
修改初始密码、修改环境变量
从模板文件中复制启动文件:
cp/var/mysql/support-files/mysql.server/etc/init.d/mysqld
修改启动文件:
vim/etc/init.d/mysqld
找到如下二行:
basedir=
datadir=
修改为:
basedir=/var/mysql/ datadir=/var/lib/mysql
更改权限
#chown-Rmysql.mysql/var/mysql/var/lib/mysql
启动
/etc/init.d/mysqldstart ln-s/var/mysql/bin/mysql/usr/bin
配置MySQL环境变量:
vim/root/.bash_profile
找到下面一行:
PATH=$PATH:$HOME/bin
修改为:
PATH=$PATH:$HOME/bin:/var/mysql/bin
利用上面生成的临时密码,登录
#mysql–uroot–pNS0+>RzwvHWl
WelcometotheMySQLmonitor.Commandsendwith;or\g.
YourMySQLconnectionidis6
Serverversion:5.7.23
Copyright(c)2000,2018,Oracleand/oritsaffiliates.Allrightsreserved.
OracleisaregisteredtrademarkofOracleCorporationand/orits
affiliates.Othernamesmaybetrademarksoftheirrespective
owners.
Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.
mysql>
更改初始密码
mysql>alteruser'root'@'localhost'identifiedby'123456';
二、安装ZabbixServer
2.1安装php
安装php7.1版本,zabbix3.0版本要求php5.4及以上。
先查看本地php版本
php-v
检查当前php的安装包
yumlistinstalled|grepphp
将本地php安装包卸载干净
yumremovephp*
默认的yum源无法升级PHP,需要添加第三方yum源,我们选择webtatic库
rpm-Uvhhttps://mirror.webtatic.com/yum/el7/epel-release.rpm rpm-Uvhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装php7.1
yuminstall-yphp71w
安装相关插件
yuminstall-yphp71w-fpmphp71w-opcachephp71w-cliphp71w-gdphp71w-imapphp71w-mysqlndphp71w-mbstringphp71w-mcryptphp71w-pdophp71w-pecl-apcuphp71w-pecl-mongodbphp71w-pecl-redisphp71w-pgsqlphp71w-xmlphp71w-xmlrpcphp71w-develmod_php71wphp71w-ldapphp71w-bcmath
修改PHP的配置参数
vim/etc/php.ini date.timezone=Asia/Shanghai max_execution_time=300 post_max_size=32M memory_limit=128M mbstring.func_overload=1 max_input_time=300
Session调整权限,
chmod-R777/var/lib/php/session/
2.2安装zabbix
安装依赖包
yum-yinstallgcc*makecurlcurl-develnet-snmpnet-snmp-develperl-DBIhttpdmariadb*mysql-devellibxml2-develcurl-develunixODBC-develnet-snmp-develOpenIPMI-developenldapopenldap-devellibevent-develjava-devellibssh2-devel
创建zabbix用户和组
groupaddzabbix useradd-gzabbixzabbix
编译、安装
tarzxvfzabbix-3.4.12.tar.gz cdzabbix-3.4.12/ ./configure--prefix=/usr/local/zabbix--enable-server--enable-proxy--enable-agent--enable-ipv6--with-mysql--with-net-snmp--with-libcurl--with-openipmi--with-unixodbc--with-ldap--with-ssh2--enable-java make&&makeinstall chown-Rzabbix.zabbix/usr/local/zabbix
修改zabbix配置文件
vi/usr/local/zabbix/etc/zabbix_server.conf LogFile=/tmp/zabbix_server.log DebugLevel=3 DBHost=192.168.75.251#server和数据库分离的写法 DBName=zabbix DBUser=zabbix DBPassword=zabbix DBSocket=/var/mysql/mysql.sock DBPort=3306 StartPollers=10 Timeout=4 AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts LogSlowQueries=3000 CacheSize=1024M
后期配置文件的参数,根据需求做调整。
把zabbix程序包中的几个sql文件传到上面的mysql服务器,导入数据库文件
[root@zabbix~]#cd/opt/soft/zabbix-3.4.12/database/mysql [root@zabbixmysql]#ll total4876 -rw-r--r--.1100110012877497Jul3019:41data.sql -rw-r--r--.1100110011978341Jul3019:41images.sql -rw-r--r--.110011001134791Jul3019:41schema.sql [root@zabbixmysql]#scp*root@192.168.75.251:/opt/
下面在mysql(192.168.75.251)服务器上操作
#mysql-uroot–p
Enterpassword:
创建zabbix数据库,字符集设置为utf8
mysql>createdatabasezabbixcharactersetutf8collateutf8_bin;
在mysql数据库中创建zabbix用户,赋予zabbix用户对zabbix数据库的全部权限,允许zabbix服务器远程访问mysql
mysql>GRANTALLPRIVILEGESONzabbix.*TOzabbix@192.168.75.250IDENTIFIEDBY'zabbix'; mysql>GRANTALLPRIVILEGESONzabbix.*TOzabbix@localhostIDENTIFIEDBY'zabbix'; mysql>flushprivileges; mysql>showdatabases; +--------------------+ |Database| +--------------------+ |information_schema| |mysql| |performance_schema| |sys| |zabbix| +--------------------+ 5rowsinset(0.00sec)
导入数据文件,在控制台操作
#mysql-uzabbix-pzabbix2.3zabbixweb部署
回到ZabbixServer主机操作。在上面已经安装好httpd,创建apache下创建zabbix目录
mkdir/var/www/html/zabbix
拷贝zabbix包中的web界面到apachezabbix目录下
\cp–rf/opt/soft/zabbix-3.4.12/frontends/php/*/var/www/html/zabbix/配置web安全
chown-Rapache.apache/var/www/html/zabbix chmoda+x/var/www/html/zabbix/conf/拷贝zabbix包中服务启动脚本(server/agentd)到linux系统服务启动目录
cp/opt/soft/zabbix-3.4.12/misc/init.d/fedora/core/zabbix_serverzabbix_agentd/etc/init.d/修改/etc/init.d/zabbix_server和/etc/init.d/zabbix_agentd
BASEDIR=/usr/local修改成 BASEDIR=/usr/local/zabbix/设置开机启动
systemctlenablehttpd systemctlenablezabbix_server systemctlenablezabbix_agentd /etc/init.d/zabbix_serverstart /etc/init.d/zabbix_agentdstart systemctlstarthttpd2.4web服务初始化
http://192.168.75.250/zabbix/setup.php
连接数据库设置,写mysql服务器所在机器,端口,数据库名称,用户、密码
三、安装ZabbixProxy
首先,在proxy机器上安装mysql,跟上面的安装步骤一样,只是在导入mysql文件时,只导入一个文件,
#mysql–uzabbix–pzabbix
安装依赖包
yum-yinstallgcc*makecurlcurl-develnet-snmpnet-snmp-develperl-DBIhttpdmariadb*mysql-devellibxml2-develcurl-develunixODBC-develnet-snmp-develOpenIPMI-developenldapopenldap-devellibevent-develjava-devellibssh2-devel创建zabbix用户和组
groupaddzabbix useradd-gzabbixzabbix编译、安装
tarzxvfzabbix-3.4.12.tar.gz cdzabbix-3.4.12/ ./configure--prefix=/opt/server/zabbix_proxy--enable-proxy--enable-agent--enable-ipv6--with-mysql--with-net-snmp--with-libcurl--with-openipmi--with-unixodbc--with-ldap--with-ssh2--enable-java make&&makeinstall chown-Rzabbix.zabbix/opt/server/zabbix_proxy配置文件修改
Vi/usr/local/zabbix/etc/zabbix_proxy.conf Server=192.168.75.250 ServerPort=10051 Hostname=zabbix_proxy LogFile=/tmp/zabbix_proxy.log DBHost=localhost#因为mysql和proxy安装在同一台机器 DBName=zabbix DBUser=zabbix DBPassword=zabbix DBSocket=/var/mysql/mysql.sock ConfigFrequency=60 DataSenderFrequency=60 StartPollers=5 Timeout=4 LogSlowQueries=3000启动proxy(要加入到开机自启)
#/opt/server/zabbix_proxy/sbin/zabbix_proxy-c/opt/server/zabbix_proxy/etc/zabbix_proxy.conf systemctlenablezabbix_proxy四、启动zabbix_agentd客户端
同上,编译安装zabbix时,客户端也一起编译了,把/usr/local下面的zabbix目录拷贝到客户端,
修改配置文件
vi/usr/local/zabbix/etc/zabbix_agentd.conf Server=zabbix_proxy_IP#建议所以客户端都挂在proxy上,扩展性强 Hostname=zabbix_agentd_hostname#填写客户端的主机名启动(要加入到开机自启)
/usr/local/zabbix/sbin/zabbix_agentd-c/usr/local/zabbix/etc/zabbix_agentd.conf echo"/usr/local/agent/sbin/zabbix_agentd-c/usr/local/agent/etc/zabbix_agentd.conf">>/etc/rc.local五、Web管理
添加监控主机
选择主机监控模版
主机监控成功
总结
以上所述是小编给大家介绍的Zabbix安装部署实践,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。