一、源码安装方式:zabbix-server
LAMP环境准备:
#groupadd zabbix
#useradd -g zabbix zabbix
1、安装依赖包:
#yum install gcc gcc-c++ httpd mysql-devel php php-gd php-xml php-mysql libxml2-devel.x86_64 net-snmp-devel.x86_64 curl-devel
2、解压zabbix源码包到指定路径:
#tar zvxf zabbix-3.2.3.tar.gz -C /usr/local/
#cd /usr/local/zabbix-3.2.3/
#./configure --prefix=/opt/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
#make install
3、在mysql或mariadb创建zabbix数据库及zabbix表结构导入:
mysql>create database zabbix default charset utf8;
msyql>grant all on zabbix.* to 'zabbix'@'localhost' identified by '123456'; #注:如果是用此命令授权用户导入数据,必须授权为all权限,否则导入数据时会报拒绝访问的错误
#cd /usr/local /zabbix-3.2.3/database/mysql
#mysql -uzabbix -p123456 zabbix < ./schema.sql
#mysql -uzabbix -p123456 zabbix < ./imges.sql
#mysql -uzabbix -p123456 zabbix < ./data.sql
4、查看和编辑配置server、agentd文件:
#cp /usr/local/zabbix-3.2.3/misc/init.d/fedora/core/zabbix_server /etc/init.d/ #将server启动命令拷贝至/etc/init.d/下,服务端默认绑定端口号是10051
#cp /usr/local/zabbix-3.2.3/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/ #将agentd启动命令拷贝至/etc/init.d/下,服务端默认绑定端口号是10050
#vim /etc/php.ini #配置php文件
max_execution_time = 300
max_input_time = 300
post_max_size = 16M
date.timezone = Asia/Shanghai
#vim /etc/init.d/zabbix_server #配置zabbix-server编译时的路径
BASEDIR=/opt/zabbix
#vim /etc/init.d/zabbix_agentd #配置zabbix-agentd编译时的路径
BASEDIR=/opt/zabbix
#vim /opt/zabbix/etc/zabbix_server.conf #server端配置文件,必须指定数据库名称,用户和密码
LogFile= /opt/zabbix/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBPassword=123456
#vim /opt/zabbix/etc/zabbix_agentd.conf #agentd端配置文件,指定本机zabbix-server ip地址及连接方式,主动还是被动,默认为主动方式:activeserver
Server=192.168.10.80 #server端ip地址
ListenPort=9050 #本机agentd监听端口
ServerActive=192.168.10.80:9051 #server端ip地址和server监听端口
Hostname=254_Zabbix #定义agentd主机名称
Include=/opt/zabbix/etc/zabbix_agentd.conf.d/ #指定自定义监控文件存放目录
UnsafeUserParameters=1 #开启自定义监控
5、安装Zabbix Web界面,复制PHP文件:
#cp -r /usr/local/zabbix-3.2.3/frontends/php/ /var/www/html/zabbix
#chown -R apache.apache /var/www/html/zabbix
#chmod -R 755 /var/www/html/zabbix
6、启动httpd服务:
#systemctl restart httpd #注:zabbix成功安装后,无需启动zabbix-server也可得到zabbix默认页面
#/etc/init.d/zabbix_server start
#/etc/init.d/zabbix_agentd start
7、验证zabbix安装是否成功:
打开Zabbix URL:http://ip/zabbix
二、yum安装方式:
1、安装Zabbix存储库:
# rpm -Uvh https://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
# yum clean all
2、安装Zabbix服务器,前端,代理:
# yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
3、创建初始数据库:
# mysql -uroot -ppassword
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
4、导入初始架构和数据:
# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
5、编辑文件/etc/zabbix/zabbix_server.conf
#vi 编辑文件/etc/zabbix/zabbix_server.conf
LogFile= /opt/zabbix/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBPassword=123456
6、编辑文件/etc/httpd/conf.d/zabbix.conf,取消注释并为您设置正确的时区:
date.timezone = Asia/Shanghai
7、启动Zabbix服务器和代理程序进程并使其在系统引导时启动:
# systemctl restart zabbix-server zabbix-agent httpd
8、配置Zabbix前端:
连接到新安装的Zabbix前端:http://server_ip_or_name/
三、安装zabbix-agentd
操作步骤:解压压缩包、修改配置文件、运行zabbix_agentd服务、查看进程和端口。
1、环境准备:
#mkdir /opt/zabbix
#groupadd zabbix
# useradd -g zabbix zabbix
# rpm -qa gcc gcc-c++
2、解压压缩包:
# tar -zvxf zabbix-3.2.3.tar.gz -C /opt/shinemonitor
# cd /usr/local /zabbix-3.2.3/
# ./configure --prefix=/opt/zabbix --enable-agent
# make install
# ls /opt/zabbix/
bin etc lib sbin share
3、修改配置文件:/opt/zabbix/etc/zabbix_agentd.conf
#vim /opt/zabbix/etc/zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log #默认日志文件路径,若要更改,记得给修改该文件权限
Server=192.168.4.59 #zabbix-server ip地址
ServerActive=192.168.4.59:10051 #zabbix-server ip地址和端口(主动将数据传输给zabbix-server)
Hostname=149CS_Zabbix #定义web端创建主机时的主机名,必须与这里一致
4、拷贝并修改zabbix-agentd启动配置文件:/etc/init.d/zabbix_agentd
# cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
# chmod +x /etc/init.d/zabbix_agentd
# vim /etc/init.d/zabbix_agentd
BASEDIR=/opt/zabbix #路径为编译时的路径
5、启动zabbix_agentd并验证:
# /etc/init.d/zabbix_agentd start
# ps -ef |grep zabbix_agentd
# netstat -anptul | grep :10050
# cat /tmp/zabbix_agentd.log