Redis 4.0.11 初始化安装脚本(shell)

#!/bin/bash
echo "Redis 初始化安装脚本"
<<COMMENT
  注:
   AUTHOR: ws, 779269823@qq.com
   CREATED: 2019.11.06
   VERSION: 1.0
   Redis版本:4.0.11
   CentOS Linux release 7.6.1810 (Core) 
COMMENT

#安装依赖库
yum install -y cpp binutils glibc-kernheaders glibc-common glibc-devel gcc make wget    

#下载解压
cd /opt
wget -c http://download.redis.io/releases/redis-4.0.11.tar.gz
if [ -f /opt/redis-4.0.11.tar.gz ];then
    tar zxvf redis-4.0.11.tar.gz
    mv redis-4.0.11 /usr/local/redis
    cd /usr/local/redis
    make
    cd src/
    make install 
else
    echo "文件不存在!"
    exit;
fi

#配置系统参数
echo 512 > /proc/sys/net/core/somaxconn
echo 1 > /proc/sys/vm/overcommit_memory
echo never > /sys/kernel/mm/transparent_hugepage/enabled
sed -i '/\# End of file/i * soft nofile 65535' /etc/security/limits.conf
sed -i '/\# End of file/i * hard nofile 65535' /etc/security/limits.conf
echo ulimit -SHn 65535 >> /etc/profile
source /etc/profile

#Redis配置文件
sed -e "s/#.*//g" /usr/local/redis/redis.conf | awk '{if (length !=0) print $0}'
sed -i '136s/daemonize no/daemonize yes/' /usr/local/redis/redis.conf    
sed -i '69s/127.0.0.1/0.0.0.0/' /usr/local/redis/redis.conf 
sed -i '88s/protected-mode yes/protected-mode no/' /usr/local/redis/redis.conf
sed -i 's/^appendonly yes/appendonly no/' /usr/local/redis/redis.conf  
sed -i 's/^dbfilename dump.rdb/dbfilename dump.rdb/' /usr/local/redis/redis.conf 
sed -i 's/^dir .\//dir \/backup/' /usr/local/redis/redis.conf 
echo logfile /var/log/redis.log >> /usr/local/redis/redis.conf
mkdir -p /etc/redis
ln -s /usr/local/redis/redis.conf /etc/redis/6379.conf   
ln -s /usr/local/redis/utils/redis_init_script /etc/init.d/redisd    
/sbin/chkconfig redisd on

#(开启redis服务,服务名为:redisd)
systemctl start redisd   

#redis-cli  
netstat -ntpl|grep redis
echo "Redis 部署完成!"
echo " "
echo "如果系统是Centos 7在安装完毕后检查防火墙,可执行以下命令来放行redis 外部通信。"
echo "firewall-cmd --zone=public --add-port=6379/tcp --permanent"    
echo "firewall-cmd --reload"
echo "firewall-cmd --zone= public --query-port=6379/tcp"

systemctl stop redisd
systemctl start redisd
 

  

posted on 2019-11-06 21:01  数驿小栈  阅读(282)  评论(0)    收藏  举报