1.挂载数据盘
挂载完成检查如图
[root@GD**IFMAP03 ~]# df -hT /app/redis/
Filesystem Type Size Used Avail Use% Mounted on
/dev/vdc xfs 20G 71M 20G 1% /app/redis
#!/bin/bash
verp=redis-5.0.12.tar.gz
ver=redis-5.0.12
#chown -R redis:redis /app/
cat /etc/group | grep redis &> /dev/null
if [ $? -eq 0 ];then
echo -e "\033[32mgroup redis already exist\033[0m"
else
groupadd redis
echo -e "\033[31mgroup redis creating\033[0m"
fi
cat /etc/passwd | grep redis &> /dev/null
if [ $? -eq 0 ];then
echo -e "\033[32muser redis already exist\033[0m"
else
useradd -d /home/redis -m redis -g redis
echo ‘redis:!QAZ2wsx12‘ | chpasswd
echo -e "\033[31muser redis createing\033[0m"
fi
if rpm -q vim-enhanced wget gcc gcc-c++ make tcl &> /dev/null;then
echo -e "\033[32mwget gcc gcc-c++ make tcl command already install\033[0m"
else
yum install -y vim wget gcc gcc-c++ make tcl
echo -e "\033[31mvim wget gcc gcc-c++ make tcl installing \033[0m"
fi
if ls -ld /tmp/$verp &> /dev/null;then
echo -e "\033[32m$verp package already download\033[0m"
else
wget -P /tmp http://10.24.13.15/$verp
echo -e "\033[31m$verp downloading\033[0m"
fi
if ls -ld /app/redis/$ver &> /dev/null;then
echo -e "\033[32m$ver package already extract\033[0m"
else
tar -zxvf /tmp/$verp -C /app/redis
fi
if [ ! -d /usr/local/redis/$ver ];then
mkdir -p /usr/local/redis/$ver
chown -R redis:redis /usr/local/redis
else
echo -e "\033[32mRedis Install Directory Create\033[0m"
fi
if [ ! -d /usr/local/redis/$ver/bin ];then
echo -e "\033[31mRedis Service Installing \033[0m"
su - redis -c "cd /app/redis/$ver/src/ && make && make test && make install PREFIX=/usr/local/redis/$ver && make test"
else
echo -e "\033[32mRedis Service Prefix Install Finish\033[0m"
fi
if ls -ld /app/redis/$ver/redis.conf.bak &> /dev/null;then
echo -e "\033[32mRedis cfgfile already backup\033[0m"
else
echo -e "\033[31mRedis cfgfile backuping \033[0m"
su - redis -c "cd /app/redis/$ver/ && cp redis.conf redis.conf.bak"
fi
lip=`ip a | grep "scope global noprefixroute" | awk -F"/" ‘{print $1}‘ | awk -F" " ‘{print $2}‘`
sed -i "s/6379/6379/g" /app/redis/$ver/redis.conf
sed -i "s/127.0.0.1/$lip/g" /app/redis/$ver/redis.conf
sed -i "s/daemonize no/daemonize yes/g" /app/redis/$ver/redis.conf
sed -i "s/appendonly no/appendonly yes/g" /app/redis/$ver/redis.conf
sed -i "s/protected-mode yes/protected-mode no/g" /app/redis/$ver/redis.conf
if ls -ld /app/redis/$ver/6379/redis_6379.log &> /dev/null;then
echo -e "\033[32mRedis logfile already exist \033[0m"
else
echo -e "\033[31mRedis logfile creating \033[0m"
su - redis -c "mkdir -p /app/redis/$ver/6379/ && touch /app/redis/$ver/6379/redis_6379.log"
fi
if ls -ld /app/redis/$ver/6379/data &> /dev/null;then
echo -e "\033[32mRedis dir already exist \033[0m"
else
echo -e "\033[31mRedis logfile creating \033[0m"
su - redis -c "mkdir -p /app/redis/$ver/6379/data"
fi
sed -i ‘s/logfile ""/logfile \/app\/redis\/redis-5.0.12\/6379\/redis_6379.log/g‘ /app/redis/$ver/redis.conf
sed -i "s/dir .\//dir \/app\/redis\/$ver\/6379\/data/g" /app/redis/$ver/redis.conf
redispid=`ps -ef|grep redis | grep -v grep | grep -w "redis-server" | awk -F" " ‘{print $2}‘`
if [ ! -z $redispid ];then
echo -e "\033[32mRedis Service Up $redispid\033[0m"
else
su - redis -c "/usr/local/redis/$ver/bin/redis-server /app/redis/$ver/redis.conf"
echo -e "\033[31mRedis Service Starting\033[0m"
fi