首頁>技術>

今天給大家分享一個超級實用的指令碼,一鍵自動安裝部署Redis的任意版本,記住是任意版本哦!

指令碼用法:chmod 755 redis-install.sh && sh redis-install.sh 4.0.10 (後面跟的是你需要的版本號,需要什麼版本就寫什麼版本),我這裡安裝的4.0.10

具體指令碼內容如下展示:

#! /usr/bin/bash##redis任何版本全程自動化原始碼編譯安裝##用法: sh redis-install.sh 4.0.10 (後面跟的是你需要的版本號,需要什麼版本就寫什麼版本),我這裡安裝的4.0.10version=$1usage(){echo "usage: $0 version"}if [ $# -ne 1 ]thenusageexit -1fi#Redis安裝包下載cd /usr/local/srcif [ ! -f redis-${version}.tar.gz ]thencurl -o /usr/local/src/redis-${version}.tar.gz http://download.redis.io/releases/redis-${version}.tar.gzfi#Redis依賴包安裝yum clean allyum makecache fastyum -y install gcc gcc-c++ tcl#編譯Redis所需要的gccyum -y install centos-release-sclyum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutilssource /opt/rh/devtoolset-9/enableecho "source /opt/rh/devtoolset-9/enable" >>/etc/profilegcc --version##內系統引數核最佳化cat >> /etc/rc.d/rc.local << "EOF"##關閉Linux的THP(記憶體管理系統)透過使用更大的記憶體頁面,來減少具有大量記憶體的計算機上的TLB的開銷if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]thenecho never > /sys/kernel/mm/transparent_hugepage/enabledfiif [ -f /sys/kernel/mm/transparent_hugepage/defrag ]thenecho never > /sys/kernel/mm/transparent_hugepage/defragfiEOFchmod u+x /etc/rc.d/rc.localif [ -f /sys/kernel/mm/transparent_hugepage/enabled ]thenecho never > /sys/kernel/mm/transparent_hugepage/enabledfiif [ -f /sys/kernel/mm/transparent_hugepage/defrag ]thenecho never > /sys/kernel/mm/transparent_hugepage/defragficat >> /etc/sysctl.conf << "EOF"#Linux系統核心引數最佳化net.core.somaxconn = 2048net.ipv4.tcp_max_syn_backlog = 2048vm.overcommit_memory = 1EOFsysctl -pcat > /etc/security/limits.conf << "EOF"root soft nofile 65535root hard nofile 65535* soft nofile 65535* hard nofile 65535EOF#Redis編譯安裝cd /usr/local/srctar -zxvf redis-${version}.tar.gzcd /usr/local/src/redis-${version}makemake PREFIX=/usr/local/redis install#Redis基礎配置mkdir -p /usr/local/redis/{etc,logs,data}egrep -v "^$|^#" /usr/local/src/redis-${version}/redis.conf > /usr/local/redis/etc/redis.conf#sed -i "s/bind 127.0.0.1/bind 0.0.0.0/g" /usr/local/redis/etc/redis.confsed -i "s/protected-mode yes/protected-mode no/g" /usr/local/redis/etc/redis.confsed -i "s/daemonize no/daemonize yes/g" /usr/local/redis/etc/redis.confsed -i "s/pidfile \/var\/run\/redis_6379.pid/pidfile \/usr\/local\/redis\/redis.pid/g" /usr/local/redis/etc/redis.confsed -i "s/dir \.\//dir \/usr\/local\/redis\/data/g" /usr/local/redis/etc/redis.confsed -i "s/logfile \"\"/logfile \"\/usr\/local\/redis\/logs\/redis.log\"/g" /usr/local/redis/etc/redis.confsed -i "s/dbfilename dump.rdb/dbfilename dump.rdb/g" /usr/local/redis/etc/redis.confsed -i "s/appendfilename \"appendonly.aof\"/appendfilename \"appendonly.aof\"/g" /usr/local/redis/etc/redis.conf#PATH配置echo "export PATH=${PATH}:/usr/local/redis/bin" >>/etc/profilesource /etc/profile#啟動redis服務/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf#檢視redis監聽埠netstat -tanp|grep redis

執行指令碼後開始自動安裝redis4.0.10

自動安裝Redis4.0.10所需要的的依賴包,如下圖所示:

自動開始解壓:

開始自動make

開始自動make install

安裝完成,Redis服務已成功啟動:

到這裡整改自動安裝指令碼已成功執行完畢,我們可以收到透過ps –ef|grep redis來檢視服務狀態以及監聽埠。

登陸redis,執行簡單的語句:

13
最新評論
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • Windows10系統下Hive開發環境搭建填坑指南「轉」