Redis6.2.6在Centos7上的安裝過程

1.系統(tǒng)環(huán)境

操作系統(tǒng):

[root@m161p114 software]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.9.2009 (Core)
Release:    7.9.2009
Codename:   Core

redis安裝的源碼文件:
redis-6.2.6.tar.gz

該文件下載后,放置在 /opt/software目錄

2.gcc升級

redis6的源碼需要用gcc版本為9的環(huán)境進(jìn)行編譯。首先需要確認(rèn),gcc及gcc-c++ 已經(jīng)安裝。如果沒有安裝,執(zhí)行如下命令:

yum -y install gcc gcc-c++

當(dāng)前系統(tǒng)的gcc環(huán)境為:

[root@m161p114 ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 

通過如下命令升級:

yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

scl enable devtoolset-9 bash

配置環(huán)境變量:
vim /etc/profile
在末尾追加:

source /opt/rh/devtoolset-9/enable

這樣系統(tǒng)就能確保每次啟動都能開啟gcc9環(huán)境。

現(xiàn)在查看gcc版本:

[root@m161p114 software]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-9/root/usr --mandir=/opt/rh/devtoolset-9/root/usr/share/man --infodir=/opt/rh/devtoolset-9/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-9.3.1-20200408/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC) 

3.編譯及安裝redis

在/opt目錄中執(zhí)行解壓:

tar -zxvf /opt/software/redis-6.2.6.tar.gz 

然后執(zhí)行make:

cd /opt/redis-6.2.6
make
make install PREFIX=/usr/local/redis

配置redis環(huán)境變量,在/etc/profile中增加如下內(nèi)容:

export REDIS_HOME=/usr/local/redis
export PATH=$PATH:$REDIS_HOME/bin

之后執(zhí)行source加載環(huán)境變量:

source /etc/profile

執(zhí)行如下命令。說明環(huán)境變量配置成功:

[root@m161p114 utils]# redis-server --version
Redis server v=6.2.6 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=336fe6a5b7d02b06

4.通過install_server.sh配置servie服務(wù)

如果出現(xiàn)如下提示:

[root@m161p114 utils]# ./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server

This systems seems to use systemd.
Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!

需要用vim將install_server.sh中的如下代碼注釋掉:

#if [ "${_pid_1_exe##*/}" = systemd ]
#then
#       echo "This systems seems to use systemd."
#       echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!"
#       exit 1
#fi

這是因為,centos7最開始的版本采用systemd配置服務(wù)。而新版本的centos又支持兼容之前的centos6中的配置。redis在此做了一個保護(hù)。

cd /opt/redis-6.2.6/utils
[root@m161p114 utils]# ./install_server.sh

Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] /opt/redis/logs/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] /opt/redis/data/6379
Please select the redis executable path [/usr/local/redis/bin/redis-server] /usr/local/redis/bin/redis-server
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /opt/redis/logs/redis_6379.log
Data dir       : /opt/redis/data/6379
Executable     : /usr/local/redis/bin/redis-server
Cli Executable : //usr/local/redis/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

現(xiàn)在可以通過service進(jìn)行啟動和關(guān)閉:

[root@m161p114 utils]# service redis_6379 start
Starting Redis server...
[root@m161p114 utils]# service redis_6379 stop
Stopping ...
Redis stopped
[root@m161p114 utils]# 

5.修改配置文件

修改redis的配置文件:

vim /etc/redis/6379.conf

修改bind為:
bind 0.0.0.0  -::1

這樣外部服務(wù)才能連接到redis服務(wù)中。
啟動redis,通過客戶端連接測試:

[root@m161p114 redis]# redis-cli
127.0.0.1:6379> 
[root@m161p114 redis]# redis-cli -h 192.168.161.114 -p 6379
192.168.161.114:6379> 

說明redis安裝成功。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容