puppet连载18:搭建redis

本文涉及的产品
云数据库 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
}

相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
存储 NoSQL Linux
Redis三种集群模式原理与搭建配置
Redis三种集群模式原理与搭建配置
1451 0
|
NoSQL 安全 Linux
【Redis入门】在阿里云上快速安装 Redis
如果你最近打算学习 redis 并且买了阿里云的 Linux 服务器,那么借助阿里云服务器和宝塔Linux面板,只需要简单几步就可以安装好 redis。
983 0
【Redis入门】在阿里云上快速安装 Redis
|
NoSQL Redis CDN
分布式服务器框架之搭建C#+MongoDB+Redis初步
WebAccount站点主要干的事儿是下发 服务器状态信息,这个服务器会和WorldServer建立连接,等所有的GameServer初始化完成之后会同步给WorldServer,WorldServer同步给账号服务器站点,然后账号站点等待玩家请求。
|
NoSQL 算法 中间件
分布式服务器框架之搭建C#+MongoDB+Redis初步
Common类库主要做的是一些大家都需要用到的通用的事情,为了避免重复,所以就提取出来了一个Dll。Common库主要是实现了表格数据的加载模块、在CsRedisClient、MongoClient中间件的基础上进行二次封装。实现了数据库连接、Redis连接、以及数据库和Redis的增删改查断开操作。
|
NoSQL 关系型数据库 MySQL
在 macOS Catalina 10.15 搭建 PHP 开发环境包括PHP的redis扩展
在 macOS Catalina 10.15 搭建 PHP 开发环境包括PHP的redis扩展
209 0
|
监控 NoSQL Java
redis灵魂拷问:怎样搭建一个哨兵主从集群
redis灵魂拷问:怎样搭建一个哨兵主从集群
101 0
|
NoSQL Linux Redis
|
消息中间件 缓存 弹性计算
ELK搭建(十):搭建redis运行指标监控平台
Redis作为基于内存的非关系型数据库,常常被应用于热点数据缓存,它很大程度上为我们关系性数据库提供了性能补充。保证redis的高可用,对应整个应用程序的运行至关重要,一个直观的监控redis运行情况的数据看板可以为我们实时了解redis运行情况提供极大的便利。
172 0
ELK搭建(十):搭建redis运行指标监控平台
|
NoSQL Java Redis
【Docker】搭建部署Redis高可用集群实验
【Docker】搭建部署Redis高可用集群实验
825 1
【Docker】搭建部署Redis高可用集群实验
|
NoSQL Redis 数据安全/隐私保护
【Docker】6、Docker搭建Redis高可用Cluster集群环境
本篇文章将使用 docker 搭建 Redis 高可用 Cluster 集群环境,我们采用三主三从模式,使用 6 个节点搭建 Cluster 集群环境
551 0

推荐镜像

更多