Puppet Self-coding module (iii): Redis

Source: Internet
Author: User

I. Description of the module

Redis is an open source API that is written in ANSI C , supports the web, can be persisted in memory, Key-value databases, and provides multiple languages .

data persistence has snapshot and log append methods, where snapshots are used to periodically save data in the Dump.rdb file

Configuring Master-Slave synchronization allows multiple slave to share the load of read requests or disable data persistence in master, reducing the burden and persisting only in slave configuration.


II. directory Structure

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7D/E7/wKiom1byUGawHB7GAAANkBdAkQ8405.png "title=" Qq20160323160613.png "alt=" Wkiom1byugawhb7gaaankbdakq8405.png "/>

Third, code display

1. Files Directory

Redis #redis服务脚本

#!/bin/sh# chkconfig: 2345 80 90# simple redis init.d script  conceived to work on linux systems# as it does use of  The /proc filesystem.# src file is  /usr/local/redis/utils/redis_init_ scriptredisport=6379exec=/usr/local/bin/redis-servercliexec=/usr/local/bin/redis-clipidfile=/var/run/ redis.pidconf= "/etc/redis.conf" case  "$"  in    start) if [ -f $ pidfile ]thenecho  "$PIDFILE  exists, process is already running or  crashed "elseecho " Starting redis server $EXEC   $CONF  &fi;; Stop) if [ ! -f  $PIDFILE  ]thenecho  $PIDFILE  does not exist,  Process is not running "elsepid=$ (cat  $PIDFILE) echo " stopping  ... "$CLIEXEC  - p  $REDISPORT  shutdownwhile [ -x /proc/${pid} ]doecho  "waiting for redis to shutdown&nbsp ..." sleep  1doneecho  "redis stopped" FI;; *) echo  "please use start or stop as first argument";; Esac

redis-2.8.19.tar.gz #redis安装包, download http://download.redis.io/releases/redis-2.8.19.tar.gz


2. Manifests Catalogue

init.pp

Class redis{Exec {path = "/usr/bin:/bin:/usr/sbin:/sbin"} include Redis::install,redis::config,redis::service }

install.pp

class redis::install {  exec{  path => ['/usr/bin ', '/usr/sbin ', '/ Bin '] }  package { [' gcc ', ' gcc-c++ ', ' Perl ', ' pcre ', ' zlib-devel ', ' openssl-devel ', ' Tcl ' :     ensure => installed,    before => exec[ ' Install '],  }  file {  ' Redis ':    path =>  '/ Usr/local/src/redis-2.8.19.tar.gz ',    ensure  => directory,     source  =>  ' puppet:///modules/redis/redis-2.8.19.tar.gz ',     ignore  =>  '. SvN ',     owner   => root,     group   => root,    mode     =>  ' 0640 ',  }  exec {  ' Tar redis ':     Command     =>  ' tar -zxf redis-2.8.19.tar.gz ',    cwd          =>  '/usr/local/src ',    refreshonly =>  true,    subscribe   => file[' Redis '],  }   exec {  ' Mv redis ':    command     =>   ' Mv -f redis-2.8.19 /usr/local/redis ',    cwd          =>  '/usr/local/src ',    refreshonly =>  true,    subscribe   => exec[' Tar redis '],  }   exec {  ' Install ':    command     =>  ' make  && make install ',    cwd          =>  '/usr/local/redis ',     refreshonly => true,    subscribe    => exec[' Mv redis '],  }}

     config.pp  

class redis::config {    case  $redis _conf {     master: {        file {  '/etc/redis.conf ':             ensure  => file,             owner   => root,             group   => root,             mode    =>  400,            content =>  Template ("Redis/master-redis.conf.erb"),             notify  => class[' Redis::service '],             require =>&nBsp class[' Redis::install '],        }    }     slave: {        file {  '/etc/redis.conf ':                 ensure   => file,                 owner   => root,                 group   => root,                 mode    =>  400,                 Content => template ("Redis/slave-redis.conf.erb"),                 notify  => class[' Redis::service '],                 require => class[' Redis::install '),             }         }    }    file {  ' REDISD ':         path    =>  '/etc/rc.d/init.d/redis ',         ensure  => file,         owner   => root,        group    => root,        mode    =>  755,        source  =>  ' puppet:///modules/ Redis/redis ',    &nbsP;}     exec {  ' iptables -i input -p tcp --dport 6379  -j accept && service iptables save ':         unless  =>  ' grep  ' 6379 " /etc/sysconfig/iptables 2>/dev/ Null ',     }}

     service.pp

class redis::service {    service {  ' Redis ':          ensure     =>  ' Running ',         enable     =>  ' true ',         hasrestart =>  ' false ',         hasstatus  =>  ' false ',        start       =>  ' Service redis start ',         stop       =>  ' Service redis stop ',         require    => class["Redis::install"],         subscribe  => class["Redis::config"],     }}


3. Templates Catalogue

Master-redis.conf.erb

# redis master configuration file example daemonize yes pidfile / Var/run/redis.pid port 6379 timeout 0 tcp-keepalive 0 loglevel notice  logfile /var/log/redis.log databases 16 save 86400 1  Stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename  dump.rdbdir ./ slave-serve-stale-data yes slave-read-only yes  Repl-disable-tcp-nodelay no slave-priority 100 maxmemory 3gb maxmemory-policy  volatile-lru maxmemory-samples 3 appendonly no appendfilename  appendonly.aof appendfsync everysec no-appendfsync-on-rewrite no  auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb lua-time-limit 5000  slowlog-log-slower-than 10000 slowlog-max-len 1024 hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-entries 512  list-max-ziplist-value 64 set-max-intset-entries 512 zset-max-ziplist-entries  128 zset-max-ziplist-value 64 activerehashing yes client-output-buffer-limit  normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60  Client-output-buffer-limit pubsub 32mb 8mb 60 aof-rewrite-incremental-fsync yes


Slave-redis.conf.erb

# redis slave configuration file example daemonize yes pidfile / Var/run/redis.pid port 6379 timeout 0 tcp-keepalive 0 loglevel notice  logfile /var/log/redis.log databases 16 save 86400 1  Stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename  dump.rdb dir ./ slaveof <%[email protected]_server %> 6379  slave-serve-stale-data yes slave-read-only yes repl-disable-tcp-nodelay no  slave-priority 100 maxmemory 3gb maxmemory-policy volatile-lru  Maxmemory-samples 3 appendonly no appendfilename appendonly.aof appendfsync  everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100  auto-aof-rewrite-min-size 64mb lua-time-limit 5000 slowlog-log-slower-than 10000 slowlog-max-len 1024 hash-max-ziplist-entries 512  hash-max-ziplist-value 64 list-max-ziplist-entries 512 list-max-ziplist-value  64 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value  64 activerehashing yes client-output-buffer-limit normal 0 0 0  Client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub  32mb 8mb 60 aof-rewrite-incremental-fsync yes


Iv. Configuration of Foreman

Refer to the first two articles

Main Library Parameters:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7D/E7/wKiom1byUR-B7zIyAAAyDj3r_SU832.png "title=" Qq20160323161717.png "alt=" Wkiom1byur-b7ziyaaaydj3r_su832.png "/>

from library parameters:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7D/E4/wKioL1byVK3w2msPAAA7b12MPZk491.png "title=" Qq20160323162957.png "alt=" Wkiol1byvk3w2mspaaa7b12mpzk491.png "/>


five . redis command line management
[[email protected] ~]# redis-cli     #连接redis数据库redis127 .0.0.1:6379>   >ping                       #测试连接   >echo test                  #测试打印   >select 1                   #选择数据库0 ~15   > dbsize                    #返回当前数据库key数量   > info                      #获取服务器状态和一些统计信息   >  monitor                   #实时监听并返回redis服务器接收到的所有请求信息   > config get parameter     #获取一个redis配置参数信息, * = All   >  config set parameter value      #设置一个redis配置参数信息   >  config resetstat         #重置INFO命令的统计信息: Keyspace hit number, Number of Keyspace errors, number of processing commands, number of received connections, expired keys, etc.   > debug object key          #获取一个key的调试信息   > debug segfault            #制造一次服务器当机   > flushdb                   #删除当前数据库中的所有key   > flushall                  #删除所有数据库中所有key   > client list               #查看当前所有客户端状态   > shutdown                  #把数据同步保存到磁盘上, and turn off Redis services   > quit                      #退出连接
vi. Redis Desktop management tools

Http://redisdesktop.com/download

Https://github.com/uglide/RedisDesktopManager/wiki/Quick-Start

Redis DesktopManager is a fast, simple, cross-platform support Redis Desktop management tools, based on Qt 5 development, support through SSH Tunnel connection.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7D/E8/wKiom1byVC6w4KvNAAF5CcsjGsk392.png "style=" float: none; "title=" 1.png "alt=" Wkiom1byvc6w4kvnaaf5ccsjgsk392.png "/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7D/E4/wKioL1byVMWTxjhUAAA_X7BabbI606.png "style=" float: none; "title=" 2.png "alt=" Wkiol1byvmwtxjhuaaa_x7babbi606.png "/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7D/E8/wKiom1byVC6DqIHkAAE_BDUxpr4545.png "style=" float: none; "title=" 3.png "alt=" Wkiom1byvc6dqihkaae_bduxpr4545.png "/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7D/E4/wKioL1byVMbAIT59AAEbapW1YzY241.png "style=" float: none; "title=" 4.png "alt=" Wkiol1byvmbait59aaebapw1yzy241.png "/>



Vii. use of the program

<?xml version= "1.0"?><configuration> <appSettings> <add key= "redis.readwritehosts" value= "1 0.188.1.40:6379 "/> <add key=" redis.readonlyhosts "value=" 10.188.1.41:6379 "/> </appSettings>< /configuration>


This article is from the "Moon Ching Xing Fei" blog, please be sure to keep this source http://ywzhou.blog.51cto.com/2785388/1754384

Puppet Self-coding module (iii): Redis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.