您好,登錄后才能下訂單哦!
由于開始接觸redis的自動化運維,為了方便后續工作的進行,寫了一個redis自動化安裝腳本,可以實現安裝、配置、并可以使用service redis start/stop控制服務的啟動和停止,參考博文http://blog.csdn.net/ludonqin/article/details/47211109
此腳本已經在Centos6.3環境下測試無誤,腳本內容如下:
#redis自動安裝腳本:
#pid文件:/var/redis/run/redis.pid
#配置文件:/etc/redis/redis.conf
#日志文件:/var/redis/log
#數據文件:/var/redis/data
#!/bin/bash
Soft_dir="/home/redis"
Download_URL="http://download.redis.io/redis-stable.tar.gz"
#3.2.9
Redis_Version="stable"
#此函數用于判斷是否為root用戶
root_or_not(){
if [ `id -u` != 0 ] ; then
echo -e "\e[1;44m <====You are not root,Please login in root!====> \e[0m"
exit 1
fi
}
#此函數用來使用戶選擇是否安裝redis
install_or_not(){
read -p "Install redis, Input Y/y ; Do not install redis,Input N/n:" INSTALL_OR_NOT
case $INSTALL_OR_NOT in
Y|y)
install_redis
;;
N|n)
echo -e "\e[0;44m <====Stop install Redis====> \e[0m"
exit 1
;;
*)
echo -e "\e[1;44m Only Input Y/y or N/n \e[0m"
install_or_not
;;
esac
}
#此函數用來檢查上一個命令的執行狀態結果返回值,若執行未成功,則退出
check_result(){
if [ $1 != 0 ];then
echo -e "\e[1,44m <==== Error,Exit install redis ====> \e[0m"
exit 1
fi
}
#此函數用于實現redis的安裝、配置、啟動停止
install_redis(){
[ ! -d ${Soft_dir} ] && mkdir ${Soft_dir}
cd ${Soft_dir}
check_result $?
yum -y install wget
check_result $?
wget $Download_URL
check_result $?
tar zxvf redis-${Redis_Version}.tar.gz
check_result $?
cd redis-${Redis_Version}
check_result $?
yum -y install gcc;yum -y install tcl
check_result $?
make
check_result $?
make install
check_result $?
mkdir /etc/redis
check_result $?
mkdir -p /var/redis/{data,log,run}
check_result $?
cp redis.conf /etc/redis/
check_result $?
echo -e "\e[1;44m ======Begin to Configure /etc/redis/redis.conf ======= \e[0m"
sed -i '150c pidfile /var/redis/run/redis.pid' /etc/redis/redis.conf
check_result $?
sed -i '247c dir /var/redis/data' /etc/redis/redis.conf
check_result $?
sed -i '163c logfile /var/redis/log/redis.log' /etc/redis/redis.conf
check_result $?
sed -i '128c daemonize yes' /etc/redis/redis.conf
check_result $?
sed -i '61c bind 0.0.0.0' /etc/redis/redis.conf
check_result $?
echo -e "\e[1;44m ======Begin To Let Service Start While The Machine Online ======= \e[0m"
cp /home/redis/redis-stable/utils/redis_init_script /etc/init.d/redis
check_result $?
sed -i '10c PIDFILE=/var/redis/run/redis.pid' /etc/init.d/redis
check_result $?
sed -i '11c CONF="/etc/redis/redis.conf"' /etc/init.d/redis
check_result $?
chmod +x /etc/init.d/redis
check_result $?
service redis start
check_result $?
echo -e "\e[1;44m ====== Success!!!!!! ======= \e[0m"
}
root_or_not
install_or_not
歡迎批評指正!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。