(一) Prometheus 监控思科交换机---各中间件安装部署

Prometheus 监控思科交换机

由于领导比较青睐 Prometheus 开源监控,由于鄙人自身也是网络专业出身,因此便但愿能用 prometheus 监控公司的交换机,公司大量的交换机在业务区,比较繁杂,虽然平常监控均可以用 Solarwinds 和 Opmanager 进行平常网络行为监控管理,可是 Solarwinds 界面比较比较有上古世纪的感受,Opmanager 又比较卡,对服务器硬件配置稍微高了点,并且没有比开源 Prometheus 的更方便管理、进行修改配置等操做。何况如今 prometheus 有较多的公司正在使用,可搜集的资料较多,但相对来讲,监控交换机的这方面, snmp_exporter 的发展就相对较为缓慢一点,不过相信咱们愈来愈多的人使用,终究会更加完善。html

Prometheus 监控思科交换机文档完整地址:https://blog.51cto.com/liujingyu/category9.htmlnode

Prometheus + snmp_exporter + Alertmanager + Grafana 安装部署

  • 各程序说明linux

    • Prometheus:用于作主监控端,收集 snmp_exporter 数据信息
    • snmp_exporter:用于监控交换机设备,收集交换机数据信息
    • Alertmanager: 用于作报警端,当交换机挂掉或者CPU信息或者内存占用太高进行报警(邮件报警),也能够对接口流量阈值进行报警
    • Grafana: 把 Prometheus 收集的数据进行比较友好的界面展现
  • 使用版本git

    • CentOS 7.8-2003-Minimal(4核 8G 100G)
    • prometheus 版本 2.21.0 监听 9090 端口
    • alertmanager 版本 0.21.0 监听 9093, 9094 端口
    • snmp_exporter 版本 0.19.0 监听 9116 端口,SNMP 是 UDP 协议 161 和 162 端口,因此不建议 docker 部署
    • Grafana 版本 7.2.0(docker部署) 监听 3000 端口
  • 官网地址:github

1.系统安装后初始步骤(优化服务器):

yum install wget yum-utils net-tools vim unzip bash-completion -y

yum update -y

ulimit -n
sed -i "s/* soft nofile 65535/ /g" /etc/security/limits.conf
sed -i "s/* hard nofile 65535/ /g" /etc/security/limits.conf
echo "* soft nofile 65535" >>/etc/security/limits.conf
echo "* hard nofile 65535" >>/etc/security/limits.conf
ulimit -n 65535
echo "修改后文件数量"
ulimit -n

echo "优化内核参数"
echo "net.ipv4.ip_local_port_range = 1024 65535" >>/etc/sysctl.conf
echo "net.ipv4.tcp_syncookies = 1" >>/etc/sysctl.conf
echo "net.ipv4.tcp_tw_reuse = 1" >>/etc/sysctl.conf
echo "net.ipv4.tcp_tw_recycle = 1" >>/etc/sysctl.conf
echo "net.ipv4.tcp_fin_timeout = 30" >>/etc/sysctl.conf
echo "net.core.somaxconn = 20480" >>/etc/sysctl.conf
echo "net.core.netdev_max_backlog = 20480" >>/etc/sysctl.conf
echo "net.ipv4.tcp_max_syn_backlog = 20480" >>/etc/sysctl.conf
echo "net.ipv4.tcp_max_tw_buckets = 800000" >>/etc/sysctl.conf

sysctl -p

sed -i 's/=enforcing/=disabled/g' /etc/selinux/config
setenforce 0
systemctl disabled firewalld
systemctl stop firewalld

2.下载所须要的安装包

wget https://github.com/prometheus/prometheus/releases/download/v2.21.0/prometheus-2.21.0.linux-amd64.tar.gz

wget https://github.com/prometheus/snmp_exporter/releases/download/v0.19.0/snmp_exporter-0.19.0.linux-amd64.tar.gz

wget https://github.com/prometheus/alertmanager/releases/download/v0.21.0/alertmanager-0.21.0.linux-amd64.tar.gz

tar -xvf prometheus-2.21.0.linux-amd64.tar.gz
mv prometheus-2.21.0.linux-amd64 /opt/prometheus

tar -xf snmp_exporter-0.19.0.linux-amd64.tar.gz
mv snmp_exporter-0.19.0.linux-amd64 /opt/snmp_exporter

tar -xf alertmanager-0.21.0.linux-amd64.tar.gz
mv alertmanager-0.21.0.linux-amd64 /opt/alertmanager

cat > /etc/systemd/system/prometheus.service <<EOF
[Unit]
Description=Prometheus
After=network.target
[Service]
ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml --storage.tsdb.path=/opt/prometheus/data
User=prometheus
[Install]
WantedBy=multi-user.target
EOF

cat > /etc/systemd/system/snmp_exporter.service <<EOF
[Unit]
Description=node_exporter
After=network.target

[Service]
ExecStart=/opt/snmp_exporter/snmp_exporter --config.file=/opt/snmp_exporter/snmp.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

cat > /etc/systemd/system/snmp_exporter.service <<EOF
[Unit]
Description=node_exporter
After=network.target

[Service]
ExecStart=/opt/alertmanager/alertmanager --config.file=/opt/alertmanager/alertmanager.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

useradd prometheus
chown -R prometheus:prometheus /opt/{snmp_exporter,prometheus,alertmanager}

systemctl daemon-reload
systemctl enable prometheus && systemctl enable snmp_exporter && systemctl enable alertmanager
systemctl start prometheus && systemctl start snmp_exporter && systemctl start alertmanager

3.安装Grafana

wget -P /etc/yum.repos.d/ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce
systemctl enable docker && systemctl start docker 

docker login --username=LOGIN_NAME registry.cn-beijing.aliyuncs.com #登陆阿里云仓库

docker pull registry.cn-beijing.aliyuncs.com/liujingyu/grafana-chinese:7.2.0
docker image ls
docker tag registry.cn-beijing.aliyuncs.com/liujingyu/grafana-chinese:7.2.0 grafana-chinese:7.2.0

docker run -tdi --name grafana-server --restart=always -p 3000:3000 grafana-chinese:7.2.0

具体配置调整请查看后续文章shell