Redis如何一鍵部署腳本

先將安裝包拖入/opt目錄

在這裡插入圖片描述

註意:這裡的腳本bind修改後為 0.0.0.0

bind修改後為bind 127.0.0.1 +服務器IP在下面

#!/bin/bash

#yum源
echo -e "\033[31m =====正在驗證當前為僅主機還是NAT模式===== \033[0m"
ping -c1 -W1 www.baidu.com &> /dev/null
if [ $? -eq 0 ];then echo -e "\033[31m 檢測當前為NAT模式,為您配置在線yum源 \033[0m"
mkdir -p /etc/yum.repos.d/repo.bak

mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/null

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/null

yum clean all &> /dev/null
yum list &> /dev/null
echo -e "\033[31m 在線源已配置完成 \033[0m"

else
echo -e "\033[31m 檢測當前為僅主機模式,為您配置本地yum源 \033[0m"
mount /dev/sr0 /mnt &> /dev/null
cd /etc/yum.repos.d/
mkdir -p /etc/yum.repos.d/repo.bak

mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/null

echo '[local]
name=local
baseurl=file:///mnt
enabled=1
gpgcheck=0' > /etc/yum.repos.d/local.repo
yum clean all &> /dev/null
yum makecache &> /dev/null

df -h | grep "/mnt" 
if [ $? -ne 0 ];then
echo -e "\033[31m 檢測當前為僅主機模式,但光盤未連接! \033[0m"
else
echo -e "\033[31m 本地yum源已配置完成 \033[0m"
fi
fi

#關閉防火墻
systemctl stop firewalld
setenforce 0
yum install -y gcc gcc-c++ make
rpm -q expect
rpm -q tcl
yum -y install expect
cd /opt
tar zxvf redis-5.0.7.tar.gz -C /opt/
cd /opt/redis-5.0.7/
make
make PREFIX=/usr/local/redis install
#由於Redis源碼包中直接提供瞭Makefile 文件,所以在解壓完軟件包後,不用先執行./configure進行配置,可直接執行make與make install 命令進行安裝。

#在/utils裡執行軟件包提供的install_server.sh腳本文件設置Redis服務所需要的相關配置文件
cd /opt/redis-5.0.7/utils

#開始免交換執行
/usr/bin/expect <<EOF
#expect開始標志
spawn ./install_server.sh
#Please select the redis port for this instance: [6379]
expect "instance"
send "\r" 
#Please select the redis config file name [/etc/redis/6379.conf] 
expect "config"
send "\r"
#Please select the redis log file name [/var/log/redis_6379.log]
expect "log"
send "\r"
#Please select the data directory for this instance [/var/lib/redis/6379]
expect "data"
send "\r"
#Please select the redis executable path []
expect "executable"
send "/usr/local/redis/bin/redis-server\r"
#Is this ok? Then press ENTER to go on or Ctrl-C to abort.
expect "abort"
send "\r"
expect eof
EOF


ln -s /usr/local/redis/bin/* /usr/local/bin/
netstat -natp | grep redis

/etc/init.d/redis_6379 restart     
/etc/init.d/redis_6379 status   

sed -i '/bind 127.0.0.1/c bind 0.0.0.0' /etc/redis/6379.conf
sed -i 's/appendonly no/appendonly yes/' /etc/redis/6379.conf

/etc/init.d/redis_6379 restart
/etc/init.d/redis_6379 status  

bind修改後為bind 127.0.0.1 +服務器IP腳本

#!/bin/bash

#yum源
echo -e "\033[31m =====正在驗證當前為僅主機還是NAT模式===== \033[0m"
ping -c1 -W1 www.baidu.com &> /dev/null
if [ $? -eq 0 ];then echo -e "\033[31m 檢測當前為NAT模式,為您配置在線yum源 \033[0m"
mkdir -p /etc/yum.repos.d/repo.bak

mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/null

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/null

yum clean all &> /dev/null
yum list &> /dev/null
echo -e "\033[31m 在線源已配置完成 \033[0m"

else
echo -e "\033[31m 檢測當前為僅主機模式,為您配置本地yum源 \033[0m"
mount /dev/sr0 /mnt &> /dev/null
cd /etc/yum.repos.d/
mkdir -p /etc/yum.repos.d/repo.bak

mv -f /etc/yum.repos.d/* /etc/yum.repos.d/repo.bak &> /dev/null

echo '[local]
name=local
baseurl=file:///mnt
enabled=1
gpgcheck=0' > /etc/yum.repos.d/local.repo
yum clean all &> /dev/null
yum makecache &> /dev/null

df -h | grep "/mnt" 
if [ $? -ne 0 ];then
echo -e "\033[31m 檢測當前為僅主機模式,但光盤未連接! \033[0m"
else
echo -e "\033[31m 本地yum源已配置完成 \033[0m"
fi
fi

#防火墻關閉
systemctl stop firewalld
setenforce 0
yum install -y gcc gcc-c++ make
rpm -q expect
rpm -q tcl
yum -y install expect
cd /opt
tar zxvf redis-5.0.7.tar.gz -C /opt/
cd /opt/redis-5.0.7/
make
make PREFIX=/usr/local/redis install
#由於Redis源碼包中直接提供瞭Makefile 文件,所以在解壓完軟件包後,不用先執行./configure進行配置,可直接執行make與make install 命令進行安裝。

#在/utils裡執行軟件包提供的install_server.sh腳本文件設置Redis服務所需要的相關配置文件
cd /opt/redis-5.0.7/utils

#開始免交換執行
/usr/bin/expect <<EOF
#expect開始標志
spawn ./install_server.sh
#Please select the redis port for this instance: [6379]
expect "instance"
send "\r" 
#Please select the redis config file name [/etc/redis/6379.conf] 
expect "config"
send "\r"
#Please select the redis log file name [/var/log/redis_6379.log]
expect "log"
send "\r"
#Please select the data directory for this instance [/var/lib/redis/6379]
expect "data"
send "\r"
#Please select the redis executable path []
expect "executable"
send "/usr/local/redis/bin/redis-server\r"
#Is this ok? Then press ENTER to go on or Ctrl-C to abort.
expect "abort"
send "\r"
expect eof
EOF


ln -s /usr/local/redis/bin/* /usr/local/bin/
netstat -natp | grep redis

/etc/init.d/redis_6379 restart     
/etc/init.d/redis_6379 status   


xyw=$(ip a | grep "ens33" | awk NR==2'{print$2}' |awk -F/ '{print$1}')
sed -i "/bind 127.0.0.1/c bind 127.0.0.1 $xyw" /etc/redis/6379.conf

sed -i 's/appendonly no/appendonly yes/' /etc/redis/6379.conf

/etc/init.d/redis_6379 restart
/etc/init.d/redis_6379 status   

到此這篇關於Redis如何一鍵部署腳本的文章就介紹到這瞭,更多相關Redis 部署腳本內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!

推薦閱讀:

    None Found