Linux下安装Redis
(1)下载
root@VM_0_17_centos redis]# wget http://download.redis.io/releases/redis-4.0.10.tar.gz
(2)解压缩
[root@VM_0_17_centos redis]# tar -xzf redis-4.0.10.tar.gz
(3)make编译文件
root@VM_0_17_centos redis-4.0.10]# make
编译之后的文件在redis-4.0.10/src
若make失败并提示找不到命令,可能是没有安装GCC环境,可以通过以下命令进行安装。
yum install -y gcc-c++
(4)make install 安装
root@VM_0_17_centos redis-4.0.10]# make
[root@VM_0_17_centos src]# make install
CC Makefile.dep
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
(5)修改配置文件
配置文件就在redis-4.0.10目录下的redis.conf
root@VM_0_17_centos redis-4.0.10]# vim redis.conf
开启后台运行==》 daemonize no ==》 改成yes
关闭仅允许127.0.0.1连接 ==》 bind 127.0.0.1 注释掉
设置密码 ==》 requirepass 后追加 你的密码
(6)开启,关闭,重启
服务在redis下的src目录下,可cd到src 再执行命令
指定配置文件开启redis服务
[root@VM_0_17_centos src]# redis-server ../redis.conf
18639:C 24 Aug 22:04:34.558 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
18639:C 24 Aug 22:04:34.558 # Redis version=4.0.10, bits=64, commit=00000000, modified=0, pid=18639, just started
18639:C 24 Aug 22:04:34.558 # Configuration loaded
客户端连接本机redis
[root@VM_0_17_centos src]# redis-cli
127.0.0.1:6379> set name 1
OK
127.0.0.1:6379> get name
"1"
127.0.0.1:6379> exit
客户端里进行关闭(这种方式,当redis再运行中关闭+ aof模式,会自动保存)
[root@VM_0_17_centos src]# redis-cli -h localhost
localhost:6379> shutdown
not connected>
not connected>
not connected>
not connected> exit
[root@VM_0_17_centos src]# redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Could not connect to Redis at 127.0.0.1:6379: Connection refused
结束进程的方式进行关闭
[root@VM_0_17_centos src]# ps -ef |grep redis-server
root 21310 1 0 22:21 ? 00:00:00 redis-server 127.0.0.1:6379
root 21532 13318 0 22:23 pts/1 00:00:00 grep --color=auto redis-server
[root@VM_0_17_centos src]# kill -9 21310
[root@VM_0_17_centos src]# redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> exit
说明:也可以通过systemctl 的命令控制redis的开启重启关闭等,另行百度