CentOS Linux release 7.3源码安装zabbix

           CentOS Linux release 7.3安装zabbix

                                          作者:尹正杰

 版权声明:原创作品,谢绝转载!否则将追究法律责任。

  

 

前言:

  我去年用用centos6的环境搭建了一下 zabbix3.0版本的,新到的公司用的都是centos7的操作系统,没法,之前的搭建的我就没有直接照搬过来,就用centos7研究了一下搭建的方法,也是百度出来的,也才过不少坑,不过终究还是搭建起来了,其实你在看搭建的步骤其实就跟之前的一篇博客的步骤是类似的,只不过是更换了操作系统,以及欢乐一下数据库而已,那么下面我们就一起来用centos7的操作系统来搭建一下zabbix吧,你会发现其实真的很简单。

 

一.实验环境

 

二.安装依赖工具

[root@yinzhengjie ~]# yum -y install gcc* make php php-gd php-mysql php-bcmath php-mbstring php-xml 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 vim   #这个可能需要等待一会时间,因为一次性安装包太多,记住你的服务器要联网在执行这条命令哟~除非你制作的有本地源。

 

三.关闭防火漆和selinux

  注意:我这里是因为在局域网,没有做NAT访问工位,如果你给您的服务器配置了一个固定的IP地址的话,建议开启必要的端口,我这里为了试验方便就没有开启了.因为我现在也是一个centos7的新手。以后有时间了可以研究一下如何在开启selinux的情况下使得服务正常运行。建议在内网做监控哟!如果贵公司向用您的zabbix监控您全国各地的服务器的话建议开启防火墙和selinux,避免不法分子的入侵!

[root@yinzhengjie ~]#  systemctl stop firewalld.service  #关闭防火强,重启后有会恢复上一次的配置情况。

[root@yinzhengjie ~]# systemctl disable firewalld.service  #禁止防火墙开机自启,即重启后,防火墙就不会自动启动了。

[root@yinzhengjie ~]# firewall-cmd --state #查看防火墙是否是启动状态
not running
[root@yinzhengjie ~]#

[root@yinzhengjie ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config  #禁用selinux,需重启

[root@yinzhengjie ~]# setenforce 0 #临时关闭,不需要重启就关闭了

 

四.源码安装zabbix3.2

1.下载zabbix3.2包,我是在网上download的,大家可以自行下载,以下是我实验环境的安装包:

链接:http://pan.baidu.com/s/1c25qjpY 密码:ktyw

2.将安装包上传到服务器上,并解压安装

[root@yinzhengjie ~]# mkdir -pv /yinzhengjie/tools/zabbix  && /yinzhengjie/tools/zabbix/ #创建一个存放软件包的目录

[root@yinzhengjie zabbix]# yum -y install lrzsz  #安装上传工具,将zabbix安装包上传上来

[root@yinzhengjie zabbix]# tar -xf zabbix-3.2.4.tar.gz
[root@yinzhengjie zabbix]# cd zabbix-3.2.4
[root@yinzhengjie zabbix-3.2.4]# ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-unixodbc  

[root@yinzhengjie zabbix-3.2.4]# make -j 4 && make install 

3.严重是否安装成

[root@yinzhengjie zabbix-3.2.4]# echo $? #如果返回值非"0"说明你安装失败了!需要先拍错哪里出了问题~
0
[root@yinzhengjie zabbix-3.2.4]#

 

五.数据库授权

1.创建管理zabbix的用户

[root@yinzhengjie zabbix-3.2.4]# groupadd zabbix
[root@yinzhengjie zabbix-3.2.4]# useradd zabbix -s /sbin/nologin -M -g zabbix
[root@yinzhengjie zabbix-3.2.4]#

2.启动数据库

[root@yinzhengjie zabbix-3.2.4]# systemctl start mariadb.service
[root@yinzhengjie zabbix-3.2.4]# echo $?
0
[root@yinzhengjie zabbix-3.2.4]#

3.给数据库设置管理密码

[root@yinzhengjie zabbix-3.2.4]# mysqladmin -u root -p password yinzhengjie  #设置root的密码为yinzhengjie
Enter password:  #直接回车就好~因为咱们是第一次启动数据库,默认密码为空

[root@yinzhengjie zabbix-3.2.4]# mysql -pyinzhengjie  #验证数据库是否能正常登陆,出现以下信息说明配置的就没有问题。
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

4.数据库授权zabbix用户

[root@yinzhengjie zabbix-3.2.4]# mysql -pyinzhengjie
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> insert into mysql.user(Host,User,Password) values('localhost','zabbix',password('zabbix'));
Query OK, 1 row affected, 4 warnings (0.00 sec)

MariaDB [(none)]> flush privileges; #这里要把上面2台语句刷新以下哟~不然直接敲击下一行命令是会报错的,因为数据库此时还没有更新上面两天的数据~
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix' with grant option;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit
Bye
[root@yinzhengjie zabbix-3.2.4]#

5.导入Sql语句

[root@yinzhengjie zabbix-3.2.4]# mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql
[root@yinzhengjie zabbix-3.2.4]# mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql
[root@yinzhengjie zabbix-3.2.4]# mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql
[root@yinzhengjie zabbix-3.2.4]#

六.修改PHP的配置参数

[root@yinzhengjie zabbix-3.2.4]# 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

 

七.移动zabbix项目到httpd目录中去

[root@yinzhengjie zabbix-3.2.4]# cp -r ./frontends/php/  /var/www/html/zabbix 

[root@yinzhengjie zabbix-3.2.4]# ll /var/www/html/
总用量 4
drwxr-xr-x. 13 root root 4096 4月 24 12:22 zabbix

[root@yinzhengjie zabbix-3.2.4]# chown -R apache.apache /var/www/html/zabbix/

[root@yinzhengjie zabbix-3.2.4]# ll /var/www/html/
总用量 4
drwxr-xr-x. 13 apache apache 4096 4月 24 12:22 zabbix
[root@yinzhengjie zabbix-3.2.4]#

 

八.配置开机启动

[root@yinzhengjie zabbix-3.2.4]# cp misc/init.d/fedora/core/zabbix_*   /etc/init.d/

[root@yinzhengjie zabbix-3.2.4]# chkconfig --add zabbix_server
[root@yinzhengjie zabbix-3.2.4]# chkconfig --add zabbix_agentd
[root@yinzhengjie zabbix-3.2.4]# chkconfig zabbix_server on
[root@yinzhengjie zabbix-3.2.4]# chkconfig zabbix_agentd on
[root@yinzhengjie zabbix-3.2.4]#

 

九.编译安装Zabbix Agent并配置

1.安装zabbbix Agent

[root@yinzhengjie zabbix-3.2.4]# pwd
/yinzhengjie/tools/zabbix/zabbix-3.2.4
[root@yinzhengjie zabbix-3.2.4]# ./configure --enable-agent

[root@yinzhengjie zabbix-3.2.4]# make -j 4 && make install

2.配置zabbix Agent

[root@yinzhengjie ~]# more /usr/local/etc/zabbix_agentd.conf | grep -v ^$ | grep -v ^#
LogFile=/tmp/zabbix_agentd.log
Server=172.16.96.210,127.0.0.1
ServerActive=172.16.96.210,127.0.0.1
Hostname=Zabbix server

[root@yinzhengjie ~]# more /usr/local/etc/zabbix_server.conf| grep -v ^# | grep -v ^$
LogFile=/tmp/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
Timeout=4
LogSlowQueries=3000
[root@yinzhengjie ~]#

 

 

十.启动服务器,web安装zabbix

 1.启动服务

[root@yinzhengjie zabbix-3.2.4]# systemctl enable httpd.service
[root@yinzhengjie zabbix-3.2.4]# systemctl enable mariadb.service

[root@yinzhengjie zabbix-3.2.4]# systemctl start httpd.service
[root@yinzhengjie zabbix-3.2.4]# echo $?
0
[root@yinzhengjie zabbix-3.2.4]# ps -ef | grep http  #检查服务是否启动成功
root 9968 1 1 13:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 9970 9968 0 13:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 9971 9968 0 13:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 9972 9968 0 13:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 9973 9968 0 13:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 9974 9968 0 13:04 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 9976 2361 0 13:04 pts/0 00:00:00 grep --color=auto http
[root@yinzhengjie zabbix-3.2.4]#

2.web登录

输入服务器IP地址+项目名称

点击下一步

输入密码zabbix点击下一步

点击下一步

继续点击下一步,别克制

点击完成

输入用户名和密码:注意用户名第一个字母是大写哟~

 

 打完收工,如果想看如何将页面配置成中文的话请参考:http://www.cnblogs.com/yinzhengjie/p/6126943.html

 

posted @ 2017-04-24 11:31  尹正杰  阅读(2860)  评论(0编辑  收藏  举报