注释:使用方法为 # ./redis.sh version ----version为官网版本号
#!/bin/bash
version=$1
serverurl='download.redis.io'
urlstatus=$(curl -s -m 5 -IL $serverurl|grep 200)
redis_home=/usr/local/redis
redis_log=/usr/local/redis/log
redis_dump=/usr/local/redis/dump
redis_conf=/usr/local/redis/etc
redis_pid=/usr/local/redis/run
redis_passwd=`date +%s |sha256sum |base64 |head -c 10 ;echo`
export PATH=$PATH:$redis_home/bin
if [ -z "$version" ]; then
echo "Please input version" && exit 1
fi
if [ "$urlstatus" == "" ];then
echo "urlstatus is OFF" && exit 1
fi
echo "Download redis from official website"
cd /usr/local/src
rm -rf redis-*.tar.gz
wget http://download.redis.io/releases/redis-"$version"'.tar.gz'
tar xzf redis-"$version"'.tar.gz'
cd redis-"$version"
make && make PREFIX="$redis_home" install
echo "ADD script and configuration file"
mkdir -p $redis_log $redis_conf $redis_dump $redis_pid
cd $redis_conf && touch redis.conf
cat /dev/null >redis.conf
echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf && sysctl -p
echo "daemonize yes" >> redis.conf
echo "bind 0.0.0.0" >>redis.conf
echo "maxmemory 1024mb" >>redis.conf
echo "pidfile $redis_pid/redis.pid" >>redis.conf
echo "port 6379" >>redis.conf
echo "tcp-keepalive 0" >>redis.conf
echo "loglevel notice" >>redis.conf
echo "logfile "$redis_log"/redis.log" >>redis.conf
echo "databases 16" >>redis.conf
echo "rdbcompression yes" >>redis.conf
echo "dbfilename dump.rdb" >>redis.conf
echo "dir $redis_dump" >>redis.conf
echo "stop-writes-on-bgsave-error yes" >>redis.conf
echo "requirepass $redis_passwd" >>redis.conf
echo "save 60 1000" >>redis.conf
$redis_home/bin/redis-server $redis_conf/redis.conf
echo "Redis password is $redis_passwd"