基于keepalived的高可用高性能的web集群

目录

 步骤
1.集群IP地址规划

2.使用Nginx做负载均衡

3.创建NFS服务为所有的web服务器提供相同的web数据

4.搭建dns服务器

5.keepalived实现双VIP负载均衡高可用

6.使用Prometheus对Web集群进行监控,结合Grafana进行数据展示


项目环境:CentOS7(7.9.2009,5台,2核4G),keepalived (1.3.5),Prometheus(2.45.0),Grafana(10.0.0),Nginx(1.23.4)等

项目描述:本项目是构建一个基于keepalived的高可用高性能的web集群项目。使用nginx做负载均衡,nfs服务保证数据的一致性,keepalived双vip架构实现HA,Prometheus+Grafana实现对Web服务器的监控。

项目步骤:
1.规划整个项目的拓扑结构和项目的思维导图

2.构建2个真正提供web服务的后端服务器(real server),使用脚本安装部署nginx软件,实现web服务功能,开启状态统计模块、负载均衡模块和http模块等。

3.搭建内部DNS服务器,进行域名解析

4.搭建NFS服务器为所有节点提供相同的Web数据,解决Web集群里的数据一致性问题

5.使用两台机器做Nginx+Keepalived双vip的负载均衡器,实现高可用防止单点故障

6.使用ab软件对整个Web集群进行压力测试,了解整个集群的并发连接数

7.搭建基于Prometheus+Grafana的监控系统,对整个Web集群里的机器进行进程监控

网络拓扑图

 步骤
1.集群IP地址规划

test:192.168.23.1                             测试服务器

web1:192.168.23.139                     nginx-web1服务器 

web2:192.168.23.132                     nginx-web2服务器

nfs-server:192.168.23.142                nfs服务器

load-balance1:192.168.23.145       nginx负载均衡服务器(master)

load-balance2:192.168.23.146       nginx负载均衡服务器(backup)

prometheus:192.168.23.132          prometheus监控服务器

dns:192.168.23.145                        dns服务器

2.使用Nginx做负载均衡

        1.以load-balance1为例,部署安装nginx脚本,并执行脚本
 

[root@load-balance1 nginx]# vim onekey_install_nginx.sh 
[root@load-balance1 nginx]# cat onekey_install_nginx.sh 
#!/bin/bash

#新建一个文件夹用来存放下载的nginx源码包
mkdir -p /yy_nginx
cd /yy_nginx

#新建用户
useradd -s /sbin/nologin yangyuan

#下载nginx
curl -O http://nginx.org/download/nginx-1.23.4.tar.gz

#解压nginx源码包
tar xf nginx-1.23.4.tar.gz

#解决依赖关系
yum install gcc openssl openssl-devel pcre pcre-devel automake make -y

cd nginx-1.23.4
#编译前的配置
./configure --prefix=/usr/local/yy99 --user=yangyuan --with-http_ssl_module --with-http_v2_module --with-threads --with-http_stub_status_module --with-stream
#如果上面的编译前的配置失败,就直接退出脚本
if (( $? != 0 ));then
	exit
fi
#编译,开启2个进程同时编译,速度会快一些
make -j 2

#编译安装
make install

#启动nginx
/usr/local/yy99/sbin/nginx
#修改PATH变量
PATH=$PATH:/usr/local/yy99/sbin
echo "PATH=$PATH:/usr/local/yy99/sbin" >>/root/.bashrc

#设置nginx的开机启动
echo "/usr/local/yy99/sbin/nginx"  >>/etc/rc.local
chmod +x /etc/rc.d/rc.local
#selinux和firewalld防火墙都关闭
service firewalld stop
systemctl disable firewalld

#临时关闭selinux
setenforce 0
#永久关闭selinux
sed -i '/^SELINUX=/ s/enforcing/disabled/' /etc/selinux/config

#修改nginx.conf的配置,将worker进程数改为2,线程数改为2048
sed -i '/worker_processes/ s/1/2/' /usr/local/yy99/conf/nginx.conf
sed -i '/worker_connections/ s/1024/2048/' /usr/local/yy99/conf/nginx.conf
[root@load-balance1 nginx]# 

2.配置nginx的负载均衡

[root@load-balance1 yy99]# cd conf/
[root@load-balance1 conf]# ls
10269265_yangyuan.shop.key        fastcgi_params.default  nginx.conf.default
10269265_yangyuan.shop_nginx.zip  koi-utf                 scgi_params
10269265_yangyuan.shop.pem        koi-win                 scgi_params.default
fastcgi.conf                      mime.types              uwsgi_params
fastcgi.conf.default              mime.types.default      uwsgi_params.default
fastcgi_params                    nginx.conf              win-utf
[root@load-balance1 conf]# vim nginx.conf
[root@load-balance1 conf]# cat nginx.conf  #一下仅显示修改了的脚本部分
http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    #定义一个负载均衡器的名字为:web_servers
    upstream web_servers{
	server 192.168.23.139;
	server 192.168.23.132;
    }


    server {
	listen 80;
	server_name www.yangyuan.shop; #设置域名为www.yangyuan.shop
	location /{
		proxy_pass http://web_servers;
		proxy_set_header X-Real-IP $remote_addr; #调用负载均衡器
	}
    }

    #在负载均衡器上配置证书,后端就可以不用配置了
        server {
        listen       443 ssl;
        server_name  localhost;

        ssl_certificate      10269265_yangyuan.shop.pem;
        ssl_certificate_key  10269265_yangyuan.shop.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
                 #root   html;
                 proxy_pass http://web_servers;
                 proxy_set_header X-Real-IP $remote_addr;
                 #index  index.html index.htm;
            }
        }
}

3.创建NFS服务为所有的web服务器提供相同的web数据

        1.安装启动nfs服务

[root@nfs-server ~]# yum install nfs-utils -y
[root@nfs-server ~]# service nfs restart
Redirecting to /bin/systemctl restart nfs.service
[root@nfs-server ~]# 

        2.编辑共享文件的配置文件
        共享/web出去,允许192.168.23.0/24网段的机器能过来访问,只有只读的权限

[root@nfs-server ~]# vim /etc/exports
[root@nfs-server ~]# cat /etc/exports
/web 192.168.23.0/24(ro,all_squash,sync)
[root@nfs-server ~]# 

        3.刷新输出文件目录

[root@nfs-server web]# exportfs -rv
exporting 192.168.23.0/24:/web

        4.关闭防火墙,防止其他机器不能访问过来

[root@nfs-server web]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service
[root@nfs-server web]# 

        5.在客户机上安装nfs服务并挂载nfs服务器的共享目录

[root@web1 html]# yum install nfs-utils -y
[root@web1 html]# mount 192.168.23.142:/web /usr/local/yy99/html/
[root@web1 html]# cd /usr/local/yy99/html/
[root@web1 html]# ls
index.html
[root@web1 html]# 

        6.开机自动挂载nfs文件系统

#在客户机上查看192.168.23.142机器共享了哪些目录
[root@web1 html]# showmount -e 192.168.23.142 
Export list for 192.168.23.142:
/web 192.168.23.0/24
[root@web1 html]# 
#修改/etc/fstab文件,实现自动挂载
[root@web1 html]# vim index.html 
[root@web1 html]# showmount -e 192.168.23.142 
Export list for 192.168.23.142:
/web 192.168.23.0/24
[root@web1 html]# vim /etc/fstab
[root@web1 html]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue May 16 16:28:35 2023
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=249126df-7c39-4712-97f1-3eae3c4869ed /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
192.168.23.142:/web  /usr/local/yy99/html nfs defaults 0 0 
[root@web1 html]# 

4.搭建dns服务器

         1.安装bind软件


[root@load-balance1 ~]# which nslookup
/usr/bin/nslookup
[root@load-balance1 ~]# rpm -qf /usr/bin/nslookup   #查询/usr/bin/nslookuo是通过那个软件包安装过来的
bind-utils-9.11.4-26.P2.el7_9.13.x86_64
[root@load-balance1 ~]# which dig
/usr/bin/dig
[root@load-balance1 ~]# rpm -qf /usr/bin/dig
bind-utils-9.11.4-26.P2.el7_9.13.x86_64
[root@load-balance1 ~]# yum install bind* -y

        2.设置named服务开机启动,并且立马启动DNS服务

[root@load-balance1 ~]# service named start
Redirecting to /bin/systemctl start named.service
[root@load-balance1 ~]# systemctl enable named
Created symlink from /etc/systemd/system/multi-user.target.wants/named.service to /usr/lib/systemd/system/named.service.
[root@load-balance1 ~]# systemctl start named     #立马启动named进程
[root@load-balance1 ~]# ps aux|grep named
named      1076  0.0 10.1 693528 100588 ?       Ssl  6月17   0:04 /usr/sbin/named -u named -c /etc/named.conf
root      23083  0.0  0.0 112828   980 pts/1    S+   17:50   0:00 grep --color=auto named
[root@load-balance1 ~]# netstat -anplut|grep named
tcp        0      0 192.168.23.145:53       0.0.0.0:*               LISTEN      1076/named          
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      1076/named          
tcp        0      0 127.0.0.1:953           0.0.0.0:*               LISTEN      1076/named          
tcp6       0      0 :::53                   :::*                    LISTEN      1076/named          
tcp6       0      0 ::1:953                 :::*                    LISTEN      1076/named          
udp        0      0 192.168.23.145:53       0.0.0.0:*                           1076/named          
udp        0      0 127.0.0.1:53            0.0.0.0:*                           1076/named          
udp6       0      0 :::53                   :::*                                1076/named          
[root@load-balance1 ~]# vim /etc/resolv.conf  #修改本机的文件,增加我们自己的dns服务器地址
[root@load-balance1 ~]# cat /etc/resolv.conf 
# Generated by NetworkManager
#nameserver 114.114.114.114
nameserver 127.0.0.1
[root@load-balance1 ~]# 

        3.修改配置文件,重启服务器允许其他电脑能过来查询dns域名

[root@load-balance1 ~]# vim /etc/named.conf
[root@load-balance1 ~]# cat /etc/named.conf
options { 
	listen-on port 53 { any; };     修改
	listen-on-v6 port 53 { any; };     修改
	directory 	"/var/named";
	dump-file 	"/var/named/data/cache_dump.db";
	statistics-file "/var/named/data/named_stats.txt";
	memstatistics-file "/var/named/data/named_mem_stats.txt";
	recursing-file  "/var/named/data/named.recursing";
	secroots-file   "/var/named/data/named.secroots";
	allow-query     { any; };     修改
[root@load-balance1 ~]# service named restart  重启named服务
Redirecting to /bin/systemctl restart named.service
[root@load-balance1 ~]# ps aux|grep named
named     23128  0.7  6.7 494580 67456 ?        Ssl  17:57   0:00 /usr/sbin/named -u named -c /etc/named.conf
root      23140  0.0  0.0 112824   976 pts/1    S+   17:58   0:00 grep --color=auto named
[root@load-balance1 ~]# netstat -anplut|grep named
tcp        0      0 192.168.23.145:53       0.0.0.0:*               LISTEN      23128/named         
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      23128/named         
tcp        0      0 127.0.0.1:953           0.0.0.0:*               LISTEN      23128/named         
tcp6       0      0 :::53                   :::*                    LISTEN      23128/named         
tcp6       0      0 ::1:953                 :::*                    LISTEN      23128/named         
udp        0      0 192.168.23.145:53       0.0.0.0:*                           23128/named         
udp        0      0 127.0.0.1:53            0.0.0.0:*                           23128/named         
udp6       0      0 :::53                   :::*                                23128/named         
[root@load-balance1 ~]# 

        4.修改配置文件,告诉named为yangyuan.shop提供域名解析

[root@load-balance1 ~]# cat /etc/named.rfc1912.zones 
zone "yangyuan.shop" IN {
	type master;
	file "yangyuan.shop.zone";
	allow-update { none; };
};

        5.添加上面的配置,建议在localhost的后面

在/var/named存放dns域名解析的数据文件 --》创建yangyuan.shop的数据文件
[root@load-balance1 ~]# cd /var/named
[root@load-balance1 named]# pwd
/var/named
[root@load-balance1 named]# ls
chroot      data     dyndb-ldap  named.empty      named.loopback  slaves
chroot_sdb  dynamic  named.ca    named.localhost  sc.com.zone
[root@load-balance1 named]# cp -a named.localhost yangyuan.shop.zone
[root@load-balance1 named]# ll
总用量 24
drwxr-x--- 7 root  named   61 6月   4 19:40 chroot
drwxr-x--- 7 root  named   61 6月   4 19:40 chroot_sdb
drwxrwx--- 2 named named   49 6月  11 12:32 data
drwxrwx--- 2 named named   60 6月  18 17:58 dynamic
drwxrwx--- 2 root  named    6 4月   1 2020 dyndb-ldap
-rw-r----- 1 root  named 2253 4月   5 2018 named.ca
-rw-r----- 1 root  named  152 12月 15 2009 named.empty
-rw-r----- 1 root  named  152 6月  21 2007 named.localhost
-rw-r----- 1 root  named  168 12月 15 2009 named.loopback
-rw-r----- 1 root  named  434 6月   6 19:55 sc.com.zone
drwxrwx--- 2 named named    6 1月  26 00:48 slaves
-rw-r----- 1 root  named  152 6月  21 2007 yangyuan.shop.zone
[root@load-balance1 named]# cat yangyuan.shop.zone 
$TTL 1D
@	IN SOA	@ rname.invalid. (
					0	; serial
					1D	; refresh
					1H	; retry
					1W	; expire
					3H )	; minimum
	NS	@
	A	127.0.0.1
	AAAA	::1
[root@load-balance1 named]# vim yangyuan.shop.zone 
[root@load-balance1 named]# cat yangyuan.shop.zone 
$TTL 1D
@	IN SOA	@ rname.invalid. (
					0	; serial
					1D	; refresh
					1H	; retry
					1W	; expire
					3H )	; minimum
	NS	@
	A	192.168.23.145
[root@load-balance1 named]# service named restart   刷新named服务
Redirecting to /bin/systemctl restart named.service
检查配置文件
[root@load-balance1 named]# named-checkconf /etc/named.rfc1912.zones   
检查数据文件是否错误
[root@load-balance1 named]# named-checkzone yangyuan.shop /var/named/yangyuan.shop.zone 
zone yangyuan.shop/IN: loaded serial 0
OK
[root@load-balance1 named]# 


5.keepalived实现双VIP负载均衡高可用

 dns负载均衡记录

www.yangyuan.shop  192.168.23.139

www.yangyuan.shop  192.168.23.132

         1.安装keepalived软件,在2台负载均衡器上都安装

[root@load-balance1 conf]# yum install keepalived -y

        2.修改配置文件,在每台机器上启用2个vrrp实例

[root@load-balance1 conf]# cd /etc/keepalived/
[root@load-balance1 keepalived]# ls
keepalived.conf
[root@load-balance1 keepalived]# vim keepalived.conf 
[root@load-balance1 keepalived]# cat keepalived.conf 
! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
   #vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 58
    priority 120
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.23.188
    }
}

vrrp_instance VI_2 {
    state BACKUP
    interface ens33
    virtual_router_id 60
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.23.199
    }
}

[root@load-balance1 keepalived]#

        第2台机器上的配置

[root@lb2 keepalived]# vim keepalived.conf 
[root@lb2 keepalived]# cat keepalived.conf 
! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
   #vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 58
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.23.188
    }
}
vrrp_instance VI_2 {
    state MASTER
    interface ens33
    virtual_router_id 60
    priority 120
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.23.199
    }
}
[root@lb2 keepalived]# 

6.使用Prometheus对Web集群进行监控,结合Grafana进行数据展示

        1.安装prometheus server

https://github.com/prometheus/prometheus/releases/download/v2.45.0-rc.0/prometheus-2.45.0-rc.0.linux-amd64.tar.gz
源码安装
1.上传下载的源码包到linux服务器
[root@web2 ~]# mkdir /prom
[root@web2 ~]# cd /prom
[root@web2 prom]# ls
prometheus-2.45.0-rc.0.linux-amd64.tar.gz
[root@web2 prom]# tar xf prometheus-2.45.0-rc.0.linux-amd64.tar.gz 
[root@web2 prom]# ls
prometheus-2.45.0-rc.0.linux-amd64  prometheus-2.45.0-rc.0.linux-amd64.tar.gz
[root@web2 prom]# 
[root@web2 prom]# mv prometheus-2.45.0-rc.0.linux-amd64 prometheus
[root@web2 prom]# cd prometheus/
[root@web2 prometheus]# ls
console_libraries  consoles  LICENSE  NOTICE  prometheus  prometheus.yml  promtool
临时修改和永久修改PATH变量,添加prometheus的路径信息
[root@web2 prometheus]# PATH=/prom/prometheus:$PATH
[root@web2 prometheus]# vim /root/.bashrc 
[root@web2 prometheus]# cat /root/.bashrc
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi
 PATH=/prom/prometheus:$PATH   添加

执行prometheus程序
[root@web2 prometheus]# nohup prometheus  --config.file=/prom/prometheus/prometheus.yml &
[1] 245848
[root@web2 prometheus]# nohup: ignoring input and appending output to 'nohup.out'

 查看prometheus进程
[root@web2 prometheus]# ps aux|grep prome
root      245848  0.1  3.7 797744 66440 pts/0    Sl   15:22   0:00 prometheus --config.file=/prom/prometheus/prometheus.yml
root      247582  0.0  0.0  12136  1136 pts/0    R+   15:22   0:00 grep --color=auto prome
查看prometheus的端口号
[root@web2 prometheus]# netstat -anplut|grep prome
tcp6       0      0 :::9090                 :::*                    LISTEN      245848/prometheus   
tcp6       0      0 ::1:9090                ::1:52646               ESTABLISHED 245848/prometheus   
tcp6       0      0 ::1:52646               ::1:9090                ESTABLISHED 245848/prometheus   
[root@web2 prometheus]# 

        2.把prometheus做成一个服务,方便管理

[root@web2 prometheus]# vim /usr/lib/systemd/system/prometheus.service
[root@web2 prometheus]# cat /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus
[Service]
ExecStart=/prom/prometheus/prometheus --config.file=/prom/prometheus/prometheus.yml
ExecReload=/bin/kill -HUP $MAINPID
killMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
[root@web2 prometheus]# systemctl daemon-reload  #重新加载systemd相关的服务



第一次是因为使用nohup方式启动的prometheus,还是需要使用kill的方式杀死第一次启动的进程后面可以使用service方式管理prometheus了
[root@web2 ~]# service prometheus restart
Redirecting to /bin/systemctl restart prometheus.service
[root@web2 ~]# ps xua|grep prometheus
root      245848  0.0  4.3 929072 76148 pts/0    Sl   15:22   0:01 prometheus --config.file=/prom/prometheus/prometheus.yml
root      514701  0.0  0.0  12136  1080 pts/1    R+   16:53   0:00 grep --color=auto prometheus
[root@web2 ~]# kill -9 245848
[root@web2 ~]# ps aux|grep prome
root      517244  0.0  0.0  12136  1156 pts/1    R+   16:54   0:00 grep --color=auto prome
[root@web2 ~]# service prometheus restart
Redirecting to /bin/systemctl restart prometheus.service
[root@web2 ~]# ps aux|grep prome
root      518338  0.2  3.3 797488 59536 ?        Ssl  16:54   0:00 /prom/prometheus/prometheus --config.file=/prom/prometheus/prometheus.yml
root      519048  0.0  0.0  12136  1120 pts/1    R+   16:54   0:00 grep --color=auto prome
[root@web2 ~]# 


         3.在node节点服务器上安装exporter程序

1.下载node_exporter-1.6.0.linux-amd64.tar.gz源码,上传到节点服务器上
2.解压
[root@load-balance1 ~]# ls
10269265_yangyuan.shop_nginx.zip  nginx
anaconda-ks.cfg                   node_exporter-1.6.0.linux-amd64.tar.gz
[root@load-balance1 ~]# tar xf node_exporter-1.6.0.linux-amd64.tar.gz 
[root@load-balance1 ~]# ls
10269265_yangyuan.shop_nginx.zip  node_exporter-1.6.0.linux-amd64
anaconda-ks.cfg                   node_exporter-1.6.0.linux-amd64.tar.gz
nginx
[root@load-balance1 ~]# mv node_exporter-1.6.0.linux-amd64 /node_exporter
[root@load-balance1 ~]# cd /node_exporter/
[root@load-balance1 node_exporter]# ls
LICENSE  node_exporter  nohup.out  NOTICE

修改PATH变量,这样就可以直接敲node_exporter运行了
[root@load-balance1 node_exporter]# PATH=/node_exporter/:$PATH
[root@load-balance1 node_exporter]# vim /root/.bashrc
[root@load-balance1 node_exporter]# cat /root/.bashrc 
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi
PATH=/node_exporter/:$PATH
PATH=/node_exporter/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/yy99/sbin
[root@load-balance1 node_exporter]# 

执行node exporter 代理程序agent,具体端口号可以自己定义,只要不和其他服务器冲突就可以
[root@load-balance1 node_exporter]# nohup node_exporter --web.listen-address 0.0.0.0:8090 &
[1] 23723
[root@load-balance1 node_exporter]# nohup: 忽略输入并把输出追加到"nohup.out"

[root@load-balance1 node_exporter]# ps aux|grep node
root      23723  1.2  1.4 725112 14896 pts/1    Sl   14:45   0:00 node_exporter --web.listen-address 0.0.0.0:8090
root      23731  0.0  0.0 112824   976 pts/1    S+   14:45   0:00 grep --color=auto node
[root@load-balance1 node_exporter]# 

        4.在prometheus server里添加我们在哪些机器里安装了exporter程序

[root@web2 prom]# cd prometheus/
[root@prometheus prometheus]# ls
console_libraries  consoles  data  LICENSE  nohup.out  NOTICE  prometheus  prometheus.yml  promtool
[root@web2 prometheus]# vim prometheus.yml 
 - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]
  - job_name: "LB1"
    static_configs:
      - targets: ["192.168.23.145:8090"]
  - job_name: "LB2"
    static_configs:
      - targets: ["192.168.23.146:8090"]
  - job_name: "NFS"
    static_configs:
      - targets: ["192.168.23.142:8090"]
  - job_name: "WEB1"
    static_configs:
      - targets: ["192.168.23.139:8090"]



重启prometheus服务
[root@web2 prometheus]# service prometheus restart
Redirecting to /bin/systemctl restart prometheus.service
[root@web2 prometheus]# 

        5.安装部署grafana

[root@web2 ~]# mkdir /grafana
[root@web2 ~]# cd /grafana
[root@web2 grafana]# ls
grafana-enterprise-10.0.0-1.x86_64.rpm
[root@web2 grafana]# yum install grafana-enterprise-10.0.0-1.x86_64.rpm -y
[root@web2 grafana]# service grafana-server start
Starting grafana-server (via systemctl):                   [  OK  ]

grafana监听的端口号是3000
[root@web2 grafana]# netstat -anplut|grep grafana
tcp        0      0 172.30.16.238:45382     34.120.177.193:443      ESTABLISHED 582842/grafana      
tcp        0    224 172.30.16.238:37276     185.199.109.133:443     ESTABLISHED 582842/grafana      
tcp6       0      0 :::3000                 :::*                    LISTEN      582842/grafana      
[root@web2 grafana]# 


登录,在浏览器里登录
http://192.168.23.132:3000
默认的用户名和密码是
用户名admin
密码admin

设置grafana开机启动
[root@web2 grafana]# systemctl enable grafana-server
Created symlink from /etc/systemd/system/multi-user.target.wants/grafana-server.service to /usr/lib/systemd/system/grafana-server.service.
[root@web2 grafana]# 

        6.grafana UI页面展示

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值