# 准备环境[root@ZabbixServer-01 ~] # cat /etc/redhat-releaseCentOS Linux release 7.5.1804 (Core)[root

# 准备环境
[root@ZabbixServer-01 ~] # cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@ZabbixServer-01 ~] # uname -r
3.10.0-862.el7.x86_64
[root@ZabbixServer-01 ~] # setenforce 0
[root@ZabbixServer-01 ~] # sed -i_bak$(date +%Y%m%d) '7s#enforcing#disabled#' /etc/selinux/config
[root@ZabbixServer-01 ~] # systemctl stop firewalld && systemctl disable firewalld
[root@ZabbixServer-01 ~] # yum install -y vim net-tools lsof wget curl lrzsz
 
# 安装NTP
[root@ZabbixServer-01 ~] # yum install -y ntp
[root@ZabbixServer-01 ~] # systemctl start ntpd && systemctl enable ntpd
 
# 安装zabbix noarch.rpm
[root@ZabbixServer-01 ~] # rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
 
# 修改/etc/yum.repos.d/zabbix.repo,将[zabbix-frontend]下的enabled改为1【注意项】
[root@ZabbixServer-01 ~] # sed -i_bak$(date +%Y%m%d) '11s#enabled=0#enabled=1#' /etc/yum.repos.d/zabbix.repo
[root@ZabbixServer-01 ~] # yum clean all
[root@ZabbixServer-01 ~] # yum repolist | grep zabbix
zabbix /x86_64 Zabbix Official Repository - x86_64              200
zabbix-frontend /x86_64 Zabbix Official Repository frontend - x86_64     183
zabbix-non-supported /x86_64 Zabbix Official Repository non-supported - x8      5
 
# 安装zabbix server和agent
[root@ZabbixServer-01 ~] # yum install -y zabbix-server-mysql zabbix-agent zabbix-get
 
# 安装Software Collections便于后续安装高版本的php
[root@ZabbixServer-01 ~] # yum install -y centos-release-scl
 
# 安装zabbix FE和相关环境
[root@ZabbixServer-01 ~] # yum install -y zabbix-web-mysql-scl zabbix-apache-conf-scl
 
# 安装centos7默认的mariadb数据库
[root@ZabbixServer-01 ~] # yum install -y mariadb mariadb-server
[root@ZabbixServer-01 ~] # systemctl start mariadb && systemctl enable mariadb
 
# 安全初始化mariadb并配置root密码
[root@ZabbixServer-01 ~] # mysql_secure_installation
 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
 
In order to log into MariaDB to secure it, we'll need the current
password  for the root user.  If you've just installed MariaDB, and
you haven't  set the root password yet, the password will be blank,
so you should just press enter here.
 
Enter current password  for root (enter  for none):   # 空密码,直接回车
OK, successfully used password, moving on...
 
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
 
Set root password? [Y /n ] Y    # 是否设置root密码
New password:     # root密码
Re-enter new password:   # 再次输入root密码
Password updated successfully!
Reloading privilege tables..
 ... Success!
 
 
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created  for
them.  This is intended only  for testing, and to  make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
 
Remove anonymous  users ? [Y /n ] Y   # 是否删除匿名账号
 ... Success!
 
Normally, root should only be allowed to connect from  'localhost' .  This
ensures that someone cannot guess at the root password from the network.
 
Disallow root login remotely? [Y /n ] Y   # 是否禁止root远程登录
 ... Success!
 
By default, MariaDB comes with a database named  'test' that anyone can
access.  This is also intended only  for testing, and should be removed
before moving into a production environment.
 
Remove  test database and access to it? [Y /n ] Y   # 是否删除test库和test库的访问权限
 - Dropping  test database...
 ... Success!
 - Removing privileges on  test database...
 ... Success!
 
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
 
Reload privilege tables now? [Y /n ] Y   # 是否刷新授权表使其立即生效
 ... Success!
 
Cleaning up...
 
All  done !  If you've completed all of the above steps, your MariaDB
installation should now be secure.
 
Thanks  for using MariaDB!
 
# 测试root登录,并授权
[root@ZabbixServer-01 ~] # mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection  id is 12
Server version: 5.5.68-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.
# 创建zabbix数据库
MariaDB [(none)]> create database zabbix character  set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
# 创建zabbix用户
MariaDB [(none)]> create user zabbix@localhost identified by  'zabbix@01' ;
Query OK, 0 rows affected (0.00 sec)
# 授权zabbix权限
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
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,password from mysql.user;
+--------+-----------+-------------------------------------------+
| user   | host      | password                                  |
+--------+-----------+-------------------------------------------+
| root   | localhost | *A35F952D7E492A65F4DB82E1ECBFB4BBBC415BFF |
| root   | 127.0.0.1 | *A35F952D7E492A65F4DB82E1ECBFB4BBBC415BFF |
| root   | ::1       | *A35F952D7E492A65F4DB82E1ECBFB4BBBC415BFF |
| zabbix | localhost | *A35F952D7E492A65F4DB82E1ECBFB4BBBC415BFF |
+--------+-----------+-------------------------------------------+
4 rows  in set (0.00 sec)
 
MariaDB [(none)]> show grants  for zabbix@ 'localhost' ;
+---------------------------------------------------------------------------------------------------------------+
| Grants  for zabbix@localhost                                                                                   |
+---------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO  'zabbix' @ 'localhost' IDENTIFIED BY PASSWORD  '*A35F952D7E492A65F4DB82E1ECBFB4BBBC415BFF' |
| GRANT ALL PRIVILEGES ON `zabbix`.* TO  'zabbix' @ 'localhost' |
+---------------------------------------------------------------------------------------------------------------+
2 rows  in set (0.01 sec)
 
# 测试zabbix用户登录
[root@ZabbixServer-01 ~] # mysql -u zabbix -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection  id is 13
Server version: 5.5.68-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)]> show grants  for current_user();
+---------------------------------------------------------------------------------------------------------------+
| Grants  for zabbix@localhost                                                                                   |
+---------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO  'zabbix' @ 'localhost' IDENTIFIED BY PASSWORD  '*A35F952D7E492A65F4DB82E1ECBFB4BBBC415BFF' |
| GRANT ALL PRIVILEGES ON `zabbix`.* TO  'zabbix' @ 'localhost' |
+---------------------------------------------------------------------------------------------------------------+
2 rows  in set (0.00 sec)
 
# 导入zabbix数据库,zabbix数据库用户为zabbix,密码为zabbix@01
[root@ZabbixServer-01 ~] # zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
 
# 编辑配置文件/etc/zabbix/zabbix_server.conf,设置数据库密码
[root@ZabbixServer-01 ~] # sed -i_bak$(date +%Y%m%d) '/# DBPassword=/a\DBPassword=zabbix@01' /etc/zabbix/zabbix_server.conf
 
# 编辑配置文件/etc/zabbix/zabbix_agentd.conf,设置ZabbixServerIP,Hostname
[root@ZabbixServer-01 ~] # sed -i_bak$(date +%Y%m%d) 's/^Server=127.0.0.1/Server=127.0.0.1,172.16.70.37/' /etc/zabbix/zabbix_agentd.conf
[root@ZabbixServer-01 ~] # sed -i 's/^ServerActive=127.0.0.1/ServerActive=127.0.0.1,172.16.70.37/' /etc/zabbix/zabbix_agentd.conf
[root@ZabbixServer-01 ~] # sed -i 's/^Hostname=Zabbix server/Hostname=ZabbixServer-01/' /etc/zabbix/zabbix_agentd.conf
[root@ZabbixServer-01 ~] # grep -E '^Server|^Hostname' /etc/zabbix/zabbix_agentd.conf
Server=127.0.0.1,172.16.70.37
ServerActive=127.0.0.1,172.16.70.37
Hostname=ZabbixServer-01
 
# 编辑配置文件/etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf,修改时区
[root@ZabbixServer-01 ~] # sed -i_bak$(date +%Y%m%d) '$c php_value[date.timezone] = Asia/Shanghai' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
 
# 重启服务并设置开启自启动
[root@ZabbixServer-01 ~] # systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
[root@ZabbixServer-01 ~] # systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
 
[root@ZabbixServer-01 ~] # netstat -nutpl | grep -E 'zabbix|mysql|php|http'
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      2120 /zabbix_agentd
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      2127 /zabbix_server
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      2118 /php-fpm : maste
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      1991 /mysqld
tcp6       0      0 :::10050                :::*                    LISTEN      2120 /zabbix_agentd
tcp6       0      0 :::10051                :::*                    LISTEN      2127 /zabbix_server
tcp6       0      0 :::80                   :::*                    LISTEN      2117 /httpd
 
[root@ZabbixServer-01 ~] # hostname -I
172.16.70.37
 
浏览器访问 http: //172 .16.70.37 /zabbix

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值