您好,登錄后才能下訂單哦!
這期內容當中小編將會給大家帶來有關Linux系統如何安裝Redis服務,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
準備工作:將包括redis在內的redis-3.2.8.tar.gz安裝包放到指定位置(此位置可以自建,為了統一,全部放在/var/software/目錄下)
(1)解壓redis安裝包:
[root@caiji software]# tar -xvf redis-3.2.8.tar.gz ...... ......
進入解壓后的文件中:
[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
(以下為輸出內容,如果有的包已經安裝過的話,輸出內容會有所差別,大體是一樣的!)
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!
(以上輸出表示包和編譯工具安裝成功!)
安裝成功后在進入redis解壓的目錄中執行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'
(自此執行make成功!)
PS: 注意如果make顯示錯誤,按照以下方法解決: 如果提示couldn’t execute tcl : no such file or
dicrectory,請自行安裝tcl; 如果提示請執行make distclean,然后再make
make成功之后,會在/var/software/redis-3.2.8/src目錄下多出一些文件,如下:
然后執行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'
執行完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] ----直接默認下一步,端口號默認為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] ----默認下一步,此處日志名和位置 Selected default - /var/log/redis_6379.log Please select the data directory for this instance [/var/lib/redis/6379] ----默認下一步,數據文件存放位置 Selected default - /var/lib/redis/6379 Please select the redis executable path [/usr/local/bin/redis-server] ----默認下一步,redis服務路徑位置 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配置成功,并且為開機啟動方式)
然后根據要求對redis的配置文件進行修改:
[root@caiji redis-3.2.8]# vim /etc/redis/6379.conf
修改項看截圖,根據截圖找到修改項,修改成截圖中的值:
配置文件修改完畢后將redis服務停止:
[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...
查看進程無誤,表示修改成功:
[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安裝配置完畢,并且是啟動狀態!)
1.通過ps -ef|grep redis命令查看Redis進程:
[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服務操作通過/etc/init.d/redis_6379 start命令,也可通過:service redis_6379 start
3.關閉Redis服務操作通過/etc/init.d/redis_6379 stop命令,也可通過:service redis_6379 stop
為了提高安全性可以對Redis中root用戶設置密碼。
方法如下:
1.臨時修改,重啟后失效:
[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"
以上設置密碼命令 “config set requirepass pwtest10” 將Redis的root用戶密碼設置為pwtest10,查詢密碼使用命令 “config get requirepass”,但是這是臨時設置,如果重啟Redis,密碼就會失效。
2.永久設置密碼:
打開Redis的配置文件 /etc/redis/6379.conf 找到配置參數 ** # requirepass foobared ** 此參數是備注釋掉的,去掉注釋修改為 ** requirepass pwtest10 **。
配置文件修改后重啟Redis即可。
上述就是小編為大家分享的Linux系統如何安裝Redis服務了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。