Linux Shell 实现一键部署Redis6

2023-05-16

redis 前言

Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。

redis 参考

redis下载RedisDesktopManager
downloaddownload

Linux 各系统下载使用参考

Red HatRocky Linux Oracle Linux

AlmaLinux 

ubuntususelinuxesxiRHEL标准安装系统安装参考YUM参考

MobaXterm 远程连接工具

Red Hat Enterprise 9.0 文档Kickstart 生成器
downloaddownloaddownloaddownloaddownloaddownloaddownload参考参考配置参考download参考Kickstart 
版本兼容性

安装 Redis

  • 创建安装自动化脚本

  • 实现在线下载redis,配置redis配置文件,环境变量,防火墙配置,企业微信机器人通知。
  • 以下基于Redhat系统
  • redis目录 /opt/redis/
  • redis 配置文件/opt/redis/conf/
  • redis 持久化数据存储 /opt/redis/data/
  • redis log 输出到/var/log/redis.log
  • redis登录密码Report@123
  • redis端口 6379
  • Redhat 9 functions使用需要执行安装yum install initscripts -y 
  • curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXXXX' #更改自己的企业微信机器人地址 
  • curl -o /etc/yum.repos.d/redhat.repo http://mirrors.aliyun.com/repo/Centos-8.repo #阿里在线repo
  • yum install figlet -y #用于将文字转换为放大艺术字(使用figlet Mysql显示)
vim /redis_install.sh
#!/bin/sh
# -*- coding: utf-8 -*-
# Author: CIASM
# Date: 2022/04/06

<<!
 ____          _ _     
|  _ \ ___  __| (_)___ 
| |_) / _ \/ _` | / __|
|  _ <  __/ (_| | \__ \
|_| \_\___|\__,_|_|___/                                  
!

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

#Define data path variables
data_downloads=/data/downloads

#Define redis path variables
Redis_URL=http://download.redis.io/releases/
Redis_gz=redis-6.2.9.tar.gz
Redis_FILE_DIR=redis-6.2.9
Redis_PREFIX=/opt/redis
Redis_catalogue=/opt
Redis_new=redis
redis_service=/usr/lib/systemd/system/redis.service
 
function install_redis (){
if [ ! -d ${Redis_PREFIX} ];then
mkdir -p $data_downloads
yum install -y gcc gcc-c++ cmake net-tools wget
wget -N -P $data_downloads $Redis_URL/$Redis_gz
tar -xf $data_downloads/$Redis_gz -C $Redis_catalogue
 if [ $? -eq 0 ];then 
   mv $Redis_catalogue/$Redis_FILE_DIR $Redis_catalogue/$Redis_new
   cd $Redis_catalogue/$Redis_new
   make && make install PREFIX=$Redis_PREFIX
   ln -s $Redis_catalogue/$Redis_new/bin/* /usr/local/sbin/
   redis_config
   action "The redis Install Sussess..." /bin/true
   else
	action "The redis Install Failed..." /bin/false 
	exit 1
   fi
   else
	echo -e "\033[31mThe redis already Install...\033[0m"
fi
}
 
function redis_config (){
echo "limits config"
cat >>/etc/security/limits.conf<<EOF
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF
 
echo "system Maximum number of connections"
echo "fs.file-max=65535" >> /etc/sysctl.conf
echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
echo "net.core.somaxconn= 1024" >> /etc/sysctl.conf
echo never > /sys/kernel/mm/transparent_hugepage/enabled
sysctl -p

echo "redis.conf config"
mkdir -p $Redis_PREFIX/conf
mkdir -p $Redis_PREFIX/data
cat >>/opt/redis/conf/redis.conf<<EOF
bind 0.0.0.0
requirepass Report@123
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
loglevel notice
logfile "/var/log/redis.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error no
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./opt/redis/data/
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-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 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
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
EOF
 
echo "redis serves the script"
cat >>$redis_service<<EOF
[Unit]
Description=Redis
After=network.target

[Service]
ExecStart=/opt/redis/bin/redis-server /opt/redis/conf/redis.conf
ExecStop=/opt/redis/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown
Restart=always
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

echo "start redis"
systemctl daemon-reload
systemctl enable --now redis.service
systemctl restart redis.service 

echo "firewall redis port"
firewall-cmd --zone=public --add-port=6379/tcp --permanent
firewall-cmd --reload

echo "rm redis" 
rm -rf $data_downloads/*
}

function Deployment_completion_notification (){
   host_ID=`dmidecode -s system-serial-number | sed -r 's/\s+//g'`
   host_IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2}' | awk 'NR==1'`
   memory_Size=`dmidecode -t memory | grep Size | grep -v No | awk '{sum+=$2} END {printf "%.0fG\n",sum/1^C4}'`
   CPU_Model=`cat /proc/cpuinfo | grep 'model name' | awk '{print $6}' | uniq`
   Disk_size=`fdisk -l | grep "sda:" | awk '{print $3$4}'`
   redhat_version=`cat /etc/redhat-release | grep "release" | awk '{print $6}'`
   redhat_core=`cat /proc/version | grep "version" | awk '{print $3}'`
   redis_server=`systemctl status redis.service | grep "Active" | awk '{print $2}'`
   redis_version=`/opt/redis/bin/redis-cli -v | grep "redis" | awk '{print $2}'`
   redis_port=`netstat -lntp | grep "redis-server" | awk '{print $4}'`
   curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXXX' \
   -H 'Content-Type: application/json' \
   -d '
    {
     "msgtype": "markdown",
      "markdown": {
         "content": " **system check** <font color=\"info\"> complete </font>  \n
         > **Host IP Address** \n
          [http://'$host_IP'](http://'$host_IP') \n
         > **Hardware information** \n
          hostSN:<font color=\"info\"> '$host_ID' </font> \n
          CPU_Model:<font color=\"info\"> '$CPU_Model' </font> \n
          memory_Size:<font color=\"info\"> '$memory_Size' </font> \n
          Disk_size:<font color=\"info\"> '$Disk_size' </font> \n
          System_version:<font color=\"info\"> '$redhat_version' </font> \n
          system_core:<font color=\"info\"> '$redhat_core' </font> \n
         > **redis install** \n
          redis_version:<font color=\"info\"> '$redis_version' </font> \n
          redis_server:<font color=\"info\"> '$redis_server' </font> \n
		  redis_port:<font color=\"info\"> '$redis_port' </font> \n",
      }
   }'
}
 

function main (){
install_redis
Deployment_completion_notification
}
 
main

执行安装

sh /redis_install.sh

企业微信通知

远程连接redis

  • 密码 Report@123
  • IP 地址
  • 端口 6379 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Linux Shell 实现一键部署Redis6 的相关文章

  • ubuntu解决github访问速度慢的一个小tip

    一 通过设置hosts来解决 xff1a 登录http tool chinaz com dns 查询以下域名映射 并分别取访问速度较快的一个ip xff0c 比如我的 github span class token punctuation
  • 搞SLAM装完一个新的ubuntu系统后需要的环境配置

    所有的文件上传百度云 xff1a 链接 https pan baidu com s 1xheyHxPwaD8Tb9QJ6SAHUA 提取码 gmt9 一个搞SLAM的小白 xff0c 新装完ubuntu系统后应该配置这些内容 1 换源2 安
  • 四元数、变换矩阵、欧拉角转换关系

    四元数to变换矩阵 Eigen span class token double colon punctuation span Quaterniond span class token function quaternion span spa
  • 队列queue最简单的复制拷贝方式

    span class token macro property span class token directive hash span span class token directive keyword include span spa
  • 影单:分享一下最近在看的一些电影

    1 千与千寻 电影讲的是少女千寻随爸爸妈妈搬去新的城市 xff0c 开车迷路 xff0c 进入了一个神秘隧道 xff0c 隧道另一边有个风情小镇 xff0c 爸爸妈妈没抵制得了食物的诱惑 xff0c 大吃特吃变成了猪 那是个妖怪的世界 xf
  • conda相关

    安装 ubuntu 18 04 安装conda环境 及 创建虚拟环境 创建虚拟环境 conda create span class token operator span n your env name python span class
  • 几种PCL点云显示方式

    注意添加头文件 xff1a span class token macro property span class token directive hash span span class token directive keyword in
  • 复盘一下slam中常用的几种点云类型

    使用livox雷达常涉及至少3种点云格式 xff0c 一个是livox官方定义的custom格式 xff0c 另外两个就是激光 视觉常用的pcl类型和ros类型 之前总结过Livox雷达驱动程序发布点云格式CustomMsg和pcl Poi
  • [Python]-使用Requests模拟登录

    文章目录 登录说明session操作data序列化 示例代码登录流程验证 在 使用Requests进行HTTP请求与文件上传下载 中介绍了requests库的常用方法 xff0c 本章介绍如何使用request进行用户登录 登录说明 一般页
  • mloam

    以读 pcd xff1a 读取4个激光雷达数据 xff0c input estimator span class token punctuation span span class token function inputCloud spa
  • ROS 工作空间下编译库文件,安装库头文件到devel文件夹

    Hello xff0c 欢迎来到我的博客 我们在ROS工作空间下编程时 xff0c 可能会出现这一种情况 xff1a 我们在一个package下写了一个库 xff0c 而在另一个package要引用这个库 这个时候该怎么处理呢 xff1f
  • js打开新页面的两种方式

    1 点击某一个链接之后跳转到新页面显示 window open http www baidu com blank 2 需要刷新当前页面或者覆盖当前页面 window open http www baidu com self
  • ROS入门教程的学习与总结

    ROS入门教程的学习与总结 1 安装ROS环境2 创建ROS空间3 创建ROS package4 catkin清除命令5 待续 1 安装ROS环境 ROS官网安装参考链接 Linux版本如果是16 04 安装ROS Kinect版本 ava
  • vins-fusion 怎么输出文件? vio_global,vio.txt,vio.csv内容与位置的修改

    提示 xff1a 文章写完后 xff0c 目录可以自动生成 xff0c 如何生成可参考右边的帮助文档 目录 vins fusion 怎么输出文件 xff1f vio global vio txt vio csv内容与位置的修改1 vio g
  • ubuntu18.04安装、使用evo

    ubuntu18 04安装evo 1 切换python版本2 安装pip33 安装evo4 自带test测试5 evo工具介绍6 evo使用6 针对不同数据集的格式以及evo命令 官方连接 xff1a https github com Mi
  • RTKLIB源码及介绍

    目录 1 官网翻译 2 文件下载 1 官网翻译 RTKLIB xff1a 用于 GNSS 定位的开源程序包 下载 版本 日期 适用于 Windows 的二进制 AP 包 带有源程序的完整包 0 2 0 2006 12 16 rtklib 0
  • KITTI数据集基准、转换成tum以及十个groundtruth对应图

    KITTI数据集基准 转换成tum以及十个groundtruth对应图 时间戳的位置gt的位置利用evo进行转换生成kitti基准带时间的tum格式十个路径展示 xff1a 跑vins fusion的时候 xff0c 不知道使用的kitti
  • 【国产可编程逻辑控制器plc调研】

    国产可编程逻辑控制器plc调研 1 高性能PLC xff08 ACxxx系列 xff09 2 中型PLC xff08 AMx00系列 xff09 3 小型PLC xff08 HxU HxS xff09 4 小型紧凑型PLC xff08 Ea
  • 【工业相机接口配置】万兆网口、Camera Link接口、CXP接口

    工业相机接口配置 xff08 万兆网口 Camera Link接口 CXP接口 xff09 万兆网口Camera Link接口CXP接口 目前接触到的工业相机主要有万兆网口 Camera Link接口 CXP接口等不同的接口 另外更常用的是
  • [C++]-yml库yaml-cpp简介

    文章目录 YAML基本语法数据类型对象数组标量引用 yaml cpp库生成器Emitter节点Node数组对象创建解析 yaml cpp是一个yml操作库 YAML YAML YAML Ain t a Markup Language xff

随机推荐