2018-05-24 Linux学习
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2018-05-24 Linux学习相关的知识,希望对你有一定的参考价值。
19.1 Linux监控平台介绍
常见开源监控软件
cacti、nagios、zabbix、smokeping、open-falcon等等
cacti、smokeping偏向于基础监控,成图非常漂亮
cacti、nagios、zabbix服务端监控中心,需要php环境支持,其中zabbix和cacti都需要mysql作为数据存储,nagios不用存储历史数据,注重服务或者监控项的状态,zabbix会获取服务或者监控项目的数据,会把数据记录到数据库里,从而可以成图
open-falcon为小米公司开发,开源后受到诸多大公司和运维工程师的追捧,适合大企业,滴滴、360、新浪微博、京东等大公司在使用这款监控软件,值得研究
后续以介绍zabbix为主
19.2 zabbix监控介绍
C/S架构,基于C++开发,监控中心支持web界面配置和管理
单server节点可以支持上万台客户端
最新版本3.4,官方文档https://www.zabbix.com/manuals
5个组件
zabbix-server 监控中心,接收客户端上报信息,负责配置、统计、操作数据
数据存储 存放数据,比如mysql
web界面 也叫web UI,在web界面下操作配置是zabbix简单易用的主要原因
zabbix-proxy 可选组件,它可以代替zabbix-server的功能,减轻server的压力
zabbix-agent 客户端软件,负责采集各个监控服务或项目的数据,并上报
19.3-6 安装zabbix
安装zabbix
官网下载地址 www.zabbix.com/download
wget repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
会连带安装httpd和php
如果mysql之前没有安装的话,需要根据lamp那一章的mysql安装方法安装mysql
vim /etc/my.cnf //需要增加配置
character_set_server = utf8
重启mysqld服务后,进入mysql命令行,创建zabbix库
create database zabbix character set utf8;
再创建用户
grant all on zabbix.* to ‘zabbix‘@‘127.0.0.1‘ identified by ‘aming-zabbix‘;
导入数据
cd /usr/share/doc/zabbix-server-mysql-3.2.7
gzip -d create.sql.gz
mysql -uroot -pxxx zabbix < create.sql
systemctl start httpd; systemctl enable httpd
vim /etc/zabbix/zabbix_server.conf //修改或增加
DBHost=127.0.0.1 //在DBName=zabbix上面增加
DBPassword=aming-zabbix //在DBuser下面增加
systemctl start zabbix-server
systemctl enable zabbix-server
netstat -lntp |grep zabbix //查看监听端口
浏览器访问 http://ip/zabbix/ w eb界面下面配置zabbix
用户名Admin 密码zabbix
进入后台第一件事情就是修改密码
忘记Admin密码如何做
进入mysql命令行,选择zabbix库
mysql -uroot -p zabbix
update users set passwd=md5(‘newpasswd’) where alias=‘Admin’;
这样就更改了Admin用户的密码
Zabbix客户端安装
在客户端上也需要下载zabbix的yum源
wget repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
yum install -y zabbix-agent
vim /etc/zabbix/zabbix_agentd.conf //修改如下配置
Server=127.0.0.1 修改为 Server=192.168.133.130 //定义服务端的ip(被动模式)
ServerActive=127.0.0.1 修改为 ServerActive=192.168.133.130 //定义服务端的ip(主动模式)
Hostname=Zabbix server 修改为 Hostname=aming-123 //这是自定义的主机名,一会还需要在web界面下设置同样的主机名
systemctl start zabbix-agent
systemctl enable zabbix-agent
操作过程
linux-01 服务端, linux-02 客户端
服务端安装
[[email protected] ~]# wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
[[email protected] ~]# rpm -ivh zabbix-release-3.4-2.el7.noarch.rpm
[[email protected] ~]# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
启动 MySQL
[[email protected] ~]# systemctl start mysqld
[[email protected] ~]# ps aux|grep mysql
[[email protected] ~]# vim /etc/my.cnf
添加最后一行
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock
server-id=160
log_bin=aminglinux01
character_set_server = utf8
配置 MySQL
[[email protected] ~]# mysql -uroot -paminglinux
mysql> create database zabbix character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on zabbix.* to ‘zabbix‘@‘127.0.0.1‘ identified by ‘aming-zabbix‘;
Query OK, 0 rows affected (0.00 sec)
[[email protected] ~]# cd /usr/share/doc/zabbix-server-mysql-3.4.8/
[[email protected] zabbix-server-mysql-3.4.8]# ls
AUTHORS ChangeLog COPYING create.sql.gz NEWS README
[[email protected] zabbix-server-mysql-3.4.8]# gzip -d create.sql.gz
[[email protected] zabbix-server-mysql-3.4.8]# ls
AUTHORS ChangeLog COPYING create.sql NEWS README
[[email protected] zabbix-server-mysql-3.4.8]# mysql -uroot -paminglinux zabbix < create.sql
Warning: Using a password on the command line interface can be insecure.
启动 zabbix
[[email protected] ~]# systemctl start zabbix-server
Job for zabbix-server.service failed because a configured resource limit was exceeded. See "systemctl status zabbix-server.service" and "journalctl -xe" for details.
[[email protected] ~]# getenforce
Enforcing
[[email protected] ~]# setenforce 0
[r[email protected] ~]# getenforce
Permissive
[[email protected] ~]# systemctl start zabbix-server
[[email protected] ~]# systemctl start httpd
开机启动
[[email protected] ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[[email protected] ~]# systemctl enable zabbix-server
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
zabbix启动但没有监听端口,修改配置
[[email protected] ~]# ps aux |grep zabbix
zabbix 11841 0.0 0.1 259384 3368 ? S 04:00 0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
root 11990 0.0 0.0 112676 980 pts/0 R+ 04:08 0:00 grep --color=auto zabbix
[[email protected] ~]# netstat -lnpt
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:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 1041/rpc.mountd
tcp 0 0 0.0.0.0:39029 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 978/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1323/master
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:48259 0.0.0.0:* LISTEN 980/rpc.statd
tcp6 0 0 :::3306 :::* LISTEN 11706/mysqld
tcp6 0 0 :::41514 :::* LISTEN -
tcp6 0 0 :::43981 :::* LISTEN 980/rpc.statd
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::80 :::* LISTEN 11888/httpd
tcp6 0 0 :::20048 :::* LISTEN 1041/rpc.mountd
tcp6 0 0 :::22 :::* LISTEN 978/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1323/master
tcp6 0 0 :::2049 :::* LISTEN -
[[email protected] ~]# vim /etc/zabbix/zabbix_server.conf
添加以下 第2第4行
DBHost=localhost
DBHost=127.0.0.1
DBUser=zabbix
DBPassword=aming-zabbix
[[email protected] ~]# netstat -lnpt
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:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 1041/rpc.mountd
tcp 0 0 0.0.0.0:39029 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 978/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1323/master
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 12062/zabbix_server
tcp 0 0 0.0.0.0:48259 0.0.0.0:* LISTEN 980/rpc.statd
tcp6 0 0 :::3306 :::* LISTEN 11706/mysqld
tcp6 0 0 :::41514 :::* LISTEN -
tcp6 0 0 :::43981 :::* LISTEN 980/rpc.statd
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::80 :::* LISTEN 11888/httpd
tcp6 0 0 :::20048 :::* LISTEN 1041/rpc.mountd
tcp6 0 0 :::22 :::* LISTEN 978/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1323/master
tcp6 0 0 :::2049 :::* LISTEN -
tcp6 0 0 :::10051 :::* LISTEN 12062/zabbix_server
[[email protected] ~]# ps aux |grep zabbix
zabbix 12062 0.5 0.2 259488 4200 ? S 04:17 0:00 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
zabbix 12065 0.0 0.1 259488 2528 ? S 04:17 0:00 /usr/sbin/zabbix_server: configuration syncer [waiting 60 sec for processes]
zabbix 12066 0.0 0.1 259488 2532 ? S 04:17 0:00 /usr/sbin/zabbix_server: alerter #1 started
zabbix 12067 0.0 0.1 259488 2532 ? S 04:17 0:00 /usr/sbin/zabbix_server: alerter #2 started
zabbix 12068 0.0 0.1 259488 2532 ? S 04:17 0:00 /usr/sbin/zabbix_server: alerter #3 started
zabbix 12069 0.0 0.1 259488 2528 ? S 04:17 0:00 /usr/sbin/zabbix_server: housekeeper [startup idle for 30 minutes]
zabbix 12070 0.0 0.1 259560 2984 ? S 04:17 0:00 /usr/sbin/zabbix_server: timer #1 [processed 0 triggers, 0 events in 0.000090 sec, 0 maintenances in 0.000000 sec, idle 30 sec]
zabbix 12071 0.0 0.1 259488 2908 ? S 04:17 0:00 /usr/sbin/zabbix_server: http poller #1 [got 0 values in 0.000733 sec, idle 5 sec]
zabbix 12072 0.1 0.2 363848 5096 ? S 04:17 0:00 /usr/sbin/zabbix_server: discoverer #1 [processed 0 rules in 0.001027 sec, idle 60 sec]
zabbix 12073 0.0 0.1 259488 2884 ? S 04:17 0:00 /usr/sbin/zabbix_server: history syncer #1 [synced 0 items in 0.000001 sec, idle 1 sec]
zabbix 12074 0.0 0.1 259488 2884 ? S 04:17 0:00 /usr/sbin/zabbix_server: history syncer #2 [synced 0 items in 0.000001 sec, idle 1 sec]
zabbix 12075 0.0 0.1 259488 2884 ? S 04:17 0:00 /usr/sbin/zabbix_server: history syncer #3 [synced 0 items in 0.000001 sec, idle 1 sec]
zabbix 12076 0.0 0.1 259488 2884 ? S 04:17 0:00 /usr/sbin/zabbix_server: history syncer #4 [synced 0 items in 0.000001 sec, idle 1 sec]
zabbix 12081 0.0 0.2 259488 3848 ? S 04:17 0:00 /usr/sbin/zabbix_server: escalator #1 [processed 0 escalations in 0.000989 sec, idle 3 sec]
zabbix 12082 0.0 0.2 259488 3840 ? S 04:17 0:00 /usr/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000003 sec, idle 5 sec]
zabbix 12083 0.0 0.1 259488 2652 ? S 04:17 0:00 /usr/sbin/zabbix_server: self-monitoring [processed data in 0.000007 sec, idle 1 sec]
zabbix 12084 0.0 0.1 259488 2888 ? S 04:17 0:00 /usr/sbin/zabbix_server: task manager [processed 0 task(s) in 0.000685 sec, idle 5 sec]
zabbix 12085 0.1 0.2 366460 5268 ? S 04:17 0:00 /usr/sbin/zabbix_server: poller #1 [got 0 values in 0.000004 sec, idle 5 sec]
zabbix 12089 0.1 0.2 366460 5268 ? S 04:17 0:00 /usr/sbin/zabbix_server: poller #2 [got 0 values in 0.000004 sec, idle 5 sec]
zabbix 12090 0.1 0.2 366460 5268 ? S 04:17 0:00 /usr/sbin/zabbix_server: poller #3 [got 0 values in 0.000006 sec, idle 5 sec]
zabbix 12091 0.1 0.2 366460 5268 ? S 04:17 0:00 /usr/sbin/zabbix_server: poller #4 [got 0 values in 0.000004 sec, idle 5 sec]
zabbix 12092 0.1 0.2 366460 5268 ? S 04:17 0:00 /usr/sbin/zabbix_server: poller #5 [got 0 values in 0.000005 sec, idle 5 sec]
zabbix 12093 0.1 0.2 366460 5268 ? S 04:17 0:00 /usr/sbin/zabbix_server: unreachable poller #1 [got 0 values in 0.000005 sec, idle 5 sec]
zabbix 12094 0.0 0.1 259488 3620 ? S 04:17 0:00 /usr/sbin/zabbix_server: trapper #1 [processed data in 0.000000 sec, waiting for connection]
zabbix 12095 0.0 0.1 259488 3620 ? S 04:17 0:00 /usr/sbin/zabbix_server: trapper #2 [processed data in 0.000000 sec, waiting for connection]
zabbix 12096 0.0 0.1 259488 3620 ? S 04:17 0:00 /usr/sbin/zabbix_server: trapper #3 [processed data in 0.000000 sec, waiting for connection]
zabbix 12100 0.0 0.1 259488 3620 ? S 04:17 0:00 /usr/sbin/zabbix_server: trapper #4 [processed data in 0.000000 sec, waiting for connection]
zabbix 12101 0.0 0.1 259488 3620 ? S 04:17 0:00 /usr/sbin/zabbix_server: trapper #5 [processed data in 0.000000 sec, waiting for connection]
zabbix 12102 0.0 0.1 262092 2688 ? S 04:17 0:00 /usr/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000005 sec, idle 5 sec]
zabbix 12105 0.0 0.1 259488 3268 ? S 04:17 0:00 /usr/sbin/zabbix_server: alert manager #1 [sent 0, failed 0 alerts, idle 5.013129 sec during 5.013131 sec]
zabbix 12106 0.0 0.1 259488 3024 ? S 04:17 0:00 /usr/sbin/zabbix_server: preprocessing manager #1 [queued 0, processed 0 values, idle 5.006026 sec during 5.006029 sec]
zabbix 12108 0.0 0.1 259488 2580 ? S 04:17 0:00 /usr/sbin/zabbix_server: preprocessing worker #1 started
zabbix 12109 0.0 0.1 259488 2580 ? S 04:17 0:00 /usr/sbin/zabbix_server: preprocessing worker #2 started
zabbix 12110 0.0 0.1 259488 2580 ? S 04:17 0:00 /usr/sbin/zabbix_server: preprocessing worker #3 started
root 12120 0.0 0.0 112676 976 pts/0 R+ 04:17 0:00 grep --color=auto zabbix
web配置zabbix
[[email protected] ~]# systemctl stop firewalld
在浏览器中打开 http://192.168.106.160/zabbix 设置zabbix
[[email protected] ~]# vim /etc/php.ini
date.timezone = Asia/Shanghai
[[email protected] ~]# systemctl restart httpd
界面 Configure DB connection
Database host:127.0.0.1
Database port:0
Database name:zabbix
User:zabbix
Password:aming-zabbix
界面 Zabbix server details 随意设置名字
Name : linux-01
登陆界面 默认
用户名:Admin
秘密: zabbix
Administration---Users---Admin,进去后修改密码和语言(aminglinux)---update---Apply
忘记Admin密码如何做
[[email protected] ~]# mysql -uroot -paminglinux
mysql> use zabbix;
mysql> show tables;
mysql> desc users;
mysql> update users set passwd=md5(‘aming‘) where alias=‘Admin‘;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from users;
使用新密码登陆zabbix
客户端安装
[[email protected] ~]# wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
[[email protected] ~]# rpm -ivh zabbix-release-3.4-2.el7.noarch.rpm
[[email protected] ~]# yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql
[[email protected] ~]# vim /etc/zabbix/zabbix_agentd.conf
设置服务端IP
Server=192.168.106.160
ServerActive=192.168.106.160
Hostname=linux-02
客户端启动
[[email protected] ~]# systemctl start zabbix-agent
[[email protected] ~]# ps aux|grep zabbix
zabbix 1392 0.0 0.0 82740 1264 ? S 22:47 0:00 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
zabbix 1393 0.0 0.0 82740 1296 ? S 22:47 0:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix 1394 0.0 0.0 82740 1852 ? S 22:47 0:00 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix 1395 0.0 0.0 82740 1852 ? S 22:47 0:00 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix 1396 0.0 0.0 82740 1852 ? S 22:47 0:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix 1397 0.0 0.1 82872 2200 ? S 22:47 0:00 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root 1400 0.0 0.0 112676 984 pts/0 R+ 22:47 0:00 grep --color=auto zabbix
[[email protected] ~]# netstat -lnpt
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:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 937/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1179/master
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 1392/zabbix_agentd
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::22 :::* LISTEN 937/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1179/master
tcp6 0 0 :::10050 :::* LISTEN 1392/zabbix_agentd
以上是关于2018-05-24 Linux学习的主要内容,如果未能解决你的问题,请参考以下文章