ansible-playbook 安装redis 主从
ansible-playbook 安装redis 主从
手动在测试机上安装一遍redis,最好使用utils下面的install_server.sh安装服务,然后将redis的配置文件和init需要的执行文件 拷贝备用
配置hosts:
[root@ansible ansible]#grep -v '^#' ./hosts |grep -v '^$'
[redis:children]
redis_master
redis_slave
[redis_master] #命名规则使用下划线,不然后面的调用有问题
192.168.3.12
[redis_slave]
192.168.3.13
192.168.3.14
建立redis角色的文件夹:
[root@ansible redis]#mkdir /etc/ansible/roles/redis/{files,templates,tasks,handlers,vars,default,meta} -pv
roles/redis/
├── default
├── files
│ └── redis-4.0.8.tar.gz
├── handlers
├── meta
├── tasks
│ └── main.yml
├── templates
│ ├── redis.j2
│ └── redis.conf.j2
└── vars
[root@ansible redis]# cat tasks/main.yml
- name: yum gcc
yum: name=gcc state=present
- name: copy redis
copy: src=redis-4.0.8.tar.gz dest=/usr/local/src/
- name: tar redis
shell: chdir=/usr/local/src/ tar -zxf redis-4.0.8.tar.gz
- name: install redis
shell: chdir=/usr/local/src/redis-4.0.8 make PREFIX=/usr/local/redis install
- name: mkdir /usr/local/redis/conf/
file: path=/usr/local/redis/conf state=directory
- name: copy redis_{{ port|default(6397) }}.conf
template: src=redis.conf.j2 dest=/usr/local/redis/conf/redis_{{ port|default(6397) }}.conf
- name: copy /etc/init.d/redis_{{ port|default(6397) }}
template: src=redis.j2 dest=/etc/init.d/redis_{{ port|default(6397) }} mode=755
- name: mkdir /var/lib/redis/{{ port|default(6397) }}
file: path=/var/lib/redis/{{ port|default(6397) }} state=directory
- name: chkconfig redis_{{ port|default(6397) }}
shell: chkconfig --add redis_{{ port|default(6397) }}
- name: systemctl enable redis_{{ port|default(6397) }}
shell: systemctl enable redis_{{ port|default(6397) }}
- name: open firewalld {{ port|default(6397) }}
shell: firewall-cmd --zone=public --add-port={{ port|default(6397) }}/tcp --permanent
- name: restart firewalld
service: name=firewalld state=restarted
- name: start redis_{{ port|default(6397) }}
service: name=redis_{{ port|default(6397) }} state=started
[root@ansible redis]#cat templates/redis.j2 #文件来源于make install之后用redis文件下面的utils下面的install_server.sh安装服务后的拷贝 主要是端口用{{ port|default(6397) }}这个代替
#!/bin/sh
#Configurations injected by install_server below....
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
PIDFILE=/var/run/redis_{{ port|default(6397) }}.pid
CONF="/usr/local/redis/conf/redis_{{ port|default(6397) }}.conf"
REDISPORT="{{ port|default(6397) }}"
###############
# SysV Init Information
# chkconfig: - 58 74
# description: redis_{{ port|default(6397) }} is the redis daemon.
### BEGIN INIT INFO
# Provides: redis_{{ port|default(6397) }}
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Should-Start: $syslog $named
# Should-Stop: $syslog $named
# Short-Description: start and stop redis_{{ port|default(6397) }}
# Description: Redis daemon
### END INIT INFO
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
status)
PID=$(cat $PIDFILE)
if [ ! -x /proc/${PID} ]
then
echo 'Redis is not running'
else
echo "Redis is running ($PID)"
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Please use start, stop, restart or status as first argument"
;;
esac
[root@ansible redis]#grep -v '^#' templates/redis.conf.j2 |grep -v '^$' #文件来源于make install之后用redis文件下面的utils下面的install_server.sh安装服务后的拷贝 主要是端口用{{ port|default(6397) }}这个代替
bind 127.0.0.1 {{ inventory_hostname }}
protected-mode yes
port {{ port|default(6397) }}
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_{{ port|default(6397) }}.pid
loglevel notice
logfile /var/log/redis_{{ port|default(6397) }}.log
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/lib/redis/{{ port|default(6397) }}
{% if inventory_hostname in groups.redis_slave %}
slaveof {{ groups.redis_master[0] }} {{ port|default(6397) }}
{% endif %}
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
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
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
aof-use-rdb-preamble no
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
配置安装yml:
[root@ansible ansible]# cat redis.yml
- hosts: redis
remote_user: root
roles:
- redis
[root@ansible ansible]# ansible-playbook --check redis.yml -e port=7000 # -e port=7000 不是必须的
[root@ansible ansible]# ansible-playbook redis.yml -e port=7000 # -e port=7000 不是必须的
[root@ansible ansible]# ansible-playbook redis.yml -e port=7001 --start-at-task="copy redis_{{ port|default(6397) }}.conf" #安装多个redis的时候可以从这个task开始
对于 sentinel 可以安装在redis服务器,也可以安装到单独的服务器上。
ansible-playbook 安装redis 主从的更多相关文章
- docker安装redis主从以及哨兵
docker安装redis主从以及哨兵 本文使用docker在四台机器上部署一主二从三哨兵的Redis主从结构. 服务器配置 192.168.102.128 主节点 centos7.5 192.168 ...
- ansible playbook 安装docker
1.新增host配置到/etc/ansible/hosts文件中 [docker] 192.168.43.95 2.配置无密码登录 # 配置ssh,默认rsa加密,保存目录(公钥)~/.ssh/id_ ...
- Vagrant Ansible Playbook 安装一群虚拟机
https://docs.ansible.com/ https://favoorr.github.io/2017/01/06/vagrant-virtualbox-vagrantfile-config ...
- ansible playbook部署ELK集群系统
一.介绍 总共4台机器,分别为 192.168.1.99 192.168.1.100 192.168.1.210 192.168.1.211 服务所在机器为: redis:192.168.1.211 ...
- ansible自动安装rabbitmq
ansible playbook 安装rabbitmq单机版,以下脚本在CentOS6.7服务器测试通过. 需要配置本机的yum源,用于安装socat软件. rabbitmq版本和Erlang版本需要 ...
- Redis 安装,主从配置及Sentinel配置自动Failover
1.安装redis 首页地址:http://redis.io/ 下载地址:http://download.redis.io/ 下载最新的源码包 tar -zxvf redis-stable.tar.g ...
- Redis安装及主从配置(转)
一.何为Redis redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合)和zset(有 ...
- Redis安装及主从配置
一.何为Redis redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合)和zset(有 ...
- windows下安装和redis主从配置(通过哨兵控制主从切换)
首先自己先得了解什么是redis,这里就不详做介绍什么是redis了,这篇文章主要讲的是怎么样配置 redis怎样配置主从关系和哨兵控制主从服务器的配置以及应用,就当是给自己记笔记吧! 1.下载red ...
随机推荐
- 详解DNS域名解析系统(域名、域名服务器[根、顶级、授权/权限、本地]、域名解析过程[递归与迭代])
文章转自:https://blog.csdn.net/weixin_43914604/article/details/105583806 学习课程:<2019王道考研计算机网络> 学习目的 ...
- Python课程笔记 (五)
今天主要学习图形用户界面,更多的还是要我们自己去实际操作,课仿佛上了一半就完了,分享一下课程(这里在SixthClass)的源码: https://gitee.com/wang_ming_er/pyt ...
- ahb时序解析
ahb 总线架构 AHB(Advanced High Performance Bus)总线规范是AMBA(Advanced Microcontroller Bus Architecture) V2.0 ...
- triangle leetcode C++
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- 第01课 OpenGL窗口(4)
下面的代码处理所有的窗口消息.当我们注册好窗口类之后,程序跳转到这部分代码处理窗口消息. LRESULT CALLBACK WndProc( HWND hWnd, // 窗口的句柄 UINT uMsg ...
- 跟着老猫来搞GO,集跬步而致千里
上次博客中,老猫已经和大家同步了如何搭建相关的GO语言的开发环境,相信在车上的小伙伴应该都已经搞定了环境了.那么本篇开始,我们就来熟悉GO语言的基础语法.本篇搞定之后,其实期待大家可以和老猫一样,能够 ...
- vue打包后反编译到源代码(reverse-sourcemap)
因为突然的疫情把我困在家了,家里的电脑没有源代码,但是需求还要改,工作还得继续... 从服务器下载了之前上传的打包后的文件,找了一圈反编译方法,得救了,在此记录一下. 1.npm install -- ...
- JVM-内存区域与OOM
本篇博客内容主要参考<深入理解Java虚拟机> 内存区域与内存溢出异常 运行时数据区 Java虚拟机运行时数据区: 程序计数器(Program Counter Register)是一块较小 ...
- IP数据报中如果不分片,分片标志值是什么?
过了好久才解决这个简单的问题,罪过罪过- 答案:如果IP数据报不分片,分片标志DF(Don't Fragment)会被设置为1.分片标志MF(More Fragment)设置为0. 下面是详细解释: ...
- Spring Boot 快速整合Swagger
一.前言 Spring Boot作为当前最为流行的Java web开发脚手架,越来越多的开发者选择用其来构建企业级的RESTFul API接口.这些接口不但会服务于传统的web端(b/s),也会服务于 ...