当前位置: 首页 > article >正文

Redis部署脚本(完成-第一版)

主要包含redis的一键部署脚本和redis启动脚本文件

当前可以完成一键部署,还需改进语法

install.sh

#!/bin/bash
systemctl stop firewalld
systemctl disable firewalld
#!/bin/bash
if ! command -v yum &> /dev/null; then
    echo -e "\e[31m yum not installed,start install yum... \e[0m\n"
    sudo apt update sudo
    apt install yum
else 
    echo -e "\e[31m yum is installed \e[0m\n"
fi

echo -e "\e[31m Starts verifying whether GCC is installed \e[0m\n"
if ! command -v gcc &> /dev/null; then
    echo -e "\e[31m gcc not installed,start install gcc... \e[0m\n"
    sudo yum install gcc 
else
    echo -e "\e[31m gcc is installed \e[0m\n"
fi

if ! command -v g++ &> /dev/null; then
    echo -e "\e[31m g++ not installed,start install g++... \e[0m\n"
    sudo yum install g++ 
else
    echo -e "\e[31m g++ is installed \e[0m\n" 
fi

echo -e "\e[31m Started upgrading the GCC version \e[0m\n"
if [ "$(gcc -dumpversion)" == "4.8.5" ]; then
    echo -e "\e[31m The GCC version is 4.8.5 to prevent Redis compilation failures and start upgrading GCC... \e[0m\n"
    yum -y install centos-release-scl
    yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
    scl enable devtoolset-9 bash
    echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
    gcc -dumpversion
    if [ "$(gcc -dumpversion)" != "4.8.5" ]; then
        echo -e "\e[31m If the GCC upgrade fails, manually upgrade the GCC version to prevent Redis compilation failures \e[0m\n"
        exit 1
    else
        echo "\e[31m The GCC upgrade is complete \e[0m\n"
        exit 0
    fi
fi


if ! command -v make &> /dev/null; then
    echo -e "\e[31m Make is not installed, start installing make... \e[0m\n"
    sudo yum install make 
else
    echo -e "\e[31m make is installed \e[0m\n"
fi

if ! command -v vim &> /dev/null; then
    echo -e "\e[31m vim does not install,start install vim... \e[0m\n"
    sudo yum install vim 
else
    echo -e "\e[31m vim is installed \e[0m\n" 
fi

echo -e "\e[31m start install Redis \e[0m\n"
REDIS_VERSION="4.0.1"
REDIS_SRC_FILENAME="redis-$REDIS_VERSION.tar.gz"
REDIS_SRC_DIRNAME="redis-$REDIS_VERSION"
tar -xvzf $REDIS_SRC_FILENAME
echo -e "\e[31m The Redis installation is complete \e[0m\n"

echo -e "\e[31m Start compiling Redis \e[0m\n"
cd $REDIS_SRC_DIRNAME
make
make install
echo -e "\e[31m Redis compilation is complete \e[0m\n"
dir1="/data/redis/data"

mkdir -p $dir1
dir2="/etc/redis/"
mkdir -p $dir2

echo -e "\e[31m Configure a Redis configuration file,reids.conf \e[0m\n"
if [ $? -eq 0 ]; then
cat > /etc/redis/6379.conf <<EOF
bind 0.0.0.0
protected-mode no
port 6379
pidfile "/data/redis/redis_6379.pid"
logfile "/data/redis/redis_6379.log"
dir "/data/redis/data"
daemonize yes
requirepass promace@123
appendonly yes
appendfilename "appendonly-41.aof"
EOF
echo -e "\e[31m reids.conf The configuration successful \e[0m\n" 
else
    echo -e "\e[31m reids.conf The configuration failed!!! \e[0m\n" 
fi

#此处目录在redis-4.0.1
current_dir=$(pwd)
cd ../
##此处目录在redis
current_dir2=$(pwd)

cp $current_dir2/redis-init $current_dir2/redis
echo -e "\e[31m Configure the Redis startup script file \e[0m\n"
sed -i '5a EXEC='$current_dir'/src/redis-server' $current_dir2/redis
sed -i '5a CLIEXEC='$current_dir'/src/redis-cli' $current_dir2/redis

mv $current_dir2/redis /etc/init.d/
echo -e "\e[31m The Redis startup script is successfully configured \e[0m\n"
echo -e "\e[31m /etc/init.d/redis The file configuration is successful!  \e[0m\n" 

sudo chmod +x /etc/init.d/redis
sudo chkconfig --add redis
sudo chkconfig redis on


current_dir3=$(pwd)
if [ $? -eq 0 ]; then
cat > $current_dir3/start.sh<<EOF
service redis start
EOF
echo -e "\e[31m start.sh The creation is successful! \e[0m\n"
else
    echo -e "\e[31m start.sh Creation failed! \e[0m\n"
fi

if [ $? -eq 0 ]; then
cat > $current_dir3/stop.sh<<EOF
service redis stop
EOF
echo -e "\e[31m stop.sh The creation is successful! \e[0m\n"
else
    echo -e "\e[31m stop.sh Creation failed! \e[0m\n"
fi


exit 0

redis-init(Redis启动脚本)

#!/bin/sh
# chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
PIDFILE=/data/redis/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"
case "$1" in
    start)
        if [ -f $PIDFILE ]; then
                echo -e "\e[31m $PIDFILE exists, process is already running or crashed \e[0m\n"
                cd /data/redis/
                rm -rf redis_${REDISPORT}.pid
                echo -e "\e[31m Redis Stopping ... ,please re-execute sh start.sh \e[0m\n"
        else
                echo -e "\e[31m Starting Redis server... \e[0m\n"
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]; then
                echo -e "\e[31m $PIDFILE does not exist, process is not running \e[0m\n"
        else
                PID=$(cat $PIDFILE)
                echo -e "\e[31m Stopping ... \e[0m\n"
                kill -9 $PID
                while [ -x /proc/${PID} ]
                do
                    echo -e "\e[31m Waiting for Redis to shutdown ... \e[0m\n"
                    sleep 1
                done
                echo -e "\e[31m Redis stopped \e[0m\n"
        fi
        ;;
    *)
        echo -e "\e[31m Please use start or stop as first argument \e[0m\n"
        ;;
esac


http://www.kler.cn/a/155811.html

相关文章:

  • 【数据结构与算法】第12课—数据结构之归并排序
  • Jetpack 之 Ink API初探
  • 【MySQL】约束
  • 软件工程概论项目(二),node.js的配置,npm的使用与vue的安装
  • 【图像压缩感知】论文阅读:Self-supervised Scalable Deep Compressed Sensing
  • 以色列支付龙头遭DDoS攻击,各地超市加油站等POS机瘫痪
  • shell命令编写
  • 正则表达式从放弃到入门(2):grep命令详解
  • 机器学习---pySpark代码开发
  • 实体类转SQL工具类
  • 在南昌找工作应该上什么网
  • MySQL更改用户权限
  • GitHub Actions 之自动化发布 Maven 项目
  • 也可Adobe Animate
  • C++代码规范(JSF-AV版本)未完待续
  • JavaWeb 添加页面和用户图像展示
  • NAND Flash和NOR Flash的异同
  • 芋道源码ruoyi-vue-pro项目前端yarn下载报错
  • LeedCode刷题---子数组问题
  • 数据库设计之三范式
  • 【计算机视觉】基于OpenCV计算机视觉的摄像头测距技术设计与实现
  • vue中keep-alive的使用
  • 【华为OD题库-049】评论转换输出-java
  • Android 13.0 Camera2 静音时拍照去掉快门声音
  • 条款2:不要滥用宏
  • 【Linux服务器Java环境搭建】05 Node JS安装及环境变量配置