centos 7 安装zabbix 4.0
实验环境
系统:centos 7 软件:Apache 2.4.6-93 mariadb 5.5.65 php 5.4.16 zabbix 4.0.21
安装前的准备工作
设置主机名为:zabbix-server [root@bogon ~]# vim /etc/hostname zabbix-server # 2、关闭selinux [root@bogon ~]# vim /etc/selinux/config ... SELINUX=disabled ... # 3、重启电脑 [root@bogon ~]# reboot
使用yum安装LAMP
[root@zabbix-server ~]# yum install httpd -y
1.1 验证Apache
启动Apache服务
[root@zabbix-server ~]# systemctl start httpd
访问本机127.0.0.1,你会看到如下界面:
安装mariadb
[root@zabbix-server ~]# yum install mariadb-server mariadb -y
对mariadb进行初始化安全设置
1 [root@zabbix-server ~]# systemctl start mariadb # 启动mariadb 2 [root@zabbix-server ~]# mysql_secure_installation # 初始化mariadb数据库 3 4 NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB 5 SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! 6 7 In order to log into MariaDB to secure it, we'll need the current 8 password for the root user. If you've just installed MariaDB, and 9 you haven't set the root password yet, the password will be blank, 10 so you should just press enter here. 11 12 Enter current password for root (enter for none): # 默认root密码为空,这里回车即可 13 OK, successfully used password, moving on... 14 15 Setting the root password ensures that nobody can log into the MariaDB 16 root user without the proper authorisation. 17 18 Set root password? [Y/n] Y # 是否设置root密码 19 New password: # 设置root密码 20 Re-enter new password: # 确认密码 21 Password updated successfully! 22 Reloading privilege tables.. 23 ... Success! 24 25 26 By default, a MariaDB installation has an anonymous user, allowing anyone 27 to log into MariaDB without having to have a user account created for 28 them. This is intended only for testing, and to make the installation 29 go a bit smoother. You should remove them before moving into a 30 production environment. 31 32 Remove anonymous users? [Y/n] Y # 是否删除匿名用户,建议删除,否则可以通过匿名用户访问数据库 33 ... Success! 34 35 Normally, root should only be allowed to connect from 'localhost'. This 36 ensures that someone cannot guess at the root password from the network. 37 38 Disallow root login remotely? [Y/n] n # 是否拒绝root远程登录,这里是实验环境我们允许 39 ... skipping. 40 41 By default, MariaDB comes with a database named 'test' that anyone can 42 access. This is also intended only for testing, and should be removed 43 before moving into a production environment. 44 45 Remove test database and access to it? [Y/n] Y # 是否删除默认test数据库,这个随意 46 - Dropping test database... 47 ... Success! 48 - Removing privileges on test database... 49 ... Success! 50 51 Reloading the privilege tables will ensure that all changes made so far 52 will take effect immediately. 53 54 Reload privilege tables now? [Y/n] Y # 是否使设置立即生效 55 ... Success! 56 57 Cleaning up... 58 59 All done! If you've completed all of the above steps, your MariaDB 60 installation should now be secure. 61 62 Thanks for using MariaDB! mysql_secure_installation
设置客户端和服务端的字符集为utf-8
[root@zabbix-server ~]# vim /etc/my.cnf [mysqld] character-set-server=utf8 # 设置服务端的字符集 collation-server=utf8_general_ci # 设置服务端的字符集 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid [client] # 设置客户端的字符集 default-character-set=utf8 [mysql] # 设置客户端的字符集 default-character-set=utf8 # # include all files from the config directory # !includedir /etc/my.cnf.d
重启mariadb
[root@zabbix-server ~]# systemctl restart mariadb
3、安装php
[root@zabbix-server ~]# yum install php php-mysql -y
3.1 验证php
在/var/www/html下创建index.php
[root@zabbix-server ~]# vim /var/www/html/index.php <?php phpinfo(); ?>
重启Apache
[root@zabbix-server ~]# systemctl restart httpd
安装zabbix
1、下载zabbix
[root@zabbix-server ~]# wget https://cdn.zabbix.com/zabbix/sources/stable/4.0/zabbix-4.0.21.tar.gz -P /usr/src/
2、解压
[root@zabbix-server ~]# tar -zxvf /usr/src/zabbix-4.0.21.tar.gz -C /opt/
3、创建运行zabbix账户
[root@zabbix-server ~]# groupadd zabbix [root@zabbix-server ~]# useradd -g zabbix zabbix
4、创建zabbix数据库
[root@zabbix-server mysql]# mysql -uroot -p MariaDB [(none)]> create database zabbix; MariaDB [(none)]> use zabbix; MariaDB [zabbix]> source /opt/zabbix-4.0.21/database/mysql/schema.sql MariaDB [zabbix]> source /opt/zabbix-4.0.21/database/mysql/data.sql
5、配置zabbix
[root@zabbix-server ~]# cd /opt/zabbix-4.0.21/ [root@zabbix-server zabbix-4.0.21]# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
这时可能报如下错误:
先装依赖包
yum install mysql-devel libxml2 libxml2-devel net-snmp-devel libevent-devel curl-devel -y
原因是缺少mysql-devel ,安装即可。
[root@zabbix-server zabbix-4.0.21]# yum install mysql-devel -y
安装完成后再次进行配置
[root@zabbix-server zabbix-4.0.21]# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
这时可能会报如下错误:
原因是缺少libxml,安装即可。
[root@zabbix-server zabbix-4.0.21]# yum install libxml2 libxml2-devel -y
安装完成后再次进行配置
[root@zabbix-server zabbix-4.0.21]# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
这时可能会报如下错误:
原因是缺少 net-snmp-devel,安装即可。
[root@zabbix-server zabbix-4.0.21]# yum install net-snmp-devel -y
安装完成后再次进行配置
[root@zabbix-server zabbix-4.0.21]# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
这时可能会报如下错误:
原因是缺少libevent-devel,安装即可。
[root@zabbix-server zabbix-4.0.21]# yum install libevent-devel -y
安装完成后再次进行配置
[root@zabbix-server zabbix-4.0.21]# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
这时可能会报如下错误:
原因是缺少curl-devel,安装即可。
[root@zabbix-server zabbix-4.0.21]# yum install curl-devel -y
安装完成后再次进行配置
[root@zabbix-server zabbix-4.0.21]# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
经过上面诸多错误,终于来到了如下所示:
6、安装zabbix
[root@zabbix-server zabbix-4.0.21]# make install
7、编辑配置文件/usr/local/etc/zabbix_server.conf
[root@zabbix-server zabbix-4.0.21]# vim /usr/local/etc/zabbix_server.conf DBHost=localhost DBName=zabbix DBUser=root DBPassword=root的密码 DBPort=3306
8、使用web界面安装zabbix
8.1 创建zabbix在web中的工作目录
[root@zabbix-server zabbix-4.0.21]# mkdir /var/www/html/zabbix
8.2 将/opt/zabbix-4.0.21/frontends/php/下的所有文件复制到/var/www/html/zabbix
[root@zabbix-server zabbix-4.0.21]# cd frontends/php/ [root@zabbix-server php]# cp -a . /var/www/html/zabbix/
8.3 在web上进行安装
访问http://127.0.0.1/zabbix我们会看到如下:
此时我们只能在centos本机上访问http://127.0.0.1/zabbix,这样操作不方便,并且其它主机将不能使用zabbix,所以调整httpd.conf文件。
[root@zabbix-server php]# vim /etc/httpd/conf/httpd.conf Listen 192.168.10.100:80 # 将监听地址改成服务器的IP地址 # 修改完成后重启Apache [root@zabbix-server php]# systemctl restart httpd # 停止防火墙 [root@zabbix-server php]# systemctl stop firewalld
此时我们便可以在宿主机上访问Apache服务了。
点击下一步后我们会看到一个提示信息,提示哪里需要整改。
错误大致分为两部分,一个是需要调整PHP的配置文件,一个缺少一些php组件。
8.4 调整php配置文件
[root@zabbix-server php]# vim /etc/php.ini post_max_size = 16M max_execution_time = 300 max_input_time = 300 date.timezone = Asia/Shanghai
重启Apache
[root@zabbix-server php]# systemctl restart httpd
再次访问http://192.168.10.100/zabbix/
我们可以看到关于php配置文件的错误没了,现在只剩php组件了。
8.5 安装php缺失的组件
[root@zabbix-server ~]# yum install php-bcmath php-mbstring php-gd libjpeg* php-ldap php-xml php-xmlrpc -y
安装完成后,重启Apache。
[root@zabbix-server ~]# systemctl restart httpd
再次访问http://192.168.10.100/zabbix/,你会看到如下:
点击下一步后,会进入到连接数据库的界面:
如果下一步出现如下错误:
表示数据库zabbix的字符集有问题。
删除数据库zabbix,并重新创建zabbix,导入数据。
[root@zabbix-server ~]# mysql -uroot -p MariaDB [(none)]> drop database zabbix; MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin; MariaDB [(none)]> use zabbix; MariaDB [zabbix]> source /opt/zabbix-4.0.21/database/mysql/schema.sql MariaDB [zabbix]> source /opt/zabbix-4.0.21/database/mysql/images.sql MariaDB [zabbix]> source /opt/zabbix-4.0.21/database/mysql/data.sql
设置完成后刷新页面,我们会看到如下界面:
点击下一步后,我们会看到如下界面:
下一步后我们会看到如下界面:
点击下一步后来到安装页面:
造成该错误的原因是Apache的用户对/var/www/html/zabbix/conf没有写入的权限。
我们给写入权限即可,如下:
[root@zabbix-server ~]# chmod a+w /var/www/html/zabbix/conf
刷新页面后你会看到如下:
点击Finish后你会看到如下界面:
登录成功后你会看到如下界面:
我们可以看到zabbix server并没有运行,造成这种情况的原因很多,我们可以通过查看日志文件来了解问题产生的原因,默认日志文件在/tmp/zabbix_server.log。
如果是数据库连接的问题,我们要确保/var/www/html/zabbix/conf/zabbix.conf.php和vim /usr/local/etc/zabbix_server.conf中的数据库信息一致,并且数据库用户名和密码正确。
我们这里出现这个问题的原因是没有开启zabbix server服务。
[root@zabbix-server ~]# zabbix_server
刷新页面我们会看到如下:
到此zabbix的安装就简单介绍到这里。