一、安装前期准备
我是在CentOS7 最小安装环境下部署的
1.下载wget
yum install wget -y
2.换repo源
# 我换的是阿里的源,推荐国内的源:
# 163源 http://mirrors.163.com/.help/CentOS7-Base-163.repo
# 备份原有源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
# 下载阿里源到/etc/yum.repos.d/目录下
cd /etc/yum.repos.d/
wget http://mirrors.aliyun.com/repo/Centos-7.repo
# 运行以下命令生成缓存
yum clean all
yum makecache
3.更新系统
yum update -y
4.升级内核(可做可不做)
(1)导入key
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
(2)安装elrepo的yum源
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
(3)安装内核
yum --enablerepo=elrepo-kernel install kernel-ml-devel kernel-ml
(4)安装后查看默认启动顺序
awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
CentOS Linux (4.10.1-1.el7.elrepo.x86_64) 7 (Core)
CentOS Linux (3.10.0-514.10.2.el7.x86_64) 7 (Core)
CentOS Linux (0-rescue-e1137a3a0e984ae3bdefd3d7502f1aaa) 7 (Core)
(5)调整内核启动顺序
# 看step 4 默认的启动顺序是从0开始,新内核是从最上面开始插入的,目前位置在0,因此选择0
grub2-set-default 0
# 调整后重启
reboot
# 重启后查看当前内核版本
uname -r
4.10.1-1.el7.elrepo.x86_64
(6)删除旧内核
yum remove kernel
二、安全设置
# 这里我为了简便安全设置,因此把安全类相关设置都关闭
1.临时关闭Selinux
setenforce 0
2.关闭Selinux
# 将SELINUX = enforcing改为disabled
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
3.停止启动防火墙+关闭防火墙
systemctl disable firewalld
systemctl stop firewalld
三、安装Zabbix 3.2.4 - 通过源码编译安装
1.安装所需包
# httpd,httpd-devel apache服务
# mariadb,mariadb-server,mariadb-devel 在Centos7中已经将默认的mysql替换为mariadb
# php相关包(php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml php-bcmath) php版本必须大于5.4
# zabbix编译需要使用的gcc,libxml2-devel,net-snmp,java,curl-devel
yum -y install httpd httpd-devel mariadb mariadb-server mariadb-devel php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml php-bcmath gcc* libxml2-devel net-snmp* java* curl-devel
2.从官网下载zabbix 3.2.4源码包
#http://www.zabbix.com/download找到最新版源码下载
(方法一)
cd /usr/local/src/
wget https://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.2.4/zabbix-3.2.7.tar.gz?r=http%3A%2F%2Fwww.zabbix.com%2Fdownload&ts=1489035350&use_mirror=superb-dca2
(方法二)
使用filezilla、winscp等软件
直接将下载的源码zabbix-3.2.7.tar.gz包放到/usr/local/src目录下
3.安装zabbix
(1)解压软件包
cd /usr/local/src
tar zxvf zabbix-3.2.7.tar.gz
(2)创建zabbix用户和组
groupadd zabbix
useradd -g zabbix zabbix
(3)配置&安装
cd zabbix-3.2.7
./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --enable-java
#配置顺利后会出现一个清单
Configuration:
Detected OS: linux-gnu
Install path: /usr/local
Compilation arch: linux
Compiler: gcc
Compiler flags: -g -O2
Library-specific flags:
database: -I/usr/include/mysql -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fPIC -g -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing -DMY_PTHREAD_FASTMUTEX=1
libXML2: -I/usr/include/libxml2
Net-SNMP: -I/usr/local/include -I/usr/lib64/perl5/CORE -I. -I/usr/include
Enable server: yes
Server details:
With database: MySQL
WEB Monitoring: cURL
Native Jabber: no
SNMP: yes
IPMI: no
SSH: no
TLS: no
ODBC: no
Linker flags: -L/usr/lib64/mysql -L/usr/lib64 -rdynamic
Libraries: -lmysqlclient -lxml2 -lnetsnmp -lcurl -lm -ldl -lresolv
Enable proxy: no
Enable agent: yes
Agent details:
TLS: no
Linker flags: -rdynamic
Libraries: -lcurl -lm -ldl -lresolv
Enable Java gateway: yes
Java gateway details:
Java compiler: javac
Java archiver: jar
LDAP support: no
IPv6 support: yes
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
(4)执行make安装
make && make install
*********************************************************
* # 安装后zabbix的相关目录 *
* #默认配置文件目录:/usr/local/etc/ *
* #zabbix服务端和客户端可执行文件目录:/usr/local/sbin/ *
* #zabbix_get采集信息可执行文件目录:/usr/local/bin/ *
*********************************************************
4.数据库操作
(1)启动+运行Mariadb
systemctl enable mariadb
systemctl start mariadb
(2)Mariadb初始化
mysql_secure_installation
#一路y+回车走起~,下面这步注意,需要设置root密码,如果不设置n
**********************************
* Set root password? [Y/n] y *
* New password: *
* Re-enter new password: *
* Password updated successfully! *
**********************************
(3)创建DB并授权
mysql -uroot -p
Enter password:
create database zabbix default character set utf8 collate utf8_bin;
#identified by '这里是zabbix账号的密码'
grant all privileges on zabbix.* to 'zabbix'@'%' identified by 'zabbix';
flush privileges;
exit
(4)导入数据库
cd /usr/local/src/zabbix-3.2.7/database/mysql
[root@localhost mysql]# mysql -uzabbix -p zabbix < schema.sql
Enter password: //zabbix
[root@localhost mysql]# mysql -uzabbix -p zabbix < images.sql
Enter password: //zabbix
[root@localhost mysql]# mysql -uzabbix -p zabbix < data.sql
Enter password: //zabbix
5.修改配置
(1)修改zabbix所需php配置
vi /etc/php.ini
max_execution_time = 300
max_input_time = 300
post_max_size = 16M
date.timezone = Asia/Shanghai
(2)修改zabbix_server配置文件
vi /usr/local/etc/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
AlertScriptsPath=/usr/local/share/zabbix/alertscripts
ListenIP=localhost
(3)将zabbix的php文件发布到apache
mkdir /var/www/html/zabbix
cd /usr/local/src/zabbix-3.2.7/frontends/php
cp -a . /var/www/html/zabbix/
6.开启相关服务
(1)zabbix-server
cp /usr/local/src/zabbix-3.2.7/misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server
cp /usr/local/src/zabbix-3.2.7/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd
chmod u+x /etc/rc.d/init.d/zabbix_server
chmod u+x /etc/rc.d/init.d/zabbix_agentd
chkconfig zabbix_server on
chkconfig zabbix_agentd on
(2)修改zabbix安装目录,其实就是确认一下,因为我直接安装在了/usr/local下
vi /etc/rc.d/init.d/zabbix_server
vi /etc/rc.d/init.d/zabbix_agentd
BASEDIR=/usr/local
#zabbix_agentd确认内容同上
(3)启动httpd服务
systemctl enable httpd
systemctl start httpd
7.访问初始页面
(1)登录 http://127.0.0.1/zabbix/
(2)按照要求配置,最后一步说明
进入命令行
cd /var/www/html/zabbix/conf/
cp zabbix.conf.php.example zabbix.conf.php
chown -R zabbix:zabbix *
vi /var/www/html/zabbix/conf/zabbix.conf.php
<?php
// Zabbix GUI configuration file.
global $DB;
$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = 'localhost';
$DB['PORT'] = '3306';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix';
$DB['PASSWORD'] = 'zabbix';
// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';
$ZBX_SERVER = 'localhost';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = 'monitor';
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
:wq
(3)reboot
#乱码问题
找到微软雅黑-常规字体,复制出来将文件名修改为msyh.ttf,然后上传到/var/www/html/zabbix/fonts
vi /var/www/html/zabbix/include/defines.inc.php
define('ZBX_GRAPH_FONT_NAME', 'msyh'); // font file name old> graphfont