Linux script one-click install redis

Upload redis-5.0.5.tar.gz to the /data/redis directory, and then edit the script as follows

#!/bin/bash
#接收参数:redis压缩包绝对路径
src=$1
#接收参数:redis安装绝对路径
target=$2
echo $src
unzipParentDir=${src%/*}
temp=${src%t*}
#解压缩后的目录
unzipDir=${temp%.*}
echo "directory :"$unzipParentDir
echo "file path :"$unzipDir
#unzip tar file to current directory
#解压缩
tar -xzvf $src -C $unzipParentDir
#进入解压后的目录
cd $unzipDir
echo `pwd`
#编译
make
#安装
make PREFIX=$target install
#复制redis配置文件
cp -f redis.conf $target"/"bin
#进入安装目录下的bin目录
cd $target"/bin"
#支持远程连接
sed -i 's|bind 127.0.0.1|# bind 127.0.0.1|' redis.conf
#设置redis密码,默认密码123
sed -i 's|# requirepass foobared|requirepass 123|' redis.conf
#redis服务后台启动
sed -i 's|daemonize no|daemonize yes|' redis.conf
#启动redis
./redis-server redis.conf
#开放redis防火墙端口
iptables -A INPUT -p tcp --dport 6379 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 6379 -j ACCEPT
#保存规则
service iptables save

Execute the shell script redis.sh, and pass in two parameters here: the first parameter is the absolute path of the redis installation package /home/redis/redis-5.0.3.tar.gz, and the second parameter is the absolute path to be installed to Path /home/redis

[root@localhost /]# cd /data/redis/
[root@localhost redis]# ./redis.sh /data/redis/redis-5.0.5.tar.gz /data/redis

Guess you like

Origin blog.csdn.net/qq_40250122/article/details/112779557