命令:wget+网址±P+安装指定目录
wget http://download.redis.io/releases/redis-4.0.1.tar.gz -P /usr/local/install-package/
##解压
tar -zxvf install-package/redis-4.0.1.tar.gz -C /usr/local/
##更改文件夹名
mv redis-4.0.1/ redis
cd redis/
##编译
make
这是由于系统没有安装gcc环境,因此在进行编译时才会出现上面提示,当安装好gcc后再进行编译时,上面错误提示将消失。
MAKE hiredis
cd hiredis && make static
make[3]: 进入目录“/usr/local/redis/deps/hiredis”
gcc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb net.c
make[3]: gcc:命令未找到
make[3]: *** [net.o] 错误 127
make[3]: 离开目录“/usr/local/redis/deps/hiredis”
make[2]: *** [hiredis] 错误 2
make[2]: 离开目录“/usr/local/redis/deps”
make[1]: [persist-settings] 错误 2 (忽略)
CC adlist.o
/bin/sh: cc: 未找到命令
make[1]: *** [adlist.o] 错误 127
make[1]: 离开目录“/usr/local/redis/src”
make: *** [all] 错误 2
yum -y install gcc automake autoconf libtool make
[root@localhost redis]# make
cd src && make all
make[1]: 进入目录“/usr/local/redis/src”
CC Makefile.dep
make[1]: 离开目录“/usr/local/redis/src”
make[1]: 进入目录“/usr/local/redis/src”
CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录
#include
^
编译中断。
make[1]: *** [adlist.o] 错误 1
make[1]: 离开目录“/usr/local/redis/src”
make: *** [all] 错误 2
make MALLOC=libc
此时进入到src目录下,进行测试
命令:make test
如果报以下错误
[root@localhost src]# make test
CC Makefile.dep
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] 错误 1
TCL(Tool Command Language)工具脚本语言,是Linux内的一种语言包。,这里需要先安装tcl。
##下载
wget https://sourceforge.net/projects/tcl/files/Tcl/8.6.8/tcl8.6.8-src.tar.gz -P /usr/local/install-package/
##解压
tar -zxvf /usr/local/install-package/tcl8.6.8-src.tar.gz -C /usr/local/
##进入TCL目录
cd tcl8.6.8/
##进入unix目录
cd unix/
##执行
./configure
##编译
make
##安装
make install
##再次进行测试
cd /usr/local/redis/src/
make test
##执行结束就会出现一大堆绿色的,表示测试成功
\o/ All tests passed without errors!
Cleanup: may take some time... OK
**命令:make PREFIX=/usr/local/redis install **
[root@localhost src]# make PREFIX=/usr/local/redis install
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
再进行查看
[root@localhost redis]# cd ../
[root@localhost redis]# ls
00-RELEASENOTES CONTRIBUTING INSTALL README.md runtest-cluster src
bin COPYING Makefile redis.conf runtest-sentinel tests
BUGS deps MANIFESTO runtest sentinel.conf utils
[root@localhost redis]# cd bin/
[root@localhost bin]# ls
##多了几个命令工具⬇⬇⬇
redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server
方式一:前端启动
**命令:./redis-server **
##进入bin目录下执行命令
[root@localhost bin]# ./redis-server
21916:C 11 Jul 01:50:50.689 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21916:C 11 Jul 01:50:50.689 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=21916, just started
21916:C 11 Jul 01:50:50.689 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
21916:M 11 Jul 01:50:50.690 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.1 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 21916
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
21916:M 11 Jul 01:50:50.692 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
21916:M 11 Jul 01:50:50.692 # Server initialized
21916:M 11 Jul 01:50:50.692 # 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.
21916:M 11 Jul 01:50:50.692 # 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.
21916:M 11 Jul 01:50:50.692 * Ready to accept connections
这样已经启动完了,但是这属于前端启动,控制台不能进行任何操作,只能ctrl+c退出启动
方式二:后端启动
##编辑redis.conf
vi redis.conf
## 部分内容如下,此时按下键盘的“/”,并输入“daemonize”,定位到“daemonize no”,按下字母“i”表示编辑,将其改为yes,然后按“Esc”,再按出英文的“:”,输入“wq”,表示保存并退出,回车
# Redis configuration file example.
#
# Note that in order to read the configuration file, Redis must be
# started with the file path as first argument:
#
# ./redis-server /path/to/redis.conf
# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
编辑完成后,再次启动
命令:./bin/redis-server ./redis.conf
## 执行命令
[root@localhost redis]# ./bin/redis-server ./redis.conf
21959:C 11 Jul 02:04:33.230 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21959:C 11 Jul 02:04:33.230 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=21959, just started
21959:C 11 Jul 02:04:33.230 # Configuration loaded
我们来看下后台是否已启动redis
命令:ps -ef | grep -i redis
## 输入命令查询是否已启动
[root@localhost ~]# ps -ef | grep -i redis
root 21960 1 0 02:04 ? 00:00:00 ./bin/redis-server 127.0.0.1:6379
root 21966 1560 0 02:06 pts/0 00:00:00 grep --color=auto -i redis
[root@localhost redis]# ./bin/redis-cli shutdown
[root@localhost redis]# ./bin/redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set String_key_1 String_value_1
OK
127.0.0.1:6379> get String_key_1
"String_value_1"
127.0.0.1:6379> keys *
1) "String_key_1"
127.0.0.1:6379> append String_key_1 _I_am_append
(integer) 26
127.0.0.1:6379> keys *
1) "String_key_1"
127.0.0.1:6379> get String_key_1
"String_value_1_I_am_append"
127.0.0.1:6379> del String_key_1
(integer) 1
127.0.0.1:6379> get String_key_1
(nil)
127.0.0.1:6379>