redis安装【redis-3.0.7】

下载redis源码安装包

[root@k8smaster ~]# wget "http://download.redis.io/releases/redis-3.0.7.tar.gz"
[root@k8smaster redis]# pwd
/data/redis
[root@k8smaster redis]# ls -lrt
total 1344
-rw-r--r-- 1 root root 1375200 Jan 28  2016 redis-3.0.7.tar.gz

编译安装

[root@k8smaster redis]# tar -xf redis-3.0.7.tar.gz #解压
[root@k8smaster redis]# 
[root@k8smaster redis-3.0.7]# yum install gcc* 安装编译工具gcc
[root@k8smaster redis-3.0.7]# make
cd src && make all
make[1]: Entering directory `/data/redis/redis-3.0.7/src'
    CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory #使用 make MALLOC=libc进行编译
 #include <jemalloc/jemalloc.h>
compilation terminated.
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/data/redis/redis-3.0.7/src'
make: *** [all] Error 2
[root@k8smaster redis-3.0.7]# 
[root@k8smaster redis-3.0.7]# make MALLOC=libc  # 默认make MALLOC=jemalloc
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory `/data/redis/redis-3.0.7/src'
[root@k8smaster redis-3.0.7]# cd src/
[root@k8smaster src]# make install
Hint: It's a good idea to run 'make test' ;)
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
[root@k8smaster src]#

配置启动

方便管理,将Redis文件中的conf配置文件和常用命令移动到统一文件中
[root@k8smaster redis]# mkdir redis
[root@k8smaster redis]# cd redis
[root@k8smaster redis]# mkdir bin  #存放redis命令
[root@k8smaster redis]# mkdir config #存放配置文件
[root@k8smaster redis]# ls -lrt
total 0
drwxr-xr-x 2 root root 6 Feb 11 13:29 bin
drwxr-xr-x 2 root root 6 Feb 11 13:29 config
[root@k8smaster redis]# pwd
/data/redis/redis
[root@k8smaster redis]#
[root@k8smaster src]# cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server ../../redis/bin/   #拷贝命令
[root@k8smaster redis-3.0.7]# cp redis.conf /data/redis/redis/config/ #拷贝配置文件
[root@k8smaster bin]# vim /data/redis/redis/config/redis.conf  #编辑配置文件
#daemonize no
daemonize yes # #修改daemonize为yes,以守护进程方式运行
# bind 127.0.0.1
bind 192.168.23.100 #以支持包括外网在内的所有IP
logfile /data/redis/redis/log/redis.log  #设置日志文件
loglevel debug
# requirepass foobared
requirepass 123456  #设置密码

[root@k8smaster bin]# ./redis-server /data/redis/redis/config/redis.conf  #启动redis
[root@k8smaster bin]#
[root@k8smaster bin]# netstat -apn|grep redis  #Redis server使用默认端口6379
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      3866/./redis-server 
tcp6       0      0 :::6379                 :::*                    LISTEN      3866/./redis-server 
[root@k8smaster bin]# 

[root@k8smaster bin]# ./redis-cli -h 192.168.23.100 -p 6379 -a 123456 #客户端访问,测试
192.168.23.100:6379> ping
PONG
192.168.23.100:6379> 
192.168.23.100:6379> set test zhaiky
OK
192.168.23.100:6379> get test
"zhaiky"
192.168.23.100:6379> 

[root@k8smaster bin]# ./redis-cli -h 192.168.23.100 -p 6379 -a 123456 shutdown #关闭redis
3885:M 11 Feb 13:55:38.051 - DB 0: 1 keys (0 volatile) in 4 slots HT.
3885:M 11 Feb 13:55:38.051 - 0 clients connected (0 slaves), 832176 bytes in use
3885:M 11 Feb 13:55:39.839 - Accepted 192.168.23.100:40462
3885:M 11 Feb 13:55:39.839 # User requested shutdown...
3885:M 11 Feb 13:55:39.839 * Saving the final RDB snapshot before exiting. #服务端接收到停止服务的命令后,并没有立即停止运行,而是做了一个Saving的操作,因此,如果采用kill -9 pid的方式杀死redis进程,可能导致部分数据丢失!
3885:M 11 Feb 13:55:39.844 * DB saved on disk
3885:M 11 Feb 13:55:39.844 * Removing the pid file.
3885:M 11 Feb 13:55:39.844 # Redis is now ready to exit, bye bye..
 

发布了60 篇原创文章 · 获赞 20 · 访问量 4580

猜你喜欢

转载自blog.csdn.net/zhaikaiyun/article/details/105004699