Zabbix监控部署、Yum源配置、vsftpd、LAMP

tech2024-09-30  19

基础环境准备

(1)IP地址配置 安装最小化CentOS 7.2-1511操作系统,配置两个节点的主机名与IP地址,并使用远程终端工具进行连接,示例代码如下: Zabbix-server节点修改IP:

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eno16777736 TYPE=Ethernet BOOTPROTO=static DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=eno16777736 UUID=6599ef4f-5b4d-4215-bdae-7048b00510ba DEVICE=eno16777736 ONBOOT=yes IPADDR=192.168.20.10 PREFIX=24

Zabbix-agent节点修改IP:

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eno16777736 TYPE=Ethernet BOOTPROTO=static DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=eno16777736 UUID=6599ef4f-5b4d-4215-bdae-7048b00510ba DEVICE=eno16777736 ONBOOT=yes IPADDR=192.168.20.20 PREFIX=24

修改完两个节点的IP地址后,使用远程工具连接虚拟机。 (2)配置主机名 节点配置主机名:

[root@localhost ~]# hostnamectl set-hostname zabbix-server //退出并重新连接虚拟机 [root@user1 ~]# hostnamectl Static hostname: zabbix-server Icon name: computer-vm Chassis: vm Machine ID: 17d24d21f1c34b699c19d5e84762b3fe Boot ID: 6ea800f863564e11afc5d91d65fafb3f Virtualization: vmware Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-327.el7.x86_64 [root@localhost ~]# hostnamectl set-hostname zabbix-agent //退出并重新连接虚拟机 [root@user2 ~]# hostnamectl Static hostname: zabbix-agent Icon name: computer-vm Chassis: vm Machine ID: 17d24d21f1c34b699c19d5e84762b3fe Boot ID: d6c808d94d6b4501b5ad740429e23aa4 Virtualization: vmware Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-327.el7.x86_64 Architecture: x86-64

(3)Yum源配置 将提供的CentOS-7-x86_64-DVD-1511.iso镜像和zabbix文件夹上传至zabbix-server节点的/opt目录下。 在zabbix-server节点创建挂载目录:

[root@zabbix-server ~]# mkdir -p /opt/centos

将CentOS-7-x86_64-DVD-1511.iso挂载到/opt/centos目录:

[root@zabbix-server opt]# mount CentOS-7-x86_64-DVD-1511.iso centos/ mount: /dev/loop0 is write-protected, mounting read-only

挂载好iso文件后,将/etc/yum.repo.d目录下的所有文件移动到/media下。

[root@zabbix-server ~]# mv /etc/yum.repos.d/* /media/

在/etc/yum.repo.d目录下创建local.repo文件,文件内容如下:

[root@zabbix-server ~]# cat /etc/yum.repos.d/local.repo [centos] name=centos baseurl=file:///opt/centos gpgcheck=0 enabled=1 [zabbix] name=zabbix baseurl=file:///opt/zabbix gpgcheck=0 enabled=1

接下来配置zabbix-agent节点的YUM源。首先在zabbix-server节点上安装vsftpd服务。

[root@zabbix-server ~]# yum install vsftpd -y

修改vsftpd服务的配置文件vsftpd.conf,在配置文件的最上面,添加一行代码,命令如下:

[root@zabbix-server ~]# vi /etc/vsftpd/vsftpd.conf anon_root=/opt # Example config file /etc/vsftpd/vsftpd.conf # # The default compiled in settings are fairly paranoid. This sample file

保存修改并退出,启动vsftpd服务,命令如下:

[root@zabbix-server ~]# systemctl start vsftpd [root@zabbix-server ~]# systemctl status vsftpd vsftpd.service - Vsftpd ftp daemon Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled) Active: active (running) since Fri 2019-10-04 19:04:54 UTC; 5s ago Process: 10014 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS) Main PID: 10015 (vsftpd) CGroup: /system.slice/vsftpd.service └─10015 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf Oct 04 19:04:54 zabbix-server systemd[1]: Started Vsftpd ftp daemon.

到zabbix-agent节点上,首先将/etc/yum.repo.d目录下的所有文件移动到/media目录下,然后创建local.repo文件,文件内容如下所示:

[root@zabbix-agent ~]# mv /etc/yum.repos.d/* /media/ [root@zabbix-agent ~]# vi /etc/yum.repos.d/local.repo [centos] name=centos baseurl=ftp://192.168.20.10/centos gpgcheck=0 enabled=1 [zabbix] name=zabbix baseurl=ftp://192.168.20.10/zabbix gpgcheck=0 enabled=1

至此,2个节点的Yum源全部配置完毕。 (4)安装LAMP+Zabbix服务(在zabbix-server节点执行) 安装httpd服务,命令如下:

[root@zabbix-server ~]# yum install httpd -y

安装数据库服务,命令如下:

[root@zabbix-server ~]# yum install -y mariadb-server mariadb

安装Zabbix服务,命令如下:

[root@zabbix-server ~]# yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent mariadb-server

升级trousers服务,命令如下:

[root@zabbix-server ~]# yum install trousers -y

zabbix分布式监控系统部署

(1)启动httpd服务 使用命令启动httpd服务,并设置开机自启,最后查看运行状态。命令如下:

[root@zabbix-server ~]# systemctl start httpd [root@zabbix-server ~]# systemctl enable httpd ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service' [root@zabbix-server ~]# systemctl status httpd httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled) Active: active (running) since Fri 2019-10-04 19:34:32 UTC; 27s ago Docs: man:httpd(8) man:apachectl(8) Main PID: 10215 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─10215 /usr/sbin/httpd -DFOREGROUND ├─10217 /usr/sbin/httpd -DFOREGROUND ├─10218 /usr/sbin/httpd -DFOREGROUND ├─10219 /usr/sbin/httpd -DFOREGROUND ├─10220 /usr/sbin/httpd -DFOREGROUND └─10221 /usr/sbin/httpd -DFOREGROUND Oct 04 19:34:31 zabbix-server systemd[1]: Starting The Apache HTTP Server... Oct 04 19:34:32 zabbix-server httpd[10215]: AH00557: httpd: apr_sockaddr_info_get() fa...er Oct 04 19:34:32 zabbix-server httpd[10215]: AH00558: httpd: Could not reliably determi...ge Oct 04 19:34:32 zabbix-server systemd[1]: Started The Apache HTTP Server. Hint: Some lines were ellipsized, use -l to show in full.

(2)启动并配置数据库服务 启动数据库服务,并设置开机自启,命令如下:

[root@zabbix-server ~]# systemctl start mariadb [root@zabbix-server ~]# systemctl enable mariadb ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'

登录数据库,创建zabbix库(中文编码格式),命令如下:

[root@zabbix-server ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.44-MariaDB MariaDB Server Copyright (c) 2000, 2015, 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)

授予zabbix用户的访问权限,命令如下:

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

退出数据库,进入到/usr/share/doc/zabbix-server-mysql-3.4.15/目录,导入数据库文件,命令如下:

MariaDB [(none)]> Ctrl-C -- exit! Aborted [root@zabbix-server ~]# cd /usr/share/doc/zabbix-server-mysql-3.4.15/ [root@zabbix-server zabbix-server-mysql-3.4.15]# ll total 2120 -rw-r--r-- 1 root root 98 Nov 12 2018 AUTHORS -rw-r--r-- 1 root root 866545 Nov 12 2018 ChangeLog -rw-r--r-- 1 root root 17990 Nov 12 2018 COPYING -rw-r--r-- 1 root root 1267039 Nov 12 2018 create.sql.gz -rw-r--r-- 1 root root 52 Nov 12 2018 NEWS -rw-r--r-- 1 root root 1062 Nov 12 2018 README [root@zabbix-server zabbix-server-mysql-3.4.15]# zcat create.sql.gz |mysql -uroot zabbix

至此,数据库配置完毕。 (3)设置时区 编辑/etc/php.ini文件,设置时区,在[Date]字段下,设置date.timezone=PRC,命令如下:

[root@zabbix-server ~]# vi /etc/php.ini [Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = PRC

编辑/etc/httpd/conf.d/zabbix.conf文件,修改时区,修改php_value date.timezone 为Asia/Shanghai,命令如下:

[root@zabbix-server ~]# vi /etc/httpd/conf.d/zabbix.conf <IfModule mod_php5.c> php_value max_execution_time 300 php_value memory_limit 128M php_value post_max_size 16M php_value upload_max_filesize 2M php_value max_input_time 300 php_value max_input_vars 10000 php_value always_populate_raw_post_data -1 # php_value date.timezone Europe/Riga php_value date.timezone Asia/Shanghai </IfModule>

修改完配置文件后重启httpd服务,命令如下:

[root@zabbix-server ~]# systemctl restart httpd

(4)修改Zabbix配置文件并启动 修改/etc/zabbix/zabbix_server.conf配置文件,修改完的配置文件如下所示:

[root@zabbix-server ~]# vi /etc/zabbix/zabbix_server.conf [root@zabbix-server ~]# grep -n '^'[a:-Z] /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 91:DBHost=localhost 100:DBName=zabbix 116:DBUser=zabbix 124:DBPassword=zabbix 132:DBSocket=/var/lib/mysql/mysql.sock 330:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log 447:Timeout=4 489:AlertScriptsPath=/usr/lib/zabbix/alertscripts 499:ExternalScripts=/usr/lib/zabbix/externalscripts 535:LogSlowQueries=3000

2.启动Zabbix服务

[root@zabbix-server ~]# systemctl start zabbix-server

查看端口号,验证zabbix-server的服务端口10051是否存在,命令如下:

[root@zabbix-server ~]# netstat -ntpl Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 10611/zabbix_server tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 10510/mysqld tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 975/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 886/master tcp6 0 0 :::10051 :::* LISTEN 10611/zabbix_server tcp6 0 0 :::80 :::* LISTEN 10579/httpd tcp6 0 0 :::21 :::* LISTEN 10015/vsftpd tcp6 0 0 :::22 :::* LISTEN 975/sshd tcp6 0 0 ::1:25 :::* LISTEN 886/master

至此,Zabbix监控服务的server端配置完毕,接下来需要在Web界面操作。

最新回复(0)