redis一键安装

#!/bin/bash  
##安装redis单机版
redis_install () { 
    rpm -q wget 
 if [ $? -ne 0 ];then
    yum install wget -y 
fi
##创建redis安装目录
if [ !  -d /opt/redis_cluster ];then
    mkdir -p /opt/redis_cluster/6379/{conf,logs,pid}
fi

#创建redis数据目录
if [ ! -d /data/redis ];then
    mkdir -p /data/redis/6379
fi

#创建redis下载目录
if [ ! -d /opt/soft ];then
    mkdir -p /opt/soft
fi

##下载redis安装包
redis_url=http://download.redis.io/releases/redis-3.2.9.tar.gz
wget -P /opt/soft $redis_url
redis_package=`echo $redis_url|awk -F"/" ‘{print $5}‘`
cd /opt/soft
tar -xvzf $redis_package -C /opt/redis_cluster
cd /opt/redis_cluster/redis-3.2.9
make 
if [ $? -eq 0 ];then
    make install 
fi

cp redis.conf /opt/redis_cluster/6379/conf/
IP=`hostname -I |awk ‘{print $1}‘`
cd /opt/redis_cluster/6379/conf

##修改配置文件,修改redis绑定地址
sed -i "/^bind/s/127.0.0.1/$IP/" redis.conf 

##修改redis后台启动
sed -i ‘/^daemonize/s/no/yes/‘ redis.conf

##修改pid存放目录
sed -i ‘/^pidfile//var/run//opt/redis_cluster/6379/pid/‘ redis.conf

##修改log存放目录
sed -i ‘/^logfile/""@/opt/redis_cluster/6379/logs/‘ redis.conf

#修改数据存放目录
sed -i ‘/^dir//@/data/redis/6379/@‘ redis.conf
}
redis_install 

##启动redis服务
redis-server /opt/redis_cluster/6379/conf/redis.conf

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

相关推荐