2 Star 2 Fork 4

冰羽... / shell

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
redis.sh 2.52 KB
一键复制 编辑 原始数据 按行查看 历史
root 提交于 2020-06-22 10:21 . 解决持久化报错问题
#!/bin/bash
Version=`cat /etc/redhat-release |grep "CentOS Linux release 7"`
echo -e "\033[32m Please enter the path(Example: /usr/local/redis): \033[0m"
read Dir
if [ -z "$Dir" ]; then
echo -e "\033[32m Using the default path /usr/local/redis :\033[0m"
Dir=/usr/local/redis
echo $Dir
else
echo -e "\033[32m Your input $Path :\033[0m"
echo $Dir
fi
echo -e "\033[32m Please enter the running user: \033[0m"
read User
if [ -z "$Dir" ]; then
echo -e "\033[32m Using the default redis :\033[0m"
Dir=redis
echo redis
else
echo -e "\033[32m Your input $Path :\033[0m"
echo $User
fi
useradd $User
echo -e "\033[32m Please enter the redis password: \033[0m"
read Pwd
if [ ! -d "$Dir" ]; then
yum -y install gcc gcc-c++ libstdc++-devel tcl wget vim tree gcc gcc-c++ autoconf curl-devel ruby ruby-devel rubygems rpm-build
mkdir -p $Dir
echo -e "\033[32m Download redis3.2.6... \033[0m"
wget http://mirror.cnop.net/redis/redis-3.2.6.tar.gz
tar -zxvf redis-3.2.6.tar.gz && mv redis-3.2.6/* $Dir && cd $Dir
make
echo -e "\033[32m make successed... \033[0m"
make test
echo -e "\033[32m make test successed... \033[0m"
sed -i 's/daemonize no/daemonize yes/' $Dir/redis.conf
echo "maxmemory 6442450944" >>$Dir/redis.conf
echo "masterauth $Pwd" >>$Dir/redis.conf
echo "requirepass $Pwd" >>$Dir/redis.conf
sed -i "s@bind 127.0.0.1@#bind 127.0.0.1@g" $Dir/redis.conf
echo "stop-writes-on-bgsave-error no" >>$Dir/redis.conf
chown $User.$User $Dir
cp $Dir/src/redis-trib.rb /usr/local/bin/
cp $Dir/src/redis-cli /usr/local/bin/
cp $Dir/src/redis-server /usr/local/bin/
cp $Dir/src/redis-sentinel /usr/local/bin/
chown $User.$User /usr/local/bin/redis*
echo "vm.overcommit_memory = 1">>/etc/sysctl.conf
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo -e "\033[32m Starting redis... \033[0m"
if [ ! -n "$Version" ]; then
#for centos 6,5
su - $User -c "redis-server $Dir/redis.conf"
echo "su - $User -c \"redis-server $Dir/redis.conf\"" >> /etc/rc.d/rc.local
else
#for centos 7+
sysctl vm.overcommit_memory=1
su - $User -c "redis-server $Dir/redis.conf"
echo "su - $User -c \"redis-server $Dir/redis.conf\"" >> /etc/rc.d/rc.local
fi
# echo -e "\033[32m Seting iptables... \033[0m"
# /sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT
# /etc/rc.d/init.d/iptables save
# service iptables restart
chmod +x /etc/rc.d/rc.local
ps -ef|grep redis
echo -e "\033[32m Install is successed. \033[0m"
else
echo -e "\033[31m Warning : the program is installed, the script will exit. \033[0m"
fi
Shell
1
https://gitee.com/cnop/shell.git
git@gitee.com:cnop/shell.git
cnop
shell
shell
master

搜索帮助