前言
Zabbix是目前最为主流的开源监控方案之一,部署本身并不困难,难的是深入理解。根据在生产环境的实践从新版Zabbix 4.0 LTS开始全部使用Docker部署,我相信未来越来越多的开源组件都会以容器化的形式呈现在我们面前。
操作系统:
[root@mysql ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core)
Mysql : 版本5.7.23 192.168.75.251
Zabbix Server:版本3.4.12 192.168.75.250
一、安装Mysql
1.1下载mysql
关闭防火墙
#systemctl stop firewalld # systemctl disable firewalld vi /etc/selinux/config SELINUX=enforcing 改为 SELINUX= disabled
Centos7 默认数据库为mariadb ,先卸载
rpm –qa |grep mariadb mariadb-libs-5.5.56-2.el7.x86_64 rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
这个版本需要boost 1.9,也要下载
[root@mysql soft]# ll total 132444 -rw-r--r-- 1 root root 83709983 Aug 10 10:26 boost_1_59_0.tar.gz -rw-r--r-- 1 root root 51907462 Aug 10 10:26 mysql-5.7.23.tar.gz
添加mysql用户,
groupadd mysql useradd -g mysql -s /sbin/nologin mysql
1.2安装依赖包
yum install -y cmake bison bison-devel libaio-devel gcc gcc-c++ git ncurses-devel
1.3编译
解压mysql ,把boost的压缩版放到解压后的mysql目录内
tar xzvf mysql-5.7.23.tar.gz mv boost_1_59_0.tar.gz mysql-5.7.23
进入MySQL源文件目录,新建configure做为编译目录,并进入该目
cd mysql-5.7.23 mkdir configure cd configure
使用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="MySQL Server (GPL)" \ -DWITH_DEBUG=OFF \ -DWITH_BOOST=..
安装
make && make install
修改配置文件
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 chown mysql.mysql /etc/my.cnf
创建日志文件
mkdir -p /var/mysql/log touch /var/mysql/log/error.log touch /var/mysql/mysql.sock chown -R mysql.mysql /var/mysql/
1.4初始化
#/var/mysql/bin/mysqld --initialize --user=mysql
查看数据文件是否生成
#ll /var/lib/mysql total 110628 -rw-r----- 1 mysql mysql 56 Aug 10 11:06 auto.cnf -rw-r----- 1 mysql mysql 417 Aug 10 11:06 ib_buffer_pool -rw-r----- 1 mysql mysql 12582912 Aug 10 11:06 ibdata1 -rw-r----- 1 mysql mysql 50331648 Aug 10 11:06 ib_logfile0 -rw-r----- 1 mysql mysql 50331648 Aug 10 11:06 ib_logfile1 drwxr-x--- 2 mysql mysql 4096 Aug 10 11:06 mysql drwxr-x--- 2 mysql mysql 8192 Aug 10 11:06 performance_schema drwxr-x--- 2 mysql mysql 8192 Aug 10 11:06 sys
查看日志文件是否生成
# ll /var/mysql/log
临时密码生成放在 error.log中
# cat /var/mysql/log/error.log 2019-11-18T09:06:22.922254Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2019-11-18T09:06:24.600401Z 0 [Warning] InnoDB: New log files created, LSN=45790 2019-11-18T09:06:24.853258Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2019-11-18T09:06:24.915246Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 5dbf9eac-9c4a-11e8-8768-000c29a48522. 2019-11-18T09:06:24.916709Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2019-11-18T09:06:24.917772Z 1 [Note] A temporary password is generated for root@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 -R mysql.mysql /var/mysql /var/lib/mysql
启动
/etc/init.d/mysqld start 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 –u root –p NS0+>RzwvHWl
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.23
Copyright (c) 2000, 2018, 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>
更改初始密码
mysql> alter user 'root'@'localhost' identified by '123456';
二、安装Zabbix Server
2.1 安装php
安装php7.1版本,zabbix3.0版本要求php5.4及以上。
先查看本地php版本
php -v
检查当前php的安装包
yum list installed | grep php
将本地php安装包卸载干净
yum remove php*
默认的yum源无法升级PHP,需要添加第三方yum源,我们选择webtatic库
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装php7.1
yum install -y php71w
安装相关插件
yum install -y php71w-fpm php71w-opcache php71w-cli php71w-gd php71w-imap php71w-mysqlnd php71w-mbstring php71w-mcrypt php71w-pdo php71w-pecl-apcu php71w-pecl-mongodb php71w-pecl-redis php71w-pgsql php71w-xml php71w-xmlrpc php71w-devel mod_php71w php71w-ldap php71w-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 -R 777 /var/lib/php/session/
2.2 安装zabbix
安装依赖包
yum -y install gcc* make curl curl-devel net-snmp net-snmp-devel perl-DBI httpd mariadb* mysql-devel libxml2-devel curl-devel unixODBC-devel net-snmp-devel OpenIPMI-devel openldap openldap-devel libevent-develjava-devellibssh2-devel
创建zabbix用户和组
groupadd zabbix useradd -g zabbix zabbix
编译、安装
tar zxvf zabbix-3.4.12.tar.gz cd zabbix-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 && make install chown -R zabbix.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@zabbix mysql]# ll total 4876 -rw-r--r--. 1 1001 1001 2877497 Jul 30 19:41 data.sql -rw-r--r--. 1 1001 1001 1978341 Jul 30 19:41 images.sql -rw-r--r--. 1 1001 1001 134791 Jul 30 19:41 schema.sql [root@zabbix mysql]# scp * root@192.168.75.251:/opt/
下面在mysql(192.168.75.251)服务器上操作
#mysql -u root –p
Enter password:
创建zabbix数据库,字符集设置为utf8
mysql>create database zabbix character set utf8 collate utf8_bin;
在mysql数据库中创建zabbix用户,赋予zabbix用户对zabbix数据库的全部权限,允许zabbix服务器远程访问mysql
mysql>GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@192.168.75.250IDENTIFIED BY 'zabbix'; mysql>GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost IDENTIFIED BY 'zabbix'; mysql>flush privileges; mysql>show databases ; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | zabbix | +--------------------+ 5 rows in set (0.00 sec)
导入数据文件,在控制台操作
#mysql -u zabbix -p zabbix
2.3zabbix web部署
回到Zabbix Server主机操作。在上面已经安装好httpd , 创建apache下创建zabbix目录
mkdir /var/www/html/zabbix
拷贝zabbix包中的web界面到apache zabbix目录下
\cp–rf /opt/soft/zabbix-3.4.12/frontends/php/* /var/www/html/zabbix/
配置web安全
chown -R apache.apache /var/www/html/zabbix chmod a+x /var/www/html/zabbix/conf/
拷贝zabbix包中服务启动脚本(server/agentd)到linux系统服务启动目录
cp /opt/soft/zabbix-3.4.12/misc/init.d/fedora/core/zabbix_server zabbix_agentd/etc/init.d/
修改/etc/init.d/zabbix_server和/etc/init.d/zabbix_agentd
BASEDIR=/usr/local修改成 BASEDIR=/usr/local/zabbix/
设置开机启动
systemctl enable httpd systemctl enable zabbix_server systemctl enable zabbix_agentd /etc/init.d/zabbix_server start /etc/init.d/zabbix_agentd start systemctl start httpd
2.4web服务初始化
http://192.168.75.250/zabbix/setup.php
连接数据库设置,写mysql服务器所在机器,端口,数据库名称,用户、密码
三、安装Zabbix Proxy
首先,在proxy机器上安装mysql ,跟上面的安装步骤一样,只是在导入mysql文件时,只导入一个文件,
#mysql–uzabbix –p zabbix
安装依赖包
yum -y install gcc* make curl curl-devel net-snmp net-snmp-devel perl-DBI httpd mariadb* mysql-devel libxml2-devel curl-devel unixODBC-devel net-snmp-devel OpenIPMI-devel openldap openldap-devel libevent-develjava-devellibssh2-devel
创建zabbix用户和组
groupadd zabbix useradd -g zabbix zabbix
编译、安装
tar zxvf zabbix-3.4.12.tar.gz cd zabbix-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 && make install chown -R zabbix.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 systemctl enable zabbix_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安装部署实践,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!