上干货:
#!/bin/bash
REDIS_VER=5.0.3
PORT=6379
TOOLS_DIR=/home/sunbox/soft
INSTALL_DIR=/usr/local
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script"
exit 1
fi
# Check network environmental
#NET_NUM=`ping -c 4 www.baidu.com |awk '/packet loss/{print $6}' |sed -e 's/%//'`
#if [ -z "$NET_NUM" ] || [ $NET_NUM -ge 10 ];then
# echo "Please check your internet"
# exit 1
#fi
#安装编译工具
yum install gcc-c++
[ ! -d $TOOLS_DIR ] && mkdir -pv $TOOLS_DIR
cd $TOOLS_DIR
if [ ! -f redis-${REDIS_VER}.tar.gz ]; then
wget http://47.92.71.36:28801/redis-${REDIS_VER}.tar.gz
fi
tar xvf redis-${REDIS_VER}.tar.gz -C $INSTALL_DIR
cd $INSTALL_DIR
[ ! -e $INSTALL_DIR/redis ] && ln -sv $INSTALL_DIR/redis-${REDIS_VER} $INSTALL_DIR/redis
#Compile redis
cd $INSTALL_DIR/redis
make
make PREFIX=$INSTALL_DIR/redis install
[ ! -d etc ] && mkdir etc
\cp -f redis.conf etc/
sed -i 's#daemonize no#daemonize yes#g' etc/redis.conf
sed -i 's#protected-mode yes#protected-mode no#g' etc/redis.conf
sed -i 's#port 6379#port '$PORT'#g' etc/redis.conf
sed -i 's#bind 127.0.0.1#bind 0.0.0.0#g' etc/redis.conf
sed -i 's/# requirepass foobared/requirepass password@123456/' etc/redis.conf
#auto start
if [ `grep redis-server /etc/rc.d/rc.local | wc -l` -eq 0 ]; then
echo "${INSTALL_DIR}/redis/bin/redis-server ${INSTALL_DIR}/redis/etc/redis.conf" >> /etc/rc.d/rc.local
fi
firewall-cmd --add-port=$PORT/tcp --permanent
firewall-cmd --reload
#Start redis-server
${INSTALL_DIR}/redis/bin/redis-server ${INSTALL_DIR}/redis/etc/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf