centos7.5 安装 redis-4.0.11
Posted BrokenColor
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7.5 安装 redis-4.0.11相关的知识,希望对你有一定的参考价值。
1.下载redis包
wget wget http://download.redis.io/releases/redis-4.0.11.tar.gz
2.解压安装
#解压 tar zxvf redis-4.0.11.tar.gz #安装 cd redis-4.0.11 #执行make
#执行make时报错:/bin/sh: cc: command not found--如果没报错可跳过
sudo yum -y install gcc gcc-c++ libstdc++-devel ##报错 # make[1]: Entering directory `/opt/redis-2.6.14/src‘ # CC adlist.o # In file included from adlist.c:34: # zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory # zmalloc.h:55:2: error: #error "Newer version of jemalloc required" # make[1]: *** [adlist.o] Error 1 # make[1]: Leaving directory `/opt/redis-2.6.14/src‘ # make: *** [all] Error 2 #执行 make MALLOC=libc #执行完上面的命令后,系统提示 ‘Hint: To run ‘make test‘ is a good idea‘ make test #报错: You need tcl 8.5 or newer in order to run the Redis test #安装tcl sudo yum install tcl
继续执行
[[email protected] redis-4.0.11]# cd src && make install #Hint: It‘s a good idea to run ‘make test‘ ;) # INSTALL install # INSTALL install # INSTALL install # INSTALL install # INSTALL install #看到显示INSTALL install说明成功
3.验证启动redis-server
换到redis src目录下 cd src ./redis-server #7965:C 07 Nov 10:38:19.858 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo #7965:C 07 Nov 10:38:19.858 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=7965, just started #7965:C 07 Nov 10:38:19.858 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf #7965:M 07 Nov 10:38:19.860 * Increased maximum number of open files to 10032 (it was originally set to 1024). # _._ # _.-``__ ‘‘-._ # _.-`` `. `_. ‘‘-._ Redis 4.0.11 (00000000/0) 64 bit # .-`` .-```. ```/ _.,_ ‘‘-._ # ( ‘ , .-` | `, ) Running in standalone mode # |`-._`-...-` __...-.``-._|‘` _.-‘| Port: 6379 # | `-._ `._ / _.-‘ | PID: 7965 # `-._ `-._ `-./ _.-‘ _.-‘ # |`-._`-._ `-.__.-‘ _.-‘_.-‘| # | `-._`-._ _.-‘_.-‘ | http://redis.io # `-._ `-._`-.__.-‘_.-‘ _.-‘ # |`-._`-._ `-.__.-‘ _.-‘_.-‘| # | `-._`-._ _.-‘_.-‘ | # `-._ `-._`-.__.-‘_.-‘ _.-‘ # `-._ `-.__.-‘ _.-‘ # `-._ _.-‘ # `-.__.-‘ # #7965:M 07 Nov 10:38:19.863 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. #7965:M 07 Nov 10:38:19.863 # Server initialized #7965:M 07 Nov 10:38:19.863 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1‘ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1‘ for this to take effect. #7965:M 07 Nov 10:38:19.863 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled‘ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. #7965:M 07 Nov 10:38:19.863 * Ready to accept connections #
4.配置
(1)配置为redis-server守护进程(即启动不会被redis-server占用窗口导致我们无法干别的事情)
#修改redis.conf [[email protected] src]# cd .. [[email protected] redis-4.0.11]# vim redis.conf #可通过查询命令:/daemonize 进行快速定位 daemonize yes # 守护进程模式开启 [[email protected] redis-4.0.11]# cd src/ [[email protected] src]# ./redis-server ../redis.conf #7976:C 07 Nov 10:52:22.184 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo #7976:C 07 Nov 10:52:22.184 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=7976, just started #7976:C 07 Nov 10:52:22.184 # Configuration loaded #查看时候启动 [[email protected] src]# ps -aux|grep redis #root 2835 0.0 0.1 150932 1540 pts/0 T 09:46 0:00 wget http://download.redis.io/releases/redis-4.0.11.tar.gz #root 7977 0.0 0.2 141836 2040 ? Ssl 10:52 0:00 ./redis-server 127.0.0.1:6379 #root 7982 0.0 0.0 112720 984 pts/0 R+ 10:53 0:00 grep --color=auto redis
(2)设置redis开机自启动
#使用kill命令杀死进程 [[email protected] redis-4.0.11]# kill -9 7977 #设置redis开机自启动 [[email protected] etc]# mkdir redis [[email protected] redis-4.0.11]# cp redis.conf /etc/redis/6379.conf [[email protected] redis-4.0.11]# cp utils/redis_init_script /etc/init.d/redisd [[email protected] redis-4.0.11]# cd /etc/init.d/ [[email protected] init.d]# chkconfig redisd on #service redisd does not support chkconfig #解决方法: #使用vim编辑redisd文件,在第一行加入如下两行注释,保存退出 # chkconfig: 2345 90 10 # description: Redis is a persistent key-value database #注释的意思是,redis服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,关闭的优先级是10。 [[email protected] var]# service redisd start #报错: /var/run/redis_6379.pid exists, process is already running or crashed #[重要]如果是没有数据的情况下 [[email protected] var]# rm /var/run/redis_6379.pid [[email protected] redis]# service redisd start #Starting Redis server... #8206:C 07 Nov 11:31:26.807 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo #8206:C 07 Nov 11:31:26.807 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=8206, just started #8206:C 07 Nov 11:31:26.807 # Configuration loaded [[email protected] redis]# ps -aux|grep redis #root 8207 0.0 0.1 38240 1988 ? Ssl 11:31 0:00 /usr/local/bin/redis-server 127.0.0.1:6379 #root 8212 0.0 0.0 112720 984 pts/0 R+ 11:31 0:00 grep --color=auto redis
测试一下redis-cli
#客户端测试 [[email protected] redis]# cd /soft/redis-4.0.11 [[email protected] redis-4.0.11]# cd src/ [[email protected] src]# ./redis-cli 127.0.0.1:6379> set "a" "valueA" #OK 127.0.0.1:6379> get "a" #"valueA"
以上是关于centos7.5 安装 redis-4.0.11的主要内容,如果未能解决你的问题,请参考以下文章