Redis一键安装shell脚本

Redis安装shell脚本

#!/bin/bash
##用法:sh redis-install.sh 7.0.5 (后面跟你需要的版本号)
version=$1
usage(){
echo "usage: $0 version"
}

if [ $# -ne 1 ]
then
usage
exit -1
fi

#Redis安装包下载
cd /usr/local/src
if [ ! -f redis-${version}.tar.gz ]
then
curl -o /usr/local/src/redis-${version}.tar.gz http://download.redis.io/releases/redis-${version}.tar.gz
fi

#Redis依赖包安装
yum clean all
yum makecache fast
yum -y install gcc gcc-c++ tcl

#编译Redis所需要的gcc
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
source /opt/rh/devtoolset-9/enable
#echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
gcc --version

#Redis编译安装
cd /usr/local/src
tar -xvf redis-${version}.tar.gz
cd /usr/local/src/redis-${version}
make PREFIX=/usr/local/redis-${version} install
make test
cd /usr/local
ln -sf redis-${version} redis

#Redis基础配置
egrep -v "^$|^#" /usr/local/src/redis-${version}/redis.conf > /etc/redis.conf
sed -i "s/bind 127.0.0.1/bind 0.0.0.0/g" /etc/redis.conf
sed -i "s/protected-mode yes/protected-mode no/g" /etc/redis.conf
sed -i "s/daemonize no/daemonize yes/g" /etc/redis.conf
sed -i 's/logfile \"\"/logfile \"\/var\/log\/redis.log\"/g' /etc/redis.conf

#PATH配置
echo "export PATH=\$PATH:/usr/local/redis/bin" >>/etc/profile
source /etc/profile

#启动redis服务
cp /usr/local/src/redis-${version}/utils/redis_init_script /etc/init.d/redis
sed -i 's/\/usr\/local\/bin\/redis-server/\/usr\/local\/redis\/bin\/redis-server/g' /etc/init.d/redis
sed -i 's/CLIEXEC=\/usr\/local\/bin\/redis-cli/CLIEXEC=\/usr\/local\/redis\/bin\/redis-cli/g' /etc/init.d/redis
sed -i 's/\/etc\/redis\/\${REDISPORT}.conf/\/etc\/redis.conf/g' /etc/init.d/redis
chkconfig redis on
/etc/init.d/redis start

#查看redis监听端口
netstat -anlp|grep redis

你可能感兴趣的:(Redis,redis,数据库)