#!/bin/bash
. ./bin/method.sh
redis_path=$(cd "$(dirname "$0")" && pwd)
redis_password_num=$(grep -n redis_password $redis_path/bin/redis.conf |awk -F ':' '{print $1}')
redis_cluster_password_num=$(grep -n redis_requirepass $redis_path/bin/redis_cluster.conf|awk -F ':' '{print $1}')
redis_cluster_masterauth_num=$(grep -n redis_masterauth $redis_path/bin/redis_cluster.conf|awk -F ':' '{print $1}')
redis_data=$redis_path/data
system_path=$(dirname $(cd "$(dirname "$0")" && pwd))
system_cpu=$(lscpu |grep 'Architecture:' |awk '{print $2}')
system_cpuname=$(lscpu |grep 'Model name' |awk '{print $3}')
system_version=$(cat /etc/os-release |grep '^NAME'|awk -F '=' '{print $2}')
system_ip=$(ip a|grep inet|grep -v inet6|grep -v 127.0.0.1|awk -F " " '{print $2}'|awk -F "/" '{print $1}'|head -n 1)
#system_ip=$(ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"|head -n 1)
echo "CPU架构:"$system_cpu
#echo "CPU名称:"$system_cpuname
echo "操作系统:"$system_version
if [[ $system_cpu == 'aarch64' ]] && [[ $system_cpuname == 'Kunpeng-920' ]];then
cp -r $redis_path/version/aarch64/Kylin_Linux_Advanced_Server/* $redis_path/bin
elif [[ $system_cpu == 'x86_64' ]];then
if [[ $system_version =~ "CentOS Linux" ]];then
cp -r $redis_path/version/x86_64/centos/* $redis_path/bin
elif [[ $system_version == 'Ubuntu' ]];then
cp -r $redis_path/version/x86_64/ubuntu/* $redis_path/bin
fi
fi
chmod 755 $redis_path/bin/*
#配置选择redis部署模式:
#单节点
#集群-3台-1台
echo "目前支持以下3种部署模式:"
echo "1. redis单节点部署。"
echo "2. redis 6个节点 1台服务器集群部署"
echo "3. redis 6个节点 3台服务器集群部署"
read -p "请选择部署的模式:" option
if [[ $option -eq '1' ]];then
#单节点
echo "开始初始化redis(如确定为默认值,则敲回车即可)"
rm -rf $redis_path/data/*
cp $redis_path/bin/redis.conf $redis_path/config/redis.conf
sed -i "s?redis_dir?$redis_data?" $redis_path/config/redis.conf
read -p "请输入redis的端口号(默认6379):" redis_port
while [ 1 ];do
if [[ $redis_port =~ ^[0-9]*$ ]];then
if [[ $redis_port != '' ]];then
sed -i "s?redis_port?$redis_port?" $redis_path/config/redis.conf
else
sed -i "s?redis_port?6379?" $redis_path/config/redis.conf
fi
break
else
read -p "端口需要设置为数字,请重新设置:" redis_port
fi
done
read -p "请输入需要设置的redis密码(默认不设置密码):" redis_password
redis_password_str='requirepass '$redis_password
if [[ $redis_password != '' ]];then
sed -i "$redis_password_num i $redis_password_str" $redis_path/config/redis.conf
fi
cp $redis_path/bin/start_single.sh $redis_path/start.sh
elif [[ $option -eq '2' ]];then
#1台服务器集群
echo "开始初始化redis(如确定为默认值,则敲回车即可)"
read -p "请确认,服务器IP是否为$system_ip (Y/y):" system_ip_a
while [ 1 ];do
if [[ $system_ip_a != 'Y' ]] && [[ $system_ip_a != 'y' ]];then
read -p "请输入服务器的IP地址:" system_ip
if [[ $system_ip != '2' ]];then
echo "输入IP错误,请重新输入!"
continue
fi
fi
break
done
# 获取端口,并检查端口
read -p "请输入redis 6个集群节点的端口号,用‘,’隔开(默认为6379,6380,6381,6382,6383,6384):" redis_port
redis_port_list=(`echo $redis_port|awk -F "," '{print $1}'` `echo $redis_port|awk -F "," '{print $2}'` `echo $redis_port|awk -F "," '{print $3}'` `echo $redis_port|awk -F "," '{print $4}'` `echo $redis_port|awk -F "," '{print $5}'` `echo $redis_port|awk -F "," '{print $6}'`)
if [[ $redis_port = '' ]];then
redis_port="6379,6380,6381,6382,6383,6384"
redis_port_list=(`echo $redis_port|awk -F "," '{print $1}'` `echo $redis_port|awk -F "," '{print $2}'` `echo $redis_port|awk -F "," '{print $3}'` `echo $redis_port|awk -F "," '{print $4}'` `echo $redis_port|awk -F "," '{print $5}'` `echo $redis_port|awk -F "," '{print $6}'`)
elif [[ ${#redis_port_list[@]} == '6' ]];then
for i in ${redis_port_list[@]}
do
if [[ $i =~ ^[0-9]*$ ]];then
if [[ $i != '' ]];then
sed -i "s?redis_port?$redis_port?" $redis_path/config/redis.conf
else
echo "有端口输入为空,请重新输入!"
exit
fi
else
read -p "端口需要设置为数字,请重新输入!"
exit
fi
done
else
echo "端口数量过多或过少,请重新输入!"
exit
fi
# 获取redis密码
read -p "请输入需要设置的redis密码(默认不设置密码):" redis_password
redis_password_str='requirepass '$redis_password
redis_masterauth_str='masterauth '$redis_password
if [[ -e $redis_path/cluster_info ]];then
echo > $redis_path/cluster_info
else
touch $redis_path/cluster_info
fi
# 执行初始化
for i in ${redis_port_list[@]}
do
if [[ -e $redis_path/data/$i ]];then
rm -rf $redis_path/data/$i/*
else
mkdir $redis_path/data/$i
fi
cp -r $redis_path/bin/redis_cluster.conf $redis_path/data/$i/redis.conf
# 修改data目录
redis_data_cluster=$redis_path'/data/'$i
sed -i "s?redis_dir?$redis_data_cluster?" $redis_path/data/$i/redis.conf
# 修改端口
sed -i "s?redis_port?$i?" $redis_path/data/$i/redis.conf
# 修改密码
if [[ $redis_password != '' ]];then
sed -i "$redis_cluster_password_num i $redis_password_str" $redis_path/data/$i/redis.conf
sed -i "$redis_cluster_masterauth_num i $redis_masterauth_str" $redis_path/data/$i/redis.conf
fi
echo $system_ip:$i >> $redis_path/cluster_info
done
# 拷贝redis启动脚本
cp $redis_path/bin/start_cluster.sh $redis_path/start.sh
# 判断是否直接创建redis集群
read -p "是否现在创建redis集群(Y/y)" create_cluster
if [[ $create_cluster == 'Y' ]] || [[ $create_cluster == 'y' ]];then
echo "正在启动Redis进程!"
sh $redis_path/start.sh
sleep 5
echo "新建集群中"
if [[ $redis_password == '' ]];then
$redis_path/bin/redis-cli --cluster create `cat $redis_path/cluster_info|grep $system_ip|sed -n 1p` `cat $redis_path/cluster_info|grep $system_ip|sed -n 2p` `cat $redis_path/cluster_info|grep $system_ip|sed -n 3p` `cat $redis_path/cluster_info|grep $system_ip|sed -n 4p` `cat $redis_path/cluster_info|grep $system_ip|sed -n 5p` `cat $redis_path/cluster_info|grep $system_ip|sed -n 6p` --cluster-replicas 1
else
$redis_path/bin/redis-cli --cluster create `cat $redis_path/cluster_info|grep $system_ip|sed -n 1p` `cat $redis_path/cluster_info|grep $system_ip|sed -n 2p` `cat $redis_path/cluster_info|grep $system_ip|sed -n 3p` --cluster-replicas 1 -a $redis_password
fi
fi
elif [[ $option -eq '3' ]];then
# 3台服务器集群
echo "开始初始化redis(如确定为默认值,则敲回车即可)"
read -p "请输入部署的三台服务器IP:" redis_ip
redis_ip_list=(`echo $redis_ip|awk -F "," '{print $1}'` `echo $redis_ip|awk -F "," '{print $2}'` `echo $redis_ip|awk -F "," '{print $3}'`)
while [ 1 ];do
for i in ${redis_ip_list[@]}
do
check_ipaddr $i
done
break
done
# 获取端口,并检查端口
read -p "请输入redis台服务器的两个集群端口号,用‘,’隔开(默认为6380,6381):" redis_port
redis_port_list=(`echo $redis_port|awk -F "," '{print $1}'` `echo $redis_port|awk -F "," '{print $2}'`)
if [[ $redis_port = '' ]];then
redis_port="6380,6381"
redis_port_list=(`echo $redis_port|awk -F "," '{print $1}'` `echo $redis_port|awk -F "," '{print $2}'`)
elif [[ ${#redis_port_list[@]} == '2' ]];then
for i in ${redis_port_list[@]}
do
if [[ $i =~ ^[0-9]*$ ]];then
if [[ $i != '' ]];then
sed -i "s?redis_port?$redis_port?" $redis_path/config/redis.conf
else
echo "有端口输入为空,请重新输入!"
exit
fi
else
read -p "端口需要设置为数字,请重新输入!"
exit
fi
done
else
echo "端口数量过多或过少,�
没有合适的资源?快使用搜索试试~ 我知道了~
Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写、支持网络
需积分: 10 0 下载量 116 浏览量
2022-08-12
09:32:20
上传
评论
收藏 65.61MB GZ 举报
温馨提示
Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API
资源详情
资源评论
资源推荐
收起资源包目录



















































共 40 条
- 1


























兵兵呀
- 粉丝: 52
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 实训报告-网页制作与网站建设项目实战.doc
- 试论互联网+时代事业单位档案管理创新.docx
- PLC控制中央空调节能改造方案设计书1.doc
- 互联网+会计时代-高职《管理会计》课程改革探究.docx
- 基于SNAP网络的实验室监控系统研究设计.doc
- 嵌入式系统程序可移植性设计方案及性能优化.doc
- 单片机电子台历设计方案.docx
- 2017年广西公需科目-“互联网+”开放合作考试及标准答案2(90分).docx
- 抢答器PLC控制系统设计-河南工业大学.doc
- 培训师大计算机采集处理系统.pptx
- 大数据在健康医疗行业中应用概况.pptx
- 慧锦校园网络布线系统措施设计方案.doc
- 机械产品和零件的计算机辅助设计.docx
- 《数据库课程设计方案》实验任务书学时.doc
- 项目管理中如何建立高绩效的研发项目团队.docx
- 基于51单片机的多路温度采集控制系统方案设计书.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

评论0