centos7 安装redis 服务详解
下载redis
-
下载redis 安装包
[root@miao soft]# wget http://download.redis.io/releases/redis-4.0.10.tar.gz
--2018-12-14 15:28:34-- http://download.redis.io/releases/redis-4.0.10.tar.gz
Resolving download.redis.io (download.redis.io)... 109.74.203.151
Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1738465 (1.7M) [application/x-gzip]
Saving to: ‘redis-4.0.10.tar.gz’
100%[========================================================>] 1,738,465 441KB/s in 3.9s
2018-12-14 15:28:38 (441 KB/s) - ‘redis-4.0.10.tar.gz’ saved [1738465/1738465]
-
解压到当前目录
tar -zxvf redis-4.0.10.tar.gz
[root@miao soft]# tar -zxvf redis-4.0.10.tar.gz
redis-4.0.10/
redis-4.0.10/.gitignore
redis-4.0.10/00-RELEASENOTES
redis-4.0.10/BUGS
redis-4.0.10/CONTRIBUTING
redis-4.0.10/COPYING
redis-4.0.10/INSTALL
......
......
编译安装
-
安装gcc 环境
yum -y install gcc-c++
-
进入redis 解压目录,编译
[root@miao soft]# cd redis-4.0.10
[root@miao redis-4.0.10]# make
cd src && make all
make[1]: Entering directory `/usr/local/soft/redis-4.0.10/src'
CC Makefile.dep
make[1]: Leaving directory `/usr/local/soft/redis-4.0.10/src'
make[1]: Entering directory `/usr/local/soft/redis-4.0.10/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 Makefile.dep dict-benchmark
(cd ../deps && make distclean)
make[2]: Entering directory `/usr/local/soft/redis-4.0.10/deps'
(cd hiredis && make clean) >
...
...
LINK redis-cli
CC redis-benchmark.o
LINK redis-benchmark
INSTALL redis-check-rdb
INSTALL redis-check-aof
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory `/usr/local/soft/redis-4.0.10/src'
- 指定目录进行安装
在这里我指定的安装目录是/usr/local/soft/redis
[root@miao redis-4.0.10]# make install PREFIX=/usr/local/soft/redis
cd src && make install
make[1]: Entering directory `/usr/local/soft/redis-4.0.10/src'
CC Makefile.dep
make[1]: Leaving directory `/usr/local/soft/redis-4.0.10/src'
make[1]: Entering directory `/usr/local/soft/redis-4.0.10/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 `/usr/local/soft/redis-4.0.10/src'
配置redis
将当前目录下的redis.conf 移动到redis 安装目录下:
[root@miao redis-4.0.10]# mv redis.conf /usr/local/soft/redis
进入安装目录:
[root@miao redis-4.0.10]# cd /usr/local/soft/redis && ll
total 64
drwxr-xr-x 2 root root 4096 Dec 14 16:03 bin
-rw-rw-r-- 1 root root 58766 Jun 13 2018 redis.conf
编辑redis.conf 配置文件
[root@miao redis]# vi redis.conf
基本没什么要改的:
- port 6379 配置端口
- bind 0.0.0.0 配置外网访问
- daemonize yes 配置后台运行
启动redis
[root@miao redis]# ./bin/redis-server redis.conf
25663:C 14 Dec 16:18:03.558 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
25663:C 14 Dec 16:18:03.558 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=25663, just started
25663:C 14 Dec 16:18:03.558 # Configuration loaded
验证正确性
使用redis 命令行客户端插入一条数据:
[root@miao redis]# ./bin/redis-cli
127.0.0.1:6379> set name redis
OK
127.0.0.1:6379> get name
"redis"
127.0.0.1:6379>