歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux管理 >> Linux配置 >> CentOS下Redis安裝配置

CentOS下Redis安裝配置

日期:2017/2/27 14:57:41   编辑:Linux配置
1、yum安裝
[root@biao ~]# yum install redis
Loaded plugins: fastestmirror
Determining fastest mirrors
* epel: mirrors.ustc.edu.cn
addons                                                                                                | 1.9 kB     00:00     
base                                                                                                  | 1.1 kB     00:00     
epel                                                                                                  | 3.7 kB     00:00     
epel/primary_db                                                                                       | 3.1 MB     00:02     
extras                                                                                                | 2.1 kB     00:00     
update                                                                                                | 1.9 kB     00:00     
update/primary_db                                                                                     | 941 kB     00:00     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package redis.i386 0:2.4.10-1.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================
Package                     Arch                       Version                             Repository                  Size
=============================================================================================================================
Installing:
redis                       i386                       2.4.10-1.el5                        epel                       299 k

Transaction Summary
=============================================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 299 k
Is this ok [y/N]: y
Downloading Packages:
redis-2.4.10-1.el5.i386.rpm                                                                           | 299 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : redis                                                                                                 1/1 

Installed:
  redis.i386 0:2.4.10-1.el5                                                                                                  

Complete!

2、檢查安裝的文件及目錄
[root@biao ~]# find / -name "redis*"
/usr/share/doc/redis-2.4.10
/usr/sbin/redis-server
/usr/bin/redis-check-aof
/usr/bin/redis-check-dump
/usr/bin/redis-benchmark
/usr/bin/redis-cli
/var/log/redis
/var/lib/redis
/var/run/redis
/etc/redis.conf
/etc/rc.d/init.d/redis
/etc/logrotate.d/redis
注意主要的的幾個安裝目錄:/usr/sbin/redis-server:redis啟動服務目錄。/etc/redis.conf:redis服務讀取的參數配置文件。

3、在/etc/redis.conf文件中配置參數:
作為簡單測試,只需要了解並正確配置其中的幾個參數,此版本默認設置即可。

daemonize:指定Redis是否後台運行。
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes

port:指定連接端口。
# Accept connections on the specified port, default is 6379.
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379

bind:綁定的地址。
# If you want you can bind a single interface, if the bind option is not
# specified all the interfaces will listen for incoming connections.
#
bind 127.0.0.1

4、啟動redis-server
[root@biao ~]# redis-server /etc/redis.conf

可以通過pstree或者ps aux|grep命令檢驗redis是否啟動成功:
[root@biao ~]# pstree
...
├─redis-server───2*[{redis-server}]
...

[root@biao ~]# ps aux|grep redis-server
root      6508  0.0  0.0  31060  1116 ?        Ssl  01:26   0:00 redis-server /etc/redis.conf
root      6581  0.0  0.0   4024   684 pts/7    R+   01:28   0:00 grep redis-server

5、連接Redis並簡單測試操作
[root@biao ~]# telnet localhost 6379
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
set test hello
+OK
get test
$5
hello
如上所示,Redis安裝成功並運行正常。
Copyright © Linux教程網 All Rights Reserved