데이터 베이스 MySQL 튜토리얼 Nagios监控生产环境redis集群服务实战

Nagios监控生产环境redis集群服务实战

Jun 07, 2016 pm 04:04 PM
nagios redis 실제 전투 제공하다 환경 생산 감시 장치 무리

前言: 以前做了cacti上展示redis性能报表图,可以看到redis的性能变化趋势图, 但是还缺了实时报警通知的功能,现在补上这一环节。在redis服务瓶颈或者异常时候即使报警通知,方便dba第一时间处理维护。 1,下载redis监控插件 Redis已经在服务器安装好了,

前言: 以前做了cacti上展示redis性能报表图,可以看到redis的性能变化趋势图,但是还缺了实时报警通知的功能,现在补上这一环节。在redis服务瓶颈或者异常时候即使报警通知,方便dba第一时间处理维护。
1,下载redis监控插件

Redis已经在服务器安装好了,所以直接可以进行监控,redis集群安装请参考:http://blog.itpub.net/26230597/viewspace-1145831/,下载地址为:http://download.csdn.net/detail/mchdba/8023351,有2个版本,一个是perl脚本写成的,一个是php脚本写成的,可以任意选择一个,这里选择的是perl脚本。

2,赋予执行权限

将check_redis.php和check_redis.pl复制到/usr/lib/nagios/plugins/目录,然后赋予执行权限,

[root@wgq_41 plugins]# cd /usr/lib/nagios/plugins/

[root@wgq_41 plugins]# chown -R nagios.nagios check_redis.*

[root@wgq_41 plugins]# chmod 750 check_redis.*

3,定义监控命令

[root@wgq objects] vim /usr/local/nagios/etc/objects/commands.cfg

# add by tim on 20141010,for redis

# check redis

define command {

command_name check_redis

command_line /usr/lib/nagios/plugins/check_redis.pl -H $HOSTADDRESS$ -p $ARG1$ -a $ARG2$ -w $ARG3$ -c $ARG4$ -f

}

4,定义redis监控主机

[root@wgq etc]# vim /usr/local/nagios/etc/hosts.cfg

# No.018,redis master server

define host{

use linux-server

host_name cache-1

alias cache-1

address 10.xxx.3.x0

check_command check-host-alive

max_check_attempts 5

check_period 24x7

contact_groups ops

notification_interval 30

notification_period 24x7

notification_options d,u,r

}

# No.020 cache-3 redis slave server

define host{

use linux-server

host_name cache-3

alias cache-3

address 10.xx.3.x2

check_command check-host-alive

max_check_attempts 5

check_period 24x7

contact_groups ops

notification_interval 30

notification_period 24x7

notification_options d,u,r

}

5,定义redis监控主机组

define hostgroup {

hostgroup_name Redis_Servers

alias Redisservices

members cache-1,cache-2

}

6,定义redis监控服务选项

[root@wgq objects]# vim /usr/local/nagios/etc/objects/services_redis.cfg

# Redis Master 监控选项

define service {

host_name cache-1

servicegroups Redisservices

service_description Redis Master Clients

check_command check_redis!6379!'connected_clients,blocked_clients,client_longest_output_list,client_biggest_input_buf'!200,50,~,~!600,150,~,~

max_check_attempts 5

normal_check_interval 3

retry_check_interval 2

check_period 24x7

notification_interval 10

notification_period 24x7

notification_options w,u,c,r

contact_groups ops

}

define service {

host_name cache-1

servicegroups Redisservices

service_description Redis Master Memory

check_command check_redis!6379!'used_memory_human,used_memory_peak_human'!~,~!~,~

max_check_attempts 5

normal_check_interval 3

retry_check_interval 2

check_period 24x7

notification_interval 10

notification_period 24x7

notification_options w,u,c,r

contact_groups ops

}

define service {

host_name cache-1

servicegroups Redisservices

service_description Redis Master CPU

check_command check_redis!6379!'used_cpu_sys,used_cpu_user,used_cpu_sys_children,used_cpu_user_children'!~,~,~,~!~,~,~,~ ; #未定义监控报警阀值

max_check_attempts 5

normal_check_interval 3

retry_check_interval 2

check_period 24x7

notification_interval 10

notification_period 24x7

notification_options w,u,c,r

contact_groups ops

}

# Redis Slave 监控选项

define service {

host_name cache-3

servicegroups Redisservices

service_description Redis Slave Clients

check_command check_redis!6379!'connected_clients,blocked_clients,client_longest_output_list,client_biggest_input_buf'!200,50,~,~!600,150,~,~

max_check_attempts 5

normal_check_interval 3

retry_check_interval 2

check_period 24x7

notification_interval 10

notification_period 24x7

notification_options w,u,c,r

contact_groups ops

}

define service {

host_name cache-3

servicegroups Redisservices

service_description Redis Slave Memory

check_command check_redis!6379!'used_memory_human,used_memory_peak_human'!~,~!~,~

max_check_attempts 5

normal_check_interval 3

retry_check_interval 2

check_period 24x7

notification_interval 10

notification_period 24x7

notification_options w,u,c,r

contact_groups ops

}

define service {

host_name cache-3

servicegroups Redisservices

service_description Redis Slave CPU

check_command check_redis!6379!'used_cpu_sys,used_cpu_user,used_cpu_sys_children,used_cpu_user_children'!~,~,~,~!~,~,~,~ ; #未定义监控报警阀值

max_check_attempts 5

normal_check_interval 3

retry_check_interval 2

check_period 24x7

notification_interval 10

notification_period 24x7

notification_options w,u,c,r

contact_groups ops

}

赋予nagios用户执行权限

[root@wgq objects]# chown -R nagios.nagios services_redis.cfg

[root@wgq objects]# chmod 777 services_redis.cfg

添加监控服务项到nagios.cfg

[root@wgq etc]# vim /usr/local/nagios/etc/nagios.cfg

cfg_file=/usr/local/nagios/etc/objects/services_redis.cfg

7,测试redis监控服务

执行命令/usr/lib/nagios/plugins/check_redis.pl -H cache-1 -a 'connected_clients,blocked_clients' -w ~,~ -c ~,~ -m -M 4G -A -R -T 来测试下redis监控是否正常运行

[root@wgq plugins]# /usr/lib/nagios/plugins/check_redis.pl -H 10.2xx.3.x0 -a 'connected_clients,blocked_clients' -w ~,~ -c ~,~ -m -M 4G -A -R -T

OK: REDIS 2.8.8 on 10.2xx.3.x0:6379 has 1 databases (db0) with 28497 keys, up 76 days 2 hours - response in 0.004s, hitrate is 12.83%, memory use is 194.14M (peak 205.14M, 6.49% of max, fragmentation 1.37%), connected_clients is 35, blocked_clients is 11 | redis_build_id=d322d411218ade61 total_connections_received=341191c used_memory_lua=33792 aof_rewrite_buffer_length=0 used_memory_rss=278749184B redis_git_dirty=0 loading=0 redis_mode=standalone latest_fork_usec=5588 repl_backlog_first_byte_offset=0 sync_partial_ok=0 master_repl_offset=0 uptime_in_days=76c aof_rewrite_scheduled=0 lru_clock=3649276 rdb_bgsave_in_progress=0 rejected_connections=0 repl_backlog_active=0 aof_delayed_fsync=1 sync_full=0 process_id=7776 used_memory_human=194.14M aof_current_rewrite_time_sec=-1 used_memory=203570960 aof_enabled=1 blocked_clients=11 aof_last_bgrewrite_status=ok aof_rewrite_in_progress=0 sync_partial_err=0 used_cpu_sys_children=2222.75 connected_slaves=0 repl_backlog_histlen=0 uptime_in_seconds=6576292c repl_backlog_size=1048576 os=Linux 2.6.32-358.el6.x86_64 x86_64 used_cpu_sys=32640.80 aof_pending_bio_fsync=0 connected_clients=35 rdb_last_bgsave_time_sec=1 used_memory_peak_human=205.14M run_id=d1fc098d26fa4bbcef3eabeec6d19a858f03dd00 rdb_last_bgsave_status=ok pubsub_patterns=8 client_biggest_input_buf=0 keyspace_hits=42175896c rdb_last_save_time=1412935342 rdb_changes_since_last_save=318 db0_keys=28497 db0_expires=7 db0_avg_ttl=34003 aof_pending_rewrite=0 aof_buffer_length=0 config_file=/usr/local/redis-2.8.8/etc/redis.conf pubsub_channels=0 used_cpu_user_children=21375.34 hz=10 aof_last_rewrite_time_sec=2 aof_last_write_status=ok aof_base_size=82883253 used_cpu_user=18460.42 keyspace_misses=286602797c tcp_port=6379 total_commands_processed=797581196c mem_fragmentation_ratio=1.37 aof_current_size=146485850 rdb_current_bgsave_time_sec=-1 client_longest_output_list=0 instantaneous_ops_per_sec=114 evicted_keys=0c used_memory_peak=215106272B expired_keys=58977c total_keys=28497 total_expires=7 response_time=0.003802s hitrate=12.8281% memory_utilization=6.49013519287109%

[root@wgq plugins]#

8,查看redis监控服务状态

先重新加载nagios,使刚添加的redis监控配置生效

[root@wgq objects]# service nagios reload

Running configuration check...

Reloading nagios configuration...

done

[root@wgq objects]#

redis监控服务界面,如下图所示:

\


9,操作过程中的报错处理过程

报错:

[root@wgq_line_cache_3_41 plugins]# ./check_redis.pl --help

Can't locate Redis.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at ./check_redis.pl line 421.

BEGIN failed--compilation aborted at ./check_redis.pl line 421.

[root@wgq_line_cache_3_41 plugins]#

[root@wgq_line_cache_3_41 plugins]# perl -MCPAN -e shell

Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v1.9402)

Enter 'h' for help.

cpan[1]> install Redis

Can't locate Module/Build/Tiny.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Build.PL line 2.

BEGIN failed--compilation aborted at Build.PL line 2.

Warning: No success on command[/usr/bin/perl Build.PL --installdirs site]

Warning (usually harmless): 'YAML' not installed, will not store persistent state

DAMS/Redis-1.976.tar.gz

/usr/bin/perl Build.PL --installdirs site -- NOT OK

Running Build test

Make had some problems, won't test

Running Build install

Make had some problems, won't install

Could not read '/root/.cpan/build/Redis-1.976-Zhz6xI/META.yml'. Falling back to other methods to determine prerequisites……

YAML是以数据为中央的标记语言,其使用ASCII码(如连字符、问号、冒号、逗号等)构造数据块(标量值或哈希码)。和XML相同,YAML也是一种机器可识别语言,并能和多种脚本语言相结合,其中一种便是Perl,需要安装YAML,如下执行:

cpan[2]>install YAML

……

Appending installation info to /usr/lib64/perl5/perllocal.pod

INGY/YAML-1.12.tar.gz

/usr/bin/make install -- OK

CPAN: YAML loaded ok (v1.12)

PS:这里可能会安装失败,失败原因是网络连接,可以多执行几次install YAML就会成功。

再继续执行install Redis,有如下提示信息

cpan[4]> install Redis

Running install for module 'Redis'

Running Build for D/DA/DAMS/Redis-1.976.tar.gz

Has already been unwrapped into directory /root/.cpan/build/Redis-1.976-cUL4rt

'/usr/bin/perl Build.PL --installdirs site' returned status 512, won't make

Running Build test

Make had some problems, won't test

Running Build install

Make had some problems, won't install

cpan[5]>

Build失败,Build.PL故障了,需要重新安装下执行命令install Build

cpan[5]> install Build

成功后,再执行install Redis

cpan[6]> install Redis

Redis安装执行成功。

\

\

参考文档:http://exchange.nagios.org/directory/Plugins/Databases/check_redis-2Epl/details

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25 : Myrise에서 모든 것을 잠금 해제하는 방법
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

Redis는 지정된 구성 파일을 사용하여 다시 시작합니다 Redis는 지정된 구성 파일을 사용하여 다시 시작합니다 Apr 10, 2025 pm 02:42 PM

구성 파일을 지정하여 Redis를 다시 시작하십시오. 1. 구성 파일을 찾으십시오 (일반적으로 Conf 서브 디렉토리에있는 redis.conf); 2. 필요한 구성을 수정합니다 (예 : 포트 변경); 3. Redis-server/path/to/redis.conf 명령을 사용하여 구성 파일을 통해 redis를 다시 시작하십시오 (여기서 /path/to/redis.conf는 수정 된 구성 파일의 경로); 4. Redis-Cli를 사용하여 성공적으로 다시 시작되었는지 확인하십시오.

Redis 재시작 데이터가 여전히 있습니다 Redis 재시작 데이터가 여전히 있습니다 Apr 10, 2025 pm 02:45 PM

Redis가 다시 시작된 후에도 데이터가 여전히 존재합니다. Redis는 메모리에 데이터를 저장하고 다시 시작하면 메모리 데이터가 삭제되지 않습니다. Redis는 또한 RDB 또는 AOF 파일을 통해 하드 디스크에 데이터를 저장하는 지속성을 제공하여 다시 시작한 후 지속적인 파일에서 데이터를 복구 할 수 있도록합니다.

Redis Restart 서비스는 어디에 있습니까? Redis Restart 서비스는 어디에 있습니까? Apr 10, 2025 pm 02:36 PM

다른 운영 체제에서 REDIS 서비스를 다시 시작하는 방법 : Linux/MacOS : SystemCTL 명령 (SystemCTL REDIS-SERVER 재시작) 또는 서비스 명령 (Service Redis-Server Restart)을 사용하십시오. Windows : Services.msc 도구를 사용하고 (실행 대화 상자에서 "services.msc"를 입력하고 Enter를 누르십시오) "redis"서비스를 마우스 오른쪽 단추로 클릭하고 "다시 시작"을 선택하십시오.

Redis Restart 명령은 무엇입니까? Redis Restart 명령은 무엇입니까? Apr 10, 2025 pm 02:39 PM

Redis Restart 명령은 Redis-Server입니다. 이 명령은 구성 파일을로드하고, 데이터 구조를 만들고, Redis 서버를 시작하고, 클라이언트 연결을 듣는 데 사용됩니다. 사용자는 터미널에서 "redis-server [옵션]"명령을 실행하여 Redis 서버를 다시 시작할 수 있습니다. 일반적인 옵션에는 배경 작동, 구성 파일 경로 지정, 청취 포트 지정 및 데이터 손실 된 경우에만 스냅 샷을 다시로드하는 것이 포함됩니다. 서버를 다시 시작하면 모든 클라이언트 연결을 분리하여 다시 시작하기 전에 필요한 데이터를 저장해야합니다.

Redis로 모든 데이터를 정리하는 방법 Redis로 모든 데이터를 정리하는 방법 Apr 10, 2025 pm 05:06 PM

모든 Redis 데이터를 청소하는 방법 : Redis 2.8 이상 : Flushall 명령은 모든 키 값 쌍을 삭제합니다. Redis 2.6 이상 : DEL 명령을 사용하여 키를 하나씩 삭제하거나 Redis 클라이언트를 사용하여 메소드를 삭제하십시오. 대안 : Redis 서비스를 다시 시작하거나 (주의해서 사용) Redis 클라이언트 (예 : Flushall () 또는 FlushDB ())를 사용하십시오.

Redis의 다른 사례가 어떻게 의사 소통하는지 Redis의 다른 사례가 어떻게 의사 소통하는지 Apr 10, 2025 pm 05:15 PM

Redis 인스턴스 간의 커뮤니케이션을위한 몇 가지 메커니즘이 있습니다 : Pub/Sub : Publish/Sub Mode, 효율적이고 낮은 긴장 메시징이 가능합니다. 클러스터 모드 : 분산 배포 방법, 고 가용성 및 결함 공차를 제공합니다. 크로스 인스턴스 명령 : 임시 운영 또는 관리 목적에 적합한 명령을 다른 인스턴스로 직접 전송할 수 있습니다.

Redis는 명확한 데이터를 다시 시작합니다 Redis는 명확한 데이터를 다시 시작합니다 Apr 10, 2025 pm 02:48 PM

Redis Restart는 Redis가 메모리에 데이터를 저장하고 RDB 또는 AOF와 같은 영구 스토리지에서 데이터를로드하기 때문에 데이터를 지우지 않습니다. 영구 스토리지에는 두 가지 유형의 영구 저장소가 있습니다 : RDB와 AOF는 다시 시작한 후 데이터가 손실되지 않도록합니다. 또한 Redis에는 스냅 샷 옵션, 복제 및 센티넬과 같은 다른 보호 기능이있어 데이터 손실을 방지합니다. 그러나 지속적인 저장소 손상 또는 우발적 종료와 같은 드문 경우 데이터 손실로 이어질 수 있습니다.

Redis의 데이터베이스에서 모든 키의 메모리 사용을 보는 방법 Redis의 데이터베이스에서 모든 키의 메모리 사용을 보는 방법 Apr 10, 2025 pm 03:03 PM

Redis는 데이터베이스에서 모든 키의 메모리 사용을 볼 수있는 두 가지 명령을 제공합니다. 메모리 사용 Allkeys : "키"(유형) # 메모리 사용 (바이트) 정보 메모리 키 공간 : 각 데이터베이스의 모든 키에 대한 메모리 사용 정보 목록을 제공합니다.

See all articles