Redis如何一鍵部署腳本
先將安裝包拖入/opt目錄

注意:這里的腳本bind修改后為 0.0.0.0
bind修改后為bind 127.0.0.1 +服務(wù)器IP在下面
#!/bin/bash #yum源 echo -e "\033[31m =====正在驗(yàn)證當(dāng)前為僅主機(jī)還是NAT模式===== \033[0m" ping -c1 -W1 www.baidu.com &> /dev/null if [ $? -eq 0 ];then echo -e "\033[31m 檢測(cè)當(dāng)前為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 檢測(cè)當(dāng)前為僅主機(jī)模式,為您配置本地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 檢測(cè)當(dāng)前為僅主機(jī)模式,但光盤未連接! \033[0m" else echo -e "\033[31m 本地yum源已配置完成 \033[0m" fi fi #關(guān)閉防火墻 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 文件,所以在解壓完軟件包后,不用先執(zhí)行./configure進(jìn)行配置,可直接執(zhí)行make與make install 命令進(jìn)行安裝。 #在/utils里執(zhí)行軟件包提供的install_server.sh腳本文件設(shè)置Redis服務(wù)所需要的相關(guān)配置文件 cd /opt/redis-5.0.7/utils #開始免交換執(zhí)行 /usr/bin/expect <<EOF #expect開始標(biāo)志 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 +服務(wù)器IP腳本
#!/bin/bash
#yum源
echo -e "\033[31m =====正在驗(yàn)證當(dāng)前為僅主機(jī)還是NAT模式===== \033[0m"
ping -c1 -W1 www.baidu.com &> /dev/null
if [ $? -eq 0 ];then echo -e "\033[31m 檢測(cè)當(dāng)前為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 檢測(cè)當(dāng)前為僅主機(jī)模式,為您配置本地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 檢測(cè)當(dāng)前為僅主機(jī)模式,但光盤未連接! \033[0m"
else
echo -e "\033[31m 本地yum源已配置完成 \033[0m"
fi
fi
#防火墻關(guān)閉
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 文件,所以在解壓完軟件包后,不用先執(zhí)行./configure進(jìn)行配置,可直接執(zhí)行make與make install 命令進(jìn)行安裝。
#在/utils里執(zhí)行軟件包提供的install_server.sh腳本文件設(shè)置Redis服務(wù)所需要的相關(guān)配置文件
cd /opt/redis-5.0.7/utils
#開始免交換執(zhí)行
/usr/bin/expect <<EOF
#expect開始標(biāo)志
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
到此這篇關(guān)于Redis如何一鍵部署腳本的文章就介紹到這了,更多相關(guān)Redis 部署腳本內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
高并發(fā)場(chǎng)景分析之redis+lua防重校驗(yàn)
這篇文章主要介紹了高并發(fā)場(chǎng)景分析之redis+lua防重校驗(yàn),本文通過示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-07-07
Django使用Redis進(jìn)行緩存詳細(xì)步驟
這篇文章主要介紹了Django使用Redis進(jìn)行緩存詳細(xì)流程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-08-08
spring?boot集成redis基礎(chǔ)入門實(shí)例詳解
redis在spring?boot項(xiàng)目開發(fā)中是常用的緩存套件,常見使用的是spring-boot-starter-data-redis,這篇文章主要介紹了spring?boot集成redis基礎(chǔ)入門,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-10-10
Redis權(quán)限和訪問控制的實(shí)現(xiàn)示例
Redis提供了一些機(jī)制來保護(hù)敏感數(shù)據(jù)和限制對(duì)Redis服務(wù)器的訪問,本文主要介紹了Redis權(quán)限和訪問控制的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下2023-12-12
通過 Redis 實(shí)現(xiàn) RPC 遠(yuǎn)程方法調(diào)用(支持多種編程語言)
這篇文章主要介紹了通過 Redis 實(shí)現(xiàn) RPC 遠(yuǎn)程方法調(diào)用,支持多種編程語言,本文就以Ruby和Python為例,給出了實(shí)現(xiàn)代碼,需要的朋友可以參考下2014-09-09
了解redis中RDB結(jié)構(gòu)_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要為大家詳細(xì)介紹了redis中RDB結(jié)構(gòu),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08
Redis設(shè)置密碼保護(hù)的實(shí)例講解
今天小編就為大家分享一篇Redis設(shè)置密碼保護(hù)的實(shí)例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-05-05

