zabbix安装
文章目录
一、部署lamp架构
1.下载centos和epel源
去阿里云镜像网站下载
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliytos-vault-8.5.2111.repo
[root@localhost ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@localhost yum.repos.d]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@localhost yum.repos.d]# ll
total 24
-rw-r--r--. 1 root root 2495 Aug 4 15:04 CentOS-Base.repo
-rw-r--r--. 1 root root 1389 Sep 1 10:50 epel-modular.repo
-rw-r--r--. 1 root root 1326 Sep 1 10:50 epel.repo
-rw-r--r--. 1 root root 1488 Sep 1 10:50 epel-testing-modular.repo
-rw-r--r--. 1 root root 1425 Sep 1 10:50 epel-testing.repo
-rw-r--r--. 1 root root 136 Jul 8 17:07 xx.repo
2.安装httpd
[root@localhost ~]# yum install -y httpd
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
3.安装php
[root@localhost ~]# yum -y install php-xml.x86_64 php-json.x86_64 php-mysqlnd.x86_64 php-common.x86_64 php-fpm.x86_64 php-bcmath.x86_64 php-cli.x86_64 php.x86_64 php-gd.x86_64 php-pdo.x86_64 php-devel.x86_64
3.安装mariadb
[root@localhost ~]# yum install -y mariadb-server mariadb
4.设置数据库服务
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# vim /etc/selinux/config
···
SELINUX=disabled
···
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# systemctl enable mariadb
[root@localhost ~]# 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
New password:
Re-enter new password:
Sorry, passwords do not match.
New password:
Re-enter new password:
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
... 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
- 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!
设置密码为redhat 其余的全部y
启动数据库服务,设置下次启动生效
5.设置httpd服务
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
<IfModule dir_module>
DirectoryIndex index.html index.php (添加index.php)
</IfModule>
[root@localhost ~]# systemctl restart httpd
6.测试php页面
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ll
total 0
[root@localhost html]# vim index.php
[root@localhost html]# cat index.php
<?php
phpinfo();
?>
7.验证
二、部署zabbix监控软件
1.安装zabbix
[root@localhost ~]# vim /etc/yum.repos.d/zabbix.repo
[root@localhost ~]# cat /etc/yum.repos.d/zabbix.repo
[aliyun]
name=aliyun
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/8/x86_64/
enable=1
gpgcheck=0
[qinghua]
name=Zabbix Official Repository - $basearch
#baseurl=http://repo.zabbix.com/zabbix/3.4/rhel/7/$basearch/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.4/rhel/8/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[root@localhost ~]# dnf -y install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-agent
2.配置数据库并导入zabbix表数据
[root@localhost ~]# mysql -uroot -predhat
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 20
Server version: 10.3.28-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.001 sec)
MariaDB [(none)]> grant all on zabbix.* to zabbix@'localhost' identified by 'redhat';(授权)
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
(刷新权限)
[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -u zabbix -predhat zabbix
(在数据库中导入zabbix表的数据)
3.验证zabbix数据库数据
MariaDB [(none)]> use zabbix
Database changed
MariaDB [zabbix]> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
| auditlog_details |
| autoreg_host |
| conditions |
| config |
| config_autoreg_tls |
| corr_condition |
| corr_condition_group |
| corr_condition_tag |
| corr_condition_tagpair |
| corr_condition_tagvalue |
| corr_operation |
| correlation |
| dashboard |
| dashboard_user |
| dashboard_usrgrp |
| dbversion |
| dchecks |
| dhosts |
| drules |
| dservices |
| escalations |
| event_recovery |
| event_suppress |
| event_tag |
| events |
| expressions |
| functions |
| globalmacro |
| globalvars |
| graph_discovery |
| graph_theme |
| graphs |
| graphs_items |
| group_discovery |
| group_prototype |
| history |
| history_log |
| history_str |
| history_text |
| history_uint |
| host_discovery |
| host_inventory |
| host_tag |
| hostmacro |
| hosts |
| hosts_groups |
| hosts_templates |
| housekeeper |
| hstgrp |
| httpstep |
| httpstep_field |
| httpstepitem |
| httptest |
| httptest_field |
| httptestitem |
| icon_map |
| icon_mapping |
| ids |
| images |
| interface |
| interface_discovery |
| item_application_prototype |
| item_condition |
| item_discovery |
| item_preproc |
| item_rtdata |
| items |
| items_applications |
| lld_macro_path |
| maintenance_tag |
| maintenances |
| maintenances_groups |
| maintenances_hosts |
| maintenances_windows |
| mappings |
| media |
| media_type |
| media_type_param |
| opcommand |
| opcommand_grp |
| opcommand_hst |
| opconditions |
| operations |
| opgroup |
| opinventory |
| opmessage |
| opmessage_grp |
| opmessage_usr |
| optemplate |
| problem |
| problem_tag |
| profiles |
| proxy_autoreg_host |
| proxy_dhistory |
| proxy_history |
| regexps |
| rights |
| screen_user |
| screen_usrgrp |
| screens |
| screens_items |
| scripts |
| service_alarms |
| services |
| services_links |
| services_times |
| sessions |
| slides |
| slideshow_user |
| slideshow_usrgrp |
| slideshows |
| sysmap_element_trigger |
| sysmap_element_url |
| sysmap_shape |
| sysmap_url |
| sysmap_user |
| sysmap_usrgrp |
| sysmaps |
| sysmaps_elements |
| sysmaps_link_triggers |
| sysmaps_links |
| tag_filter |
| task |
| task_acknowledge |
| task_check_now |
| task_close_problem |
| task_remote_command |
| task_remote_command_result |
| timeperiods |
| trends |
| trends_uint |
| trigger_depends |
| trigger_discovery |
| trigger_tag |
| triggers |
| users |
| users_groups |
| usrgrp |
| valuemaps |
| widget |
| widget_field |
+----------------------------+
149 rows in set (0.001 sec)
4.配置zabbix并启动服务
[root@localhost ~]# vim
找到下面信息取消注释
/etc/zabbix/zabbix_server.conf
ListenPort=10051
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=redhat (打开注释并修改连接mysql的密码,密码为之前设置的)
DBSocket=/var/lib/mysql/mysql.sock
ListenIP=0.0.0.0
[root@localhost ~]# systemctl restart zabbix-server
[root@localhost ~]# systemctl enable zabbix-server
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-server.service → /usr/lib/systemd/system/zabbix-server.service.
验证查看端口 80端口和10051端口
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl enable httpd
出现时钟问题
解决:
[root@localhost ~]# vim /etc/php.ini
找到下面信息取消分号等号后面写亚洲上海
date.timezone = Asia/Shanghai
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# systemctl restart php-fpm.service
用户名:Admin
密码:zabbix