puppet连载18:搭建redis

本文涉及的产品
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
云数据库 Tair(兼容Redis),内存型 2GB
简介: cd /puppet/softwget http://download.redis.io/releases/redis-3.2.11.tar.gzmkdir -p /etc/puppet/modules/linuxredis/{manifests,...

cd /puppet/soft
wget http://download.redis.io/releases/redis-3.2.11.tar.gz
mkdir -p /etc/puppet/modules/linuxredis/{manifests,files,templates}


vi /etc/puppet/modules/linuxredis/templates/redis-3.2.11.conf.erb

bind 0.0.0.0
protected-mode yes
port <%= real_redis_port %>
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_<%= real_redis_port %>.pid
loglevel notice
logfile ""
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
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
hz 10
aof-rewrite-incremental-fsync yes


写启动脚本

vim /puppet/soft/redis-3.2.11.sh

!/bin/bash

chkconfig:2345 93 63

description:redis star stop

. /etc/rc.d/init.d/functions

servicename=/data/redis-3.2.11/src/redis-server
serviceconfig=/data/redis-3.2.11/redis.conf

if [ ! -f $servicename ];then
exit 6;
fi

if [ ! -f $serviceconfig ];then
exit 7;
fi

case 1 in start)servicename serviceconfig ;; stop) pkill redis-server ;; restart) pkill redis-server &&servicename serviceconfig ;; status) RETVAL=`ps aux|grep "servicename"|grep -Ev "grep|color"|wc -l`
if [ RETVAL -ge 1 ]; then echo 'running' exit 0 else echo 'stopped' fi exit 1 ;; *) echo "Usage:0 {start|stop|restart|status}"
exit 2
esac

exit $?

vi /etc/puppet/modules/linuxredis/manifests/init.pp

class linuxredis::redis3211 {

real_redis_port =redis_port ? {'' => '6379',default => $redis_port }

exec {"/data":
command => "mkdir /data",
creates => "/data",
path => ["/usr/bin","/usr/sbin","/sbin","/bin"],
}
file {"/data/redis-3.2.11.tar.gz":
source => "puppet:///soft/redis-3.2.11.tar.gz",
ensure => file,
mode => 755,owner => root,group => root,
require => [Exec["/data"],File["/etc/init.d/redis-server"]],
notify => Exec["tar redis-3.2.11.tar.gz"],
}
file {"/etc/init.d/redis-server":
source => "puppet:///soft/redis-3.2.11.sh",
ensure => file,
mode => 755,owner => root,group => root,
}
exec {"tar redis-3.2.11.tar.gz":
command => "tar zxvf redis-3.2.11.tar.gz && cd redis-3.2.11 && make && cd src && make install",
cwd => "/data",
refreshonly => true,
path => ["/usr/bin","/usr/sbin","/sbin","/bin"],
notify => Exec["firewallredisport"],
}
exec {"firewallredisport":
command => "firewall-cmd --add-port=$real_redis_port/tcp --permanent && firewall-cmd --reload",
path => ["/usr/sbin","/usr/bin","/bin","/sbin"],
refreshonly => true,
}
file {'/data/redis-3.2.11/redis.conf':
ensure => file,
mode => 755,owner => root,group => root,
content => template("/etc/puppet/modules/linuxredis/templates/redis-3.2.11.conf.erb"),
backup => '.bak',
notify => [Service["redis-server"],Exec["firewallredisport"]],
require => Exec["tar redis-3.2.11.tar.gz"],
}
service {"redis-server":
ensure => running,
hasrestart => true,
provider => init,
start => "/etc/init.d/redis-server start",
stop => "/etc/init.d/redis-server stop",
restart => "/etc/init.d/redis-server restart",
status => "/etc/init.d/redis-server status",
}
}


调用

node 'huangat-test' {

$real_redis_port =

include linuxredis::redis3211
}

目录
相关文章
|
存储 NoSQL Linux
Redis三种集群模式原理与搭建配置
Redis三种集群模式原理与搭建配置
2733 0
|
NoSQL 安全 Linux
【Redis入门】在阿里云上快速安装 Redis
如果你最近打算学习 redis 并且买了阿里云的 Linux 服务器,那么借助阿里云服务器和宝塔Linux面板,只需要简单几步就可以安装好 redis。
1354 0
【Redis入门】在阿里云上快速安装 Redis
|
NoSQL Linux Redis
|
NoSQL Java Linux
redis哨兵模式搭建和使用
本文主要介绍如何搭建Redis哨兵模式以及Springboot如何配置redis哨兵模式
1657 5
redis哨兵模式搭建和使用
|
NoSQL Java Redis
【Docker】搭建部署Redis高可用集群实验
【Docker】搭建部署Redis高可用集群实验
1333 1
【Docker】搭建部署Redis高可用集群实验
|
消息中间件 缓存 弹性计算
ELK搭建(十):搭建redis运行指标监控平台
Redis作为基于内存的非关系型数据库,常常被应用于热点数据缓存,它很大程度上为我们关系性数据库提供了性能补充。保证redis的高可用,对应整个应用程序的运行至关重要,一个直观的监控redis运行情况的数据看板可以为我们实时了解redis运行情况提供极大的便利。
314 0
ELK搭建(十):搭建redis运行指标监控平台
|
NoSQL Redis 算法
搭建Redis高可用Cluster集群环境
首先搭建单机版 Redis 环境
265 0
搭建Redis高可用Cluster集群环境
|
NoSQL Redis 容器
搭建redis集群
docker-compose 搭建redis集群
213 0
搭建redis集群
|
NoSQL Linux Redis
搭建redis服务(单体应用)
搭建redis服务(单体应用)
180 0
|
NoSQL 关系型数据库 MySQL
【网络安全】基于centos7搭建discuz+redis服务
【网络安全】基于centos7搭建discuz+redis服务
243 0
【网络安全】基于centos7搭建discuz+redis服务

热门文章

最新文章

推荐镜像

更多
下一篇
开通oss服务