溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Linux系統(tǒng)如何安裝Redis服務(wù)

發(fā)布時(shí)間:2021-11-05 10:20:55 來源:億速云 閱讀:214 作者:柒染 欄目:建站服務(wù)器

這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)Linux系統(tǒng)如何安裝Redis服務(wù),文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

一、配置本地yum源,用于安裝redis所需要包: http://blog.itpub.net/30484956/viewspace-2675381/
二、安裝redis:

準(zhǔn)備工作:將包括redis在內(nèi)的redis-3.2.8.tar.gz安裝包放到指定位置(此位置可以自建,為了統(tǒng)一,全部放在/var/software/目錄下)

(1)解壓redis安裝包:

[root@caiji software]# tar -xvf redis-3.2.8.tar.gz
......
......

進(jìn)入解壓后的文件中:

[root@caiji software]# cd redis-3.2.8
[root@caiji redis-3.2.8]# ls
00-RELEASENOTES  COPYING  Makefile   redis.conf       runtest-sentinel  tests
BUGS             deps     MANIFESTO  runtest          sentinel.conf     utils
CONTRIBUTING     INSTALL  README.md  runtest-cluster  src

使用yum命令安裝redis所需要的包和編譯工具:

[root@caiji software]# yum -y install wget  make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel kernel keyutils  patch perl

(以下為輸出內(nèi)容,如果有的包已經(jīng)安裝過的話,輸出內(nèi)容會有所差別,大體是一樣的?。?/p>

Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
Package wget-1.12-1.8.el6.x86_64 already installed and latest version
Package 1:make-3.81-20.el6.x86_64 already installed and latest version
Package openssl-1.0.1e-15.el6.x86_64 already installed and latest version
Package kernel-2.6.32-431.el6.x86_64 already installed and latest version
Package keyutils-1.4-4.el6.x86_64 already installed and latest version
Package patch-2.6-6.el6.x86_64 already installed and latest version
Package 4:perl-5.10.1-136.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package gcc.x86_64 0:4.4.7-4.el6 will be installed
--> Processing Dependency: cpp = 4.4.7-4.el6 for package: gcc-4.4.7-4.el6.x86_64
--> Processing Dependency: cloog-ppl >= 0.15 for package: gcc-4.4.7-4.el6.x86_64
---> Package gcc-c++.x86_64 0:4.4.7-4.el6 will be installed
--> Processing Dependency: libstdc++-devel = 4.4.7-4.el6 for package: gcc-c++-4.4.7-4.el6.x86_64
--> Processing Dependency: libmpfr.so.1()(64bit) for package: gcc-c++-4.4.7-4.el6.x86_64
---> Package openssl-devel.x86_64 0:1.0.1e-15.el6 will be installed
--> Processing Dependency: krb5-devel for package: openssl-devel-1.0.1e-15.el6.x86_64
---> Package pcre-devel.x86_64 0:7.8-6.el6 will be installed
---> Package zlib-devel.x86_64 0:1.2.3-29.el6 will be installed
--> Running transaction check
---> Package cloog-ppl.x86_64 0:0.15.7-1.2.el6 will be installed
--> Processing Dependency: libppl_c.so.2()(64bit) for package: cloog-ppl-0.15.7-1.2.el6.x86_64
--> Processing Dependency: libppl.so.7()(64bit) for package: cloog-ppl-0.15.7-1.2.el6.x86_64
---> Package cpp.x86_64 0:4.4.7-4.el6 will be installed
---> Package krb5-devel.x86_64 0:1.10.3-10.el6_4.6 will be installed
--> Processing Dependency: libselinux-devel for package: krb5-devel-1.10.3-10.el6_4.6.x86_64
--> Processing Dependency: libcom_err-devel for package: krb5-devel-1.10.3-10.el6_4.6.x86_64
--> Processing Dependency: keyutils-libs-devel for package: krb5-devel-1.10.3-10.el6_4.6.x86_64
---> Package libstdc++-devel.x86_64 0:4.4.7-4.el6 will be installed
---> Package mpfr.x86_64 0:2.4.1-6.el6 will be installed
--> Running transaction check
---> Package keyutils-libs-devel.x86_64 0:1.4-4.el6 will be installed
---> Package libcom_err-devel.x86_64 0:1.41.12-18.el6 will be installed
---> Package libselinux-devel.x86_64 0:2.0.94-5.3.el6_4.1 will be installed
--> Processing Dependency: libsepol-devel >= 2.0.32-1 for package: libselinux-devel-2.0.94-5.3.el6_4.1.x86_64
--> Processing Dependency: pkgconfig(libsepol) for package: libselinux-devel-2.0.94-5.3.el6_4.1.x86_64
---> Package ppl.x86_64 0:0.10.2-11.el6 will be installed
--> Running transaction check
---> Package libsepol-devel.x86_64 0:2.0.41-4.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
 Package                  Arch        Version                  Repository  Size
================================================================================
Installing:
 gcc                      x86_64      4.4.7-4.el6              local       10 M
 gcc-c++                  x86_64      4.4.7-4.el6              local      4.7 M
 openssl-devel            x86_64      1.0.1e-15.el6            local      1.2 M
 pcre-devel               x86_64      7.8-6.el6                local      318 k
 zlib-devel               x86_64      1.2.3-29.el6             local       44 k
Installing for dependencies:
 cloog-ppl                x86_64      0.15.7-1.2.el6           local       93 k
 cpp                      x86_64      4.4.7-4.el6              local      3.7 M
 keyutils-libs-devel      x86_64      1.4-4.el6                local       28 k
 krb5-devel               x86_64      1.10.3-10.el6_4.6        local      495 k
 libcom_err-devel         x86_64      1.41.12-18.el6           local       32 k
 libselinux-devel         x86_64      2.0.94-5.3.el6_4.1       local      136 k
 libsepol-devel           x86_64      2.0.41-4.el6             local       64 k
 libstdc++-devel          x86_64      4.4.7-4.el6              local      1.6 M
 mpfr                     x86_64      2.4.1-6.el6              local      156 k
 ppl                      x86_64      0.10.2-11.el6            local      1.3 M
Transaction Summary
================================================================================
Install      15 Package(s)
Total download size: 24 M
Installed size: 59 M
Downloading Packages:
--------------------------------------------------------------------------------
Total                                            48 MB/s |  24 MB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : mpfr-2.4.1-6.el6.x86_64                                     1/15 
  Installing : cpp-4.4.7-4.el6.x86_64                                      2/15 
  Installing : ppl-0.10.2-11.el6.x86_64                                    3/15 
  Installing : cloog-ppl-0.15.7-1.2.el6.x86_64                             4/15 
  Installing : gcc-4.4.7-4.el6.x86_64                                      5/15 
  Installing : zlib-devel-1.2.3-29.el6.x86_64                              6/15 
  Installing : libcom_err-devel-1.41.12-18.el6.x86_64                      7/15 
  Installing : keyutils-libs-devel-1.4-4.el6.x86_64                        8/15 
  Installing : libsepol-devel-2.0.41-4.el6.x86_64                          9/15 
  Installing : libselinux-devel-2.0.94-5.3.el6_4.1.x86_64                 10/15 
  Installing : krb5-devel-1.10.3-10.el6_4.6.x86_64                        11/15 
  Installing : libstdc++-devel-4.4.7-4.el6.x86_64                         12/15 
  Installing : gcc-c++-4.4.7-4.el6.x86_64                                 13/15 
  Installing : openssl-devel-1.0.1e-15.el6.x86_64                         14/15 
  Installing : pcre-devel-7.8-6.el6.x86_64                                15/15 
local/productid                                          | 1.7 kB     00:00 ... 
  Verifying  : pcre-devel-7.8-6.el6.x86_64                                 1/15 
  Verifying  : libstdc++-devel-4.4.7-4.el6.x86_64                          2/15 
  Verifying  : libsepol-devel-2.0.41-4.el6.x86_64                          3/15 
  Verifying  : keyutils-libs-devel-1.4-4.el6.x86_64                        4/15 
  Verifying  : cpp-4.4.7-4.el6.x86_64                                      5/15 
  Verifying  : libcom_err-devel-1.41.12-18.el6.x86_64                      6/15 
  Verifying  : openssl-devel-1.0.1e-15.el6.x86_64                          7/15 
  Verifying  : libselinux-devel-2.0.94-5.3.el6_4.1.x86_64                  8/15 
  Verifying  : mpfr-2.4.1-6.el6.x86_64                                     9/15 
  Verifying  : zlib-devel-1.2.3-29.el6.x86_64                             10/15 
  Verifying  : gcc-4.4.7-4.el6.x86_64                                     11/15 
  Verifying  : krb5-devel-1.10.3-10.el6_4.6.x86_64                        12/15 
  Verifying  : gcc-c++-4.4.7-4.el6.x86_64                                 13/15 
  Verifying  : ppl-0.10.2-11.el6.x86_64                                   14/15 
  Verifying  : cloog-ppl-0.15.7-1.2.el6.x86_64                            15/15 
Installed:
  gcc.x86_64 0:4.4.7-4.el6                   gcc-c++.x86_64 0:4.4.7-4.el6       
  openssl-devel.x86_64 0:1.0.1e-15.el6       pcre-devel.x86_64 0:7.8-6.el6      
  zlib-devel.x86_64 0:1.2.3-29.el6          
Dependency Installed:
  cloog-ppl.x86_64 0:0.15.7-1.2.el6                                             
  cpp.x86_64 0:4.4.7-4.el6                                                      
  keyutils-libs-devel.x86_64 0:1.4-4.el6                                        
  krb5-devel.x86_64 0:1.10.3-10.el6_4.6                                         
  libcom_err-devel.x86_64 0:1.41.12-18.el6                                      
  libselinux-devel.x86_64 0:2.0.94-5.3.el6_4.1                                  
  libsepol-devel.x86_64 0:2.0.41-4.el6                                          
  libstdc++-devel.x86_64 0:4.4.7-4.el6                                          
  mpfr.x86_64 0:2.4.1-6.el6                                                     
  ppl.x86_64 0:0.10.2-11.el6                                                    
Complete!

(以上輸出表示包和編譯工具安裝成功?。?/p>

安裝成功后在進(jìn)入redis解壓的目錄中執(zhí)行make命令:

[root@caiji redis-3.2.8]# make
(以下是命令輸出)
cd src && make all
make[1]: Entering directory `/var/software/redis-3.2.8/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html
(cd ../deps && make distclean)
make[2]: Entering directory `/var/software/redis-3.2.8/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd geohash-int && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
..........
省略部分輸出。。。。。
..........
    CC crc16.o
    CC endianconv.o
    CC slowlog.o
    CC scripting.o
    CC bio.o
    CC rio.o
    CC rand.o
    CC memtest.o
    CC crc64.o
    CC bitops.o
    CC sentinel.o
    CC notify.o
    CC setproctitle.o
    CC blocked.o
    CC hyperloglog.o
    CC latency.o
    CC sparkline.o
    CC redis-check-rdb.o
    CC geo.o
    LINK redis-server
    INSTALL redis-sentinel
    CC redis-cli.o
    LINK redis-cli
    CC redis-benchmark.o
    LINK redis-benchmark
    INSTALL redis-check-rdb
    CC redis-check-aof.o
    LINK redis-check-aof
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory `/var/software/redis-3.2.8/src'

(自此執(zhí)行make成功?。?/p>

PS: 注意如果make顯示錯(cuò)誤,按照以下方法解決: 如果提示couldn’t execute tcl : no such file or
dicrectory,請自行安裝tcl; 如果提示

請執(zhí)行make distclean,然后再make

make成功之后,會在/var/software/redis-3.2.8/src目錄下多出一些文件,如下:

然后執(zhí)行make install:

[root@caiji redis-3.2.8]# make install
cd src && make install
make[1]: Entering directory `/var/software/redis-3.2.8/src'
Hint: It's a good idea to run 'make test' ;)
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: Leaving directory `/var/software/redis-3.2.8/src'

執(zhí)行完make install后會在目錄/usr/local/bin下生成以下文件:

[root@caiji redis-3.2.8]# ll /usr/local/bin
total 26344
-rwxr-xr-x. 1 root root 5578239 May  5 11:01 redis-benchmark
-rwxr-xr-x. 1 root root   22185 May  5 11:01 redis-check-aof
-rwxr-xr-x. 1 root root 7827882 May  5 11:01 redis-check-rdb
-rwxr-xr-x. 1 root root 5707107 May  5 11:01 redis-cli
lrwxrwxrwx. 1 root root    12 May  5 11:01 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 7827882 May  5 11:01 redis-server

查看redis版本號:

[root@caiji redis-3.2.8]# /usr/local/bin/redis-server -v
Redis server v=3.2.8 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=1882e7b0ae5da5a3

(自此redis安裝完成)

配置redis:

[root@caiji redis-3.2.8]# ./utils/install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]            ----直接默認(rèn)下一步,端口號默認(rèn)為6379
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]    ----默認(rèn)下一步,此處配置文件名和位置
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]    ----默認(rèn)下一步,此處日志名和位置
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]   ----默認(rèn)下一步,數(shù)據(jù)文件存放位置
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]     ----默認(rèn)下一步,redis服務(wù)路徑位置 
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/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!

(自此redis配置成功,并且為開機(jī)啟動方式)

然后根據(jù)要求對redis的配置文件進(jìn)行修改:

[root@caiji redis-3.2.8]# vim /etc/redis/6379.conf

修改項(xiàng)看截圖,根據(jù)截圖找到修改項(xiàng),修改成截圖中的值:

Linux系統(tǒng)如何安裝Redis服務(wù)

Linux系統(tǒng)如何安裝Redis服務(wù)
Linux系統(tǒng)如何安裝Redis服務(wù)
Linux系統(tǒng)如何安裝Redis服務(wù)
Linux系統(tǒng)如何安裝Redis服務(wù)
Linux系統(tǒng)如何安裝Redis服務(wù)

配置文件修改完畢后將redis服務(wù)停止:

[root@caiji redis-3.2.8]# /etc/init.d/redis_6379 stop
Stopping ...
Waiting for Redis to shutdown ...
Redis stopped

然后重新啟動:

[root@caiji redis-3.2.8]# /etc/init.d/redis_6379 start
Starting Redis server...

查看進(jìn)程無誤,表示修改成功:

[root@caiji redis-3.2.8]# ps -ef | grep redis
root     32106     1  0 11:31 ?        00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379        
root     32111  3030  0 11:31 pts/0    00:00:00 grep redis

(自此redis安裝配置完畢,并且是啟動狀態(tài)!)

三、Redis服務(wù)查看、開啟、關(guān)閉:

1.通過ps -ef|grep redis命令查看Redis進(jìn)程:

[root@caiji redis-3.2.8]# ps -ef | grep redis
root     32106     1  0 11:31 ?        00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379        
root     32111  3030  0 11:31 pts/0    00:00:00 grep redis

2.開啟Redis服務(wù)操作通過/etc/init.d/redis_6379 start命令,也可通過:service redis_6379 start

3.關(guān)閉Redis服務(wù)操作通過/etc/init.d/redis_6379 stop命令,也可通過:service redis_6379 stop

四、修改Redis用戶root密碼

為了提高安全性可以對Redis中root用戶設(shè)置密碼。
方法如下:
1.臨時(shí)修改,重啟后失效:

[root@local ~]# cd /usr/local/bin[root@local bin]# ll
otal 26344
-rwxr-xr-x. 1 root root 5578239 May  5 11:01 redis-benchmark
-rwxr-xr-x. 1 root root   22185 May  5 11:01 redis-check-aof
-rwxr-xr-x. 1 root root 7827882 May  5 11:01 redis-check-rdb
-rwxr-xr-x. 1 root root 5707107 May  5 11:01 redis-cli
lrwxrwxrwx. 1 root root    12 May  5 11:01 redis-sentinel -> redis-server-
rwxr-xr-x. 1 root root 7827882 May  5 11:01 redis-server
[root@local bin]# ./redis-cli
127.0.0.1:6379> config set requirepass pwtest10
OK
127. 0.0.1:6379> auth pwtest10
OK
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "pwtest10"

以上設(shè)置密碼命令 “config set requirepass pwtest10” 將Redis的root用戶密碼設(shè)置為pwtest10,查詢密碼使用命令 “config get requirepass”,但是這是臨時(shí)設(shè)置,如果重啟Redis,密碼就會失效。

2.永久設(shè)置密碼:
打開Redis的配置文件 /etc/redis/6379.conf 找到配置參數(shù) ** # requirepass foobared ** 此參數(shù)是備注釋掉的,去掉注釋修改為 ** requirepass pwtest10 **。

配置文件修改后重啟Redis即可。

上述就是小編為大家分享的Linux系統(tǒng)如何安裝Redis服務(wù)了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI