如何在linux平台上安装redis3.0集群版(附自动安装脚本)
2014-09-24 14:35
761 查看
#!/bin/bash
#version choose
OS=`sed -n '1p' /etc/issue|awk '{print $1}'`
if [ $OS = "Ubuntu" -o $OS = "Debian" ];then
apt-get -y install gcc make tcl ruby unzip
elif [ $OS = "Suse" ];then
zypper -y install gcc make tcl ruby unzip
else
yum -y install gcc make automake tcl ruby ruby-rdoc unzip
fi
#Install redis
if [ ! -d /home/tools/ ];then
mkdir -p /home/tools
else
rm -rf /home/tools && mkdir -p /home/tools
fi
cd /home/tools
wget https://github.com/antirez/redis/archive/3.0.0-rc1.tar.gz tar zxvf 3.0.0-rc1.tar.gz
if [ $? -eq 0 ];then
cd redis-3.0.0-rc1/ && make && make PREFIX=/opt/redis install
fi
#Config redis
mkdir -p /opt/redis/etc
mkdir -p /opt/redis/run
mkdir -p /opt/redis/data
mkdir -p /opt/redis/log
mkdir -p /opt/redis/data/6379
\cp redis.conf /opt/redis/etc/redis.conf
\cp /opt/redis/etc/redis.conf /opt/redis/etc/redis_6379.conf
cd /home/tools/redis-3.0.0-rc1/src
\cp redis-trib.rb /opt/redis/bin/
sed -i '37s/daemonize no/daemonize yes/' /opt/redis/etc/redis_6379.conf
sed -i '41s#/var/run/redis.pid#/opt/redis/run/redis_6379.pid#' /opt/redis/etc/redis_6379.conf
sed -i '187s#dir ./#dir /opt/redis/data/6379#' /opt/redis/etc/redis_6379.conf
sed -i '103s#logfile ""#logfile /opt/redis/log/redis_6379.log#' /opt/redis/etc/redis_6379.conf
sed -i 's/appendonly no/appendonly yes/g' /opt/redis/etc/redis_6379.conf
sed -i 's/appendfilename "appendonly.aof"/appendfilename "appendonly-6379.aof"/g' /opt/redis/etc/redis_6379.conf
sed -i 's#\# cluster-enabled yes#cluster-enabled yes#g' /opt/redis/etc/redis_6379.conf
sed -i 's#\# cluster-node-timeout 15000#cluster-node-timeout 5000#g' /opt/redis/etc/redis_6379.conf
sed -i 's#\# cluster-config-file nodes-6379.conf#cluster-config-file nodes-6379.conf#g' /opt/redis/etc/redis_6379.conf
#Adding memory optimization parameters
echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
sysctl -p
#Config start/stop script
cat > /etc/init.d/redis_6379 <<EOF
#!/bin/bash
EXEC="/opt/redis/bin/redis-server"
PIDFILE="/opt/redis/run/redis_6379.pid"
CONF="/opt/redis/etc/redis_6379.conf"
REDISPORT="6379"
case "\$1" in
start)
if [ -f \$\$PIDFILE ]
then
echo "\$PIDFILE exists, process is already running or crashed."
else
echo "Starting Redis server..."
\$EXEC \$CONF
fi
;;
stop)
if [ ! -f \$PIDFILE ]
then
echo "\$PIDFILE does not exist, process is not running."
else
PID=\$(cat \$PIDFILE)
echo "Stopping Redis Server…"
while [ -x /proc/\${PID} ]
do
kill -9 \$PID
sleep 1
done
echo "Redis stopped."
fi
;;
*)
echo "Usage: \$0 {start|stop}" >&2
exit 1
;;
esac
EOF
#Setup redis
chmod +x /etc/init.d/redis_6379 && /etc/init.d/redis_6379 start
ln -s /opt/redis/bin/* /usr/bin
#Installrubygem
cd /home/tools/
wget http://production.cf.rubygems.org/rubygems/rubygems-2.4.2.zip if [ $? -eq 0 ];then
unzip rubygems-2.4.2.zip
fi
cd rubygems-2.4.2/
ruby setup.rb
if [ $? -eq 0 ];then
gem install redis --version 3.0.0
fi
本文出自 “运维人生” 博客,请务必保留此出处http://jinyan2049.blog.51cto.com/881440/1557700
#version choose
OS=`sed -n '1p' /etc/issue|awk '{print $1}'`
if [ $OS = "Ubuntu" -o $OS = "Debian" ];then
apt-get -y install gcc make tcl ruby unzip
elif [ $OS = "Suse" ];then
zypper -y install gcc make tcl ruby unzip
else
yum -y install gcc make automake tcl ruby ruby-rdoc unzip
fi
#Install redis
if [ ! -d /home/tools/ ];then
mkdir -p /home/tools
else
rm -rf /home/tools && mkdir -p /home/tools
fi
cd /home/tools
wget https://github.com/antirez/redis/archive/3.0.0-rc1.tar.gz tar zxvf 3.0.0-rc1.tar.gz
if [ $? -eq 0 ];then
cd redis-3.0.0-rc1/ && make && make PREFIX=/opt/redis install
fi
#Config redis
mkdir -p /opt/redis/etc
mkdir -p /opt/redis/run
mkdir -p /opt/redis/data
mkdir -p /opt/redis/log
mkdir -p /opt/redis/data/6379
\cp redis.conf /opt/redis/etc/redis.conf
\cp /opt/redis/etc/redis.conf /opt/redis/etc/redis_6379.conf
cd /home/tools/redis-3.0.0-rc1/src
\cp redis-trib.rb /opt/redis/bin/
sed -i '37s/daemonize no/daemonize yes/' /opt/redis/etc/redis_6379.conf
sed -i '41s#/var/run/redis.pid#/opt/redis/run/redis_6379.pid#' /opt/redis/etc/redis_6379.conf
sed -i '187s#dir ./#dir /opt/redis/data/6379#' /opt/redis/etc/redis_6379.conf
sed -i '103s#logfile ""#logfile /opt/redis/log/redis_6379.log#' /opt/redis/etc/redis_6379.conf
sed -i 's/appendonly no/appendonly yes/g' /opt/redis/etc/redis_6379.conf
sed -i 's/appendfilename "appendonly.aof"/appendfilename "appendonly-6379.aof"/g' /opt/redis/etc/redis_6379.conf
sed -i 's#\# cluster-enabled yes#cluster-enabled yes#g' /opt/redis/etc/redis_6379.conf
sed -i 's#\# cluster-node-timeout 15000#cluster-node-timeout 5000#g' /opt/redis/etc/redis_6379.conf
sed -i 's#\# cluster-config-file nodes-6379.conf#cluster-config-file nodes-6379.conf#g' /opt/redis/etc/redis_6379.conf
#Adding memory optimization parameters
echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
sysctl -p
#Config start/stop script
cat > /etc/init.d/redis_6379 <<EOF
#!/bin/bash
EXEC="/opt/redis/bin/redis-server"
PIDFILE="/opt/redis/run/redis_6379.pid"
CONF="/opt/redis/etc/redis_6379.conf"
REDISPORT="6379"
case "\$1" in
start)
if [ -f \$\$PIDFILE ]
then
echo "\$PIDFILE exists, process is already running or crashed."
else
echo "Starting Redis server..."
\$EXEC \$CONF
fi
;;
stop)
if [ ! -f \$PIDFILE ]
then
echo "\$PIDFILE does not exist, process is not running."
else
PID=\$(cat \$PIDFILE)
echo "Stopping Redis Server…"
while [ -x /proc/\${PID} ]
do
kill -9 \$PID
sleep 1
done
echo "Redis stopped."
fi
;;
*)
echo "Usage: \$0 {start|stop}" >&2
exit 1
;;
esac
EOF
#Setup redis
chmod +x /etc/init.d/redis_6379 && /etc/init.d/redis_6379 start
ln -s /opt/redis/bin/* /usr/bin
#Installrubygem
cd /home/tools/
wget http://production.cf.rubygems.org/rubygems/rubygems-2.4.2.zip if [ $? -eq 0 ];then
unzip rubygems-2.4.2.zip
fi
cd rubygems-2.4.2/
ruby setup.rb
if [ $? -eq 0 ];then
gem install redis --version 3.0.0
fi
本文出自 “运维人生” 博客,请务必保留此出处http://jinyan2049.blog.51cto.com/881440/1557700
相关文章推荐
- linux下redis自动安装脚本
- Linux下Redis数据库的安装方法与自动启动脚本分享
- [2月25日的脚本] 如何自动地安装NET4.5, PowerShell 3.0, KB2592525 (PowerShell)
- IT忍者神龟之Linux Redis安装,Linux如何安装Redis,Linux Redis自动启动,Redis开机启动
- Linux Redis安装,Linux如何安装Redis,Linux Redis自动启动,Redis开机启动
- 智能一代云平台(十四):Linux上安装集群版Redis
- Linux安装脚本需要交互之如何实现自动安装
- Linux平台-源码安装heartbeat 3.0集群
- 在linux下如何通过expect正确执行自动切换登录,并且执行命令和脚本
- 发布MySQL集群自动安装脚本1.0!
- 朋友的一个问题:Linux开机如何自动运行自己编写好的shell脚本
- suse linux luckemftp安装及ftp shell自动上传脚本
- Linux如何开机自动运行自己的脚本
- 归档Redis在Windows,linux平台下的安装配置
- 如何在linux平台安装Windows版SourceInsight3.5
- Redis在Windows+linux平台下的安装配置
- Linux开机如何自动运行自己编写好的shell脚本
- 如何顺利实现LINUX系统开机自动启动指定的脚本程序
- Linux平台和Windows平台下两种自动备份MySQL数据的脚本(Shell&Bat)和步骤
- linux ,叫你如何实现脚本自动创建自己专属迷你小linux(一)