Redis & Sentinel 安装脚本

#!/bin/bash

# 判断是否为root用户,不是root用户提示退出

if [[ $EUID -ne 0 ]]; then
?? echo "This script. must be run as root" 1>&2
?? exit 1
fi

?

# 安装必要的组件

yum install -y gcc

?

#?下载redis源代码

cd /tmp

wget -P /tmp?http://download.redis.io/releases/redis-3.2.1.tar.gz

?

# 对比文件下载是否正确

echo 26c0fc282369121b4e278523fce122910b65fbbf ?redis-3.2.1.tar.gz > /tmp/download.txt

sha1sum -c download.txt

if [ $? -ne 0 ]
then
? echo "The Download File is not Correct, Please Download it again."

? exit 0
fi

?

# 编译安装

tar xf redis-3.2.1.tar.gz

cd redis-3.2.1

make

make install

?

# 创建组和用户

groupadd redis

useradd -g redis redis

?

# LOG文件存放位置

mkdir /var/log/redis

chown?redis:redis /var/log/redis

?

# 当前IP地址

IP=`ifconfig eth0 | grep "inet " | awk ‘{ print $2}‘`

?

# Redis服务开机运行

echo "[Unit]" >?/usr/lib/systemd/system/redis.service?
echo "Description=Redis persistent key-value database" >>?/usr/lib/systemd/system/redis.service?
echo "After=network.target" >>?/usr/lib/systemd/system/redis.service?
echo "[Service]" >>?/usr/lib/systemd/system/redis.service??
echo "Type=forking" >>?/usr/lib/systemd/system/redis.service??
echo "ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf" >>?/usr/lib/systemd/system/redis.service??

echo "ExecStop=/usr/local/bin/redis-cli -h ${IP} shutdown" >>?/usr/lib/systemd/system/redis.service??

echo "User=redis" >>?/usr/lib/systemd/system/redis.service??
echo "Group=redis" >>?/usr/lib/systemd/system/redis.service??
echo "[Install]" >>?/usr/lib/systemd/system/redis.service??

echo "WantedBy=multi-user.target" >>?/usr/lib/systemd/system/redis.service

?

# Redis Sentinel 服务开机运行

echo "[Unit]" >?/usr/lib/systemd/system/redis-sentinel.service?

echo "Description=Redis Sentinel" >>?/usr/lib/systemd/system/redis-sentinel.service?

echo "After=network.target" >>?/usr/lib/systemd/system/redis-sentinel.service?

echo "[Service]" >>?/usr/lib/systemd/system/redis-sentinel.service??

echo "Type=forking" >>?/usr/lib/systemd/system/redis-sentinel.service??

echo "ExecStart=/usr/local/bin/redis-sentinel /etc/redis/sentinel.conf" >>?/usr/lib/systemd/system/redis-sentinel.service??

echo "ExecStop=/usr/local/bin/redis-cli -h ${IP} -p 26379 shutdown" >>?/usr/lib/systemd/system/redis-sentinel.service??

echo "User=redis" >>?/usr/lib/systemd/system/redis-sentinel.service??

echo "Group=redis" >>?/usr/lib/systemd/system/redis-sentinel.service??

echo "[Install]" >>?/usr/lib/systemd/system/redis-sentinel.service??

echo "WantedBy=multi-user.target" >>?/usr/lib/systemd/system/redis-sentinel.service

?

# redis 服务限制

mkdir?/etc/systemd/system/redis.service.d/

echo "[Service]" >?/etc/systemd/system/redis.service.d/limits.conf?

echo "LimitNOFILE=65535" >> /etc/systemd/system/redis.service.d/limits.conf

?

# 启用开机自动运行

systemctl enable redis.service

systemctl enable redis-sentinel.service

?

# 禁用selinux

sed -i ‘s/SELINUX=enforcing/SELINUX=disable/‘?/etc/selinux/config

# 系统优化

echo "net.core.somaxconn=4096" >> /etc/sysctl.conf

echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local

chmod +x /etc/rc.local

echo "vm.overcommit_memory=1" >> /etc/sysctl.conf

echo "*? soft? nofile? 65535" >>?/etc/security/limits.conf

echo "?* ?hard? nofile? 65535" >>?/etc/security/limits.conf

echo "?* ?soft? nproc? 65535" >>?/etc/security/limits.conf

echo "?* ?hard? nproc? 65535" >>?/etc/security/limits.conf

echo "net.ipv4.tcp_tw_recycle=1"?>> /etc/sysctl.conf

?

# 别名

echo "alias redis=‘redis-cli -h ${IP}‘" >> /etc/profile

echo "alias sentinel=‘redis-cli -h ${IP} -p 26379‘" >> /etc/profile

?

# 修改时区

/bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

?

#Redis配置文件存放位置

mkdir /etc/redis

?

# 修改配置文件redis.conf

echo "bind ${IP}" > /etc/redis/redis.conf

echo "protected-mode no" >> /etc/redis/redis.conf

echo "tcp-backlog 4096" >> /etc/redis/redis.conf

echo "timeout 300" >> /etc/redis/redis.conf

echo "tcp-keepalive 60" >> /etc/redis/redis.conf

echo "daemonize yes" >> /etc/redis/redis.conf

echo "supervised systemd" >> /etc/redis/redis.conf

echo "logfile /var/log/redis/redis.log" >> /etc/redis/redis.conf

echo "dir /var/log/redis" >> /etc/redis/redis.conf

echo "maxclients 10000" >> /etc/redis/redis.conf

echo "maxmemory 4G" >> /etc/redis/redis.conf

echo "maxmemory-policy volatile-lru" >> /etc/redis/redis.conf

echo "appendonly no" >> /etc/redis/redis.conf

echo "slowlog-max-len 512" >> /etc/redis/redis.conf

echo "client-output-buffer-limit slave 512mb 256mb 300" >> /etc/redis/redis.conf

?

# 修改配置文件sentinel.conf

echo "port 26379" > /etc/redis/sentinel.conf

echo "bind ${IP}" >> /etc/redis/sentinel.conf

echo "dir /var/log/redis" >> /etc/redis/sentinel.conf

echo "sentinel monitor mymaster ${IP} 6379 2" >> /etc/redis/sentinel.conf

echo "maxclients 10" >> /etc/redis/sentinel.conf

echo "logfile /var/log/redis/sentinel.log" >> /etc/redis/sentinel.conf

echo "daemonize yes" >> /etc/redis/sentinel.conf

echo "sentinel down-after-milliseconds mymaster 5000" >> /etc/redis/sentinel.conf

echo "sentinel failover-timeout mymaster 60000" >> /etc/redis/sentinel.conf

Redis & Sentinel 安装脚本

时间: 2024-10-10 04:51:56

Redis & Sentinel 安装脚本的相关文章

Redis自动化安装脚本

redis自动安装脚本: 安装目录:/usr/local/redis 二进制文件:/usr/local/bin 配置文件:/usr/local/redis/etc,配置文件自己根据自身的业务去配置,这里只是一个空文件. 日志文件:/usr/local/redis/logs 数据文件:/usr/local/redis/dump #!/bin/bash Soft_dir="/home/tools" Download_URL="http://download.redis.io/re

【redis运维】redis自动安装脚本(只安装redis)

Redis自动安装部署 本文总共分为4个部分: redis自动安装脚本目录结构说明: redis自动安装脚本内容: redis的操作系统服务脚本说明: 本文引用的资料链接地址. 说明:本文未涉及redis内存分配器部分的内容. 第一部分 Redis自动安装脚本目录结构说明: # ls 查看当前目录包含以下3个文件 -- install_redis.sh        # redis自动安装脚本 -- redis-2.8.9.tar.gz      # redis安装包(需make,make te

Redis Sentinel安装与部署,实现redis的高可用

前言 对于生产环境,高可用是避免不了要面对的问题,无论什么环境.服务,只要用于生产,就需要满足高可用:此文针对的是redis的高可用. 接下来会有系列文章,该系列是对spring-session实现分布式集群session的共享的完整阐述,同时也引伸出缓存的实现:而此篇是该系列的第一篇. github地址:https://github.com/youzhibing/redis 环境准备 redis版本:redis-3.0.0 linux:centos6.7 ip:192.168.11.202,

redis+sentinel 安装与配置

redis安装与配置 环境信息: Master:10.10.56.3 Centos6.8Slave:10.10.56.4 Centos6.8 开始安装redis服务 # 下载安装$ wget http://download.redis.io/releases/redis-3.0.0.tar.gz # 解压$ tar xzf redis-3.0.0.tar.gz # 切换到目录$ cd redis-3.0.0 # 编译$ make 复制文件cp redis-benchmark redis-cli

linux下redis自动安装脚本

#!/bin/bash yum -y install wget wget http://download.redis.io/releases/redis-3.2.3.tar.gz tar xf redis-3.2.3.tar.gz cd /home/redis/redis-3.2.3 make cd /home/redis/redis-3.2.3 make PREFIX=/usr/local/redis install cp /home/redis/redis-3.2.3/redis.conf 

redis-4.0.1 源码一键安装脚本(centos 7)

#!/usr/bin/env bash set -e #定义下载路径: SRC='/usr/local/src' #定义redis 目录: REDISDIR='/usr/local/redis' #定义redis 密码: REDISPAS="$(openssl rand -base64 32)" && echo ${REDISPAS} > /root/.REDIS_PAS #从官网下载redis 源码包: wget -O ${SRC}/redis-4.0.1.ta

如何在linux平台上安装redis(附自动安装脚本)

1.Redis的简单介绍 Redis是一种高级key-value数据库.它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富.有字符串,链表,集合和有序集合.支持在服务器端计算集合的并,交和补集(difference)等,还支持多种排序功能.所以Redis也可以被看成是一个数据结构服务器. Redis的所有数据都是保存在内存中,然后不定期的通过异步方式保存到磁盘上(这被称为"半持久化模式");也可以把每一次数据变化都写到一个append onlyfile(aof)里

Redis Sentinel高可用架构

Redis目前高可用的架构非常多,比如keepalived+redis,redis cluster,twemproxy,codis,这些架构各有优劣,今天暂且不说这些架构,今天主要说说redis sentinel高可用架构. 它的主要功能有以下几点 不时地监控redis是否按照预期良好地运行; 如果发现某个redis节点运行出现状况,能够通知另外一个进程(例如它的客户端); 能够进行自动切换.当一个master节点不可用时,能够选举出master的多个slave(如果有超过一个slave的话)中

redis sentinel哨兵模式集群搭建教程

1.环境说明 我们将使用192.168.220.128.192.168.220.129.192.168.220.130三台机器搭建sentinel集群 当前我们已在192.168.220.128上按redis安装教程安装了redis,192.168.220.129和192.168.220.130两台上没有安装 2.配置并启动192.168.220.128上的sentinel 2.1修改conf/redis.conf,配置masterauth字段值 2.2修改conf/sentinel.conf,