centos7.5离线安装zabbix4.0

一.配置环境

1.1 Linux环境说明

zabbix 安装要求 https://www.zabbix.com/documentation/4.0/zh/manual/installation/requirements
[root@localhost bw]# cat /etc/redhat-release 查看系统版本信息
CentOS Linux release 7.4.1708 (Core) 
[root@localhost bw]# systemctl stop firewalld.service 关闭防火墙
[root@localhost bw]# systemctl disable firewalld.service 开机禁止启动防火墙

[root@localhost bw]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled  #永久关闭selinux
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected. 
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

[root@localhost bw]#setenforce 0  临时关闭
[root@localhost bw]#getenforce  结果为Disabled 为关闭 检查selinux是否关闭

1.2 搭建LAMP环境

Zabbix是建立在LAMP或者LNMP环境之上,在此为了方便就使用yum安装LAMP环境。

# 建立仓库
[root@localhost bw]#yum -y install epel-release
[root@localhost bw]#yum -y install createrepo --downloadonly --downloaddir=/home/bw/repo

[root@localhost bw]# cd repo
[root@localhost repo]#yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash --downloadonly --downloaddir=/home/bw/repo
[root@localhost repo]# yum localinstall -y ./* 安装后检查应用版本
[root@localhost repo]# rpm -qa httpd php mariadb 安装后检查应用版本
httpd-2.4.6-89.el7.centos.x86_64
mariadb-5.5.60-1.el7_5.x86_64
php-5.4.16-46.el7.x86_64

# 编辑httpd
[root@localhost repo]# vim /etc/httpd/conf/httpd.conf
95 ServerName www.aihuidi.com:80 修改主机名,URL
164 DirectoryIndex index.html index.php 修改首页文件格式

# 编辑配置PHP,配置中国时区
[root@localhost repo]# vim /etc/php.ini
878 date.timezone = PRC

# 启动mysqld
[root@localhost repo]# systemctl start mariadb 启动数据库
[root@localhost repo]# systemctl enable mariadb 加入开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@localhost repo]# systemctl status mariadb 查看运行状态
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2019-06-13 00:31:21 CST; 11s ago
Main PID: 2490 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─2490 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─2653 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/ma...

Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: MySQL manual for more instructions.
Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: Please report any problems at http://mariadb.org/jira
Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: The latest information about MariaDB is available at http://mariadb.org/.
Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: You can find additional information about the MySQL part at:
Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: http://dev.mysql.com
Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: Consider joining MariaDB's strong and vibrant community:
Jun 13 00:31:19 node2 mariadb-prepare-db-dir[2412]: https://mariadb.org/get-involved/
Jun 13 00:31:19 node2 mysqld_safe[2490]: 190613 00:31:19 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Jun 13 00:31:19 node2 mysqld_safe[2490]: 190613 00:31:19 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Jun 13 00:31:21 node2 systemd[1]: Started MariaDB database server.

[root@localhost repo]# netstat -lntup|grep mysqld 查看服务端口是否存在
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2653/mysqld 
6370/mysqld

# 初始化数据库,并设置root用户密码
[root@localhost repo]# mysqladmin -u root password 123456 设置数据库密码
[root@localhost repo]# mysql -uroot -p 登录数据库
Enter password: 
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, 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; #创建zabbix数据库
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT all ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges; #刷新权限
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------+
| user | host |
+--------+-----------+
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | node2 |
| root | node2 |
+--------+-----------+
7 rows in set (0.00 sec)

MariaDB [(none)]> drop user ''@localhost; # 删除空用户
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------+
| user | host |
+--------+-----------+
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
| | node2 |
| root | node2 |
+--------+-----------+
6 rows in set (0.00 sec)

MariaDB [(none)]> quit;
Bye

二.安装zabbix

安装依赖包+组件

[root@localhost repo]# yum -y install net-snmp net-snmp-devel curl curl-devel libxml2 libxml2-devel libevent-devel.x86_64 javacc.noarch javacc-javadoc.noarch javacc-maven-plugin.noarch javacc* --downloadonly --downloaddir=/home/bw/repo
[root@localhost repo]# yum install php-bcmath php-mbstring -y --downloadonly --downloaddir=/home/bw/repo   安装php支持zabbix组件
[root@localhost repo]# rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm   安装zabbix yum源 ,本地下载,上传到虚拟机上
[root@localhost repo]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y --downloadonly --downloaddir=/home/bw/repo   安装zabbix组件

#报错的话添加yum源
cat <<EOF > /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - \$basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/\$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - \$basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/\$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
EOF

# 添加密钥
curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
curl https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX

yum localinstall -y ./* # 本地安装

安装zabbix agent篇(centos7)

[root@localhost repo]# wget http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.9-3.el7.x86_64.rpm
[root@localhost repo]# yum localinstall -y ./* 
[root@localhost repo]# hostname 
xxxxx
[root@localhost repo]# firewall-cmd --state
not running
[root@localhost repo]# vi /etc/zabbix/zabbix_agentd.conf Server=xx.xx.xx.xx #zabbix-server地址 ServerActive=xx.xx.xx.xx #zabbix-server地址 Hostname=agent1 #这台安装zabbix-agent的主机名,可以通过hostname命令查看主机名 [root@localhost repo]# systemctl start zabbix-agent.service [root@localhost repo]]# systemctl enable zabbix-agent.service Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service. [root@localhost repo]# systemctl status zabbix-agent.service [root@localhost repo]# cat /var/log/zabbix/zabbix_agentd.log
导入初始架构和数据,系统将提示您输入新创建的密码
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
Enter password: #导入数据到数据库zabbix中(最后一个zabbix是数据库zabbix),且因为用户zabbix是%(任意主机),密码是用户zabbix登陆密码zabbix

配置zabbix-server

[root@localhost repo]# vim /etc/zabbix/zabbix_server.conf 配置数据库密码
38:LogFile=/var/log/zabbix/zabbix_server.log
49:LogFileSize=0
72:PidFile=/var/run/zabbix/zabbix_server.pid
82:SocketDir=/var/run/zabbix
100:DBName=zabbix
116:DBUser=zabbix
124:DBPassword=123456 把注释打开写zabbix库的密码
356:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
473:Timeout=4
516:AlertScriptsPath=/usr/lib/zabbix/alertscripts
527:ExternalScripts=/usr/lib/zabbix/externalscripts
563:LogSlowQueries=3000

[root@localhost repo]# vim /etc/httpd/conf.d/zabbix.conf 修改时区
php_value date.timezone Asia/Shanghai

[root@localhost repo]# systemctl enable zabbix-server 启动zabbix服务并加入开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[root@localhost repo]# systemctl start zabbix-server
[root@localhost repo]# systemctl start httpd 启动httpd服务并加入开机自启动
[root@localhost repo]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@localhost repo]#

google 浏览器访问 http://ip/zabbix即可

zabbix离线包下载

# 链接:https://pan.baidu.com/s/1texfmbV-Y97gbGDamL_Ggg
# 提取码:hmir 下载离线包以后直接解压,然后切换到解压的目录下, 执行 yum localinstall -y ./* 即可完成安装,然后按照上面的步骤配置即可。

参考链接1:https://blog.csdn.net/weixin_43822878/article/details/91569016

参考链接2: https://blog.csdn.net/GongMeiyan/article/details/104079380

 

posted @ 2020-06-20 11:36  老虎死了还有狼  阅读(1599)  评论(0编辑  收藏  举报