Linux下Redis安装指南(redis安装linux)

Redis是以内存中哈希表实现的,且支持存储的value类型多样,包括stirng(字符串),list(链表),set(集合),zset(sorted set:有序集合)和hashes(哈希类型)。在Linux系统安装使用Redis比较简单,这里给安装与配置Redis的指南:

### 一、安装

1.下载Redis源码

$ wget http://download.redis.io/releases/redis-stable.tar.gz

2.解压源码

$ tar xzf redis-stable.tar.gz

3.进入安装目录,执行Make安装

$ cd redis-stable
$ make

4.安装成功后,在src目录下生成redis-server/redis-cli/redis-benchmark等可执行文件,将其复制到其他路径:

# cd src
# cp redis-server /usr/local/bin/
# cp redis-cli /usr/local/bin/
# cp redis-benchmark /usr/local/bin/

### 二、配置

1.在/etc目录下,创建一个名为redis.conf的配置文件:

# sudo vim /etc/redis.conf

2.在配置文件中,将daemonize修改为yes, fork的作用是后台运行

# For systems that support it, there is an option of automated memory management.
# Set it to 'no' if you are one of these systems which needs to manually configure
# everything.
daemonize yes

3.修改端口号

# By default Redis listens for connections from all the network interfaces
# available on the server. It is possible to listen to just one or multiple
# interfaces using the "bind" configuration directive, followed by one or
# more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1
bind 0.0.0.0

# Specify the port number if you want Redis to listen on a different port
# than the default 6379
port 6379

4.配置允许存取远程IP

# If you want you can bind a single interface, and it will still accept
# connections from other interfaces:
#
# bind 127.0.0.1
# bind 192.168.1.100 10.0.0.1
# WARNING: The following item is not recommended.
# bind any other
protected-mode no

### 三、开启服务

1.使用命令启动服务

$ redis-server /etc/redis.conf

2.或者以守护进程运行

$ redis-server /etc/redis.conf --daemonize yes

### 四、测试

1.新起一个终端,测试Redis服务是否可用

$ redis-cli
$ ping
PONG

2.当返回的结果为PONG,说明Redis服务成功运行,服务安装配置已完成。


数据运维技术 » Linux下Redis安装指南(redis安装linux)