yum install gcc
[root@mmjredis local]# yum install gcc
wget http://download.redis.io/releases/redis-6.0.1.tar.gz
[root@mmjredis src]# wget http://download.redis.io/releases/redis-6.0.1.tar.gz
出现下载解析错误
[root@mmjredis src]# wget http://download.redis.io/releases/redis-6.0.1.tar.gz
--2020-05-06 11:16:01-- http://download.redis.io/releases/redis-6.0.1.tar.gz
Resolving download.redis.io (download.redis.io)... failed: Name or service not known.
wget: unable to resolve host address ‘download.redis.io’
解决办法:编辑/etc/resolv.conf文件
[root@mmjredis src]# vim /etc/resolv.conf
增加Google的DNS服务器IP
options timeout:2 attempts:3 rotate single-request-reopen
; generated by /usr/sbin/dhclient-script
nameserver 100.100.2.138
nameserver 100.100.2.136
nameserver 8.8.8.8
nameserver 8.8.4.4
再次执行下载
[root@mmjredis src]# wget http://download.redis.io/releases/redis-6.0.1.tar.gz
[root@mmjredis src]# tar -zxvf redis-6.0.1.tar.gz
[root@mmjredis src]# tar -zxvf redis-6.0.1.tar.gz
cd redis-6.0.1
[root@mmjredis src]# cd redis-6.0.1
make PREFIX=/usr/local/redis install
[root@mmjredis redis-6.0.1]# make PREFIX=/usr/local/redis install
出现错误
serverLog(LL_NOTICE,"The server is now ready to accept connections at %s", server.unixsocket);
^
server.c:5103:19: error: ‘struct redisServer’ has no member named ‘supervised_mode’
if (server.supervised_mode == SUPERVISED_SYSTEMD) {
^
server.c:5104:24: error: ‘struct redisServer’ has no member named ‘masterhost’
if (!server.masterhost) {
^
server.c:5117:15: error: ‘struct redisServer’ has no member named ‘maxmemory’
if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {
^
server.c:5117:39: error: ‘struct redisServer’ has no member named ‘maxmemory’
if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {
^
server.c:5118:176: error: ‘struct redisServer’ has no member named ‘maxmemory’
serverLog(LL_WARNING,"WARNING: You specified a maxmemory value that is less than 1MB (current value is %llu bytes). Are you sure this is what you really want?", server.maxmemory);
^
server.c: In function ‘hasActiveChildProcess’:
server.c:1476:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
server.c: In function ‘allPersistenceDisabled’:
server.c:1482:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
server.c: In function ‘writeCommandsDeniedByDiskError’:
server.c:3747:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
server.c: In function ‘iAmMaster’:
server.c:4914:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
make[1]: *** [server.o] Error 1
make[1]: Leaving directory `/usr/src/redis-6.0.1/src'
make: *** [install] Error 2
解决办法:
# 查看gcc版本是否在5.3以上,centos7.6默认安装4.8.5
gcc -v
# 升级gcc到5.3及以上,如下:
升级到gcc 9.3:
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
需要注意的是scl命令启用只是临时的,退出shell或重启就会恢复原系统gcc版本。
如果要长期使用gcc 9.3的话:
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
这样退出shell重新打开就是新版的gcc了
以下其他版本同理,修改devtoolset版本号即可。
再次编译安装
[root@mmjredis redis-6.0.1]# 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
make[1]: Leaving directory '/usr/src/redis-6.0.1/src'
先切换到 usr/local/redis/bin目录
[root@mmjredis bin]# cd /usr/local/redis/bin
./redis-server
[root@mmjredis bin]# ./redis-server
[root@mmjredis bin]# ./redis-server
7404:C 06 May 2020 12:03:04.482 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7404:C 06 May 2020 12:03:04.482 # Redis version=6.0.1, bits=64, commit=00000000, modified=0, pid=7404, just started
7404:C 06 May 2020 12:03:04.482 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.0.1 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 7404
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
7404:M 06 May 2020 12:03:04.483 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7404:M 06 May 2020 12:03:04.483 # Server initialized
7404:M 06 May 2020 12:03:04.483 # 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.
7404:M 06 May 2020 12:03:04.483 # 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.
7404:M 06 May 2020 12:03:04.483 * Loading RDB produced by version 6.0.1
7404:M 06 May 2020 12:03:04.483 * RDB age 224 seconds
7404:M 06 May 2020 12:03:04.483 * RDB memory usage when created 0.77 Mb
7404:M 06 May 2020 12:03:04.483 * DB loaded from disk: 0.000 seconds
7404:M 06 May 2020 12:03:04.483 * Ready to accept connections
如上图:redis启动成功,但是这种启动方式需要一直打开窗口,不能进行其他操作,不太方便。
按 ctrl + c可以关闭窗口。
将安装包的redis.conf文件拷贝道bin目录下
[root@mmjredis bin]# cp /usr/src/redis-6.0.1/redis.conf redis.conf
修改redis.conf文件
将
daemonize no
修改为
daemonize yes
指定redis.conf文件启动
[root@mmjredis bin]# ./redis-server redis.conf
[root@mmjredis bin]# ./redis-server redis.conf
7464:C 06 May 2020 12:19:28.484 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7464:C 06 May 2020 12:19:28.484 # Redis version=6.0.1, bits=64, commit=00000000, modified=0, pid=7464, just started
7464:C 06 May 2020 12:19:28.484 # Configuration loaded
关闭redis进程
首先使用ps -aux | grep redis查看redis进程
[root@mmjredis bin]# ps -aux|grep redis
root 7465 0.0 0.0 162196 7848 ? Ssl 12:19 0:00 ./redis-server 127.0.0.1:6379
root 7476 0.0 0.0 112648 972 pts/0 S+ 12:20 0:00 grep --color=auto redis
使用kill命令杀死进程
[root@mmjredis bin]# kill 7465
1、在/etc目录下新建redis目录
mkdir redis
[root@mmjredis bin]# cd /etc
[root@mmjredis etc]# mkdir redis
2、将/usr/local/redis/bin/redis.conf 文件复制一份到/etc/redis目录下,并命名为6379.conf
[root@mmjredis utils]# cp /usr/local/redis/bin/redis.conf /etc/redis/6379.conf
3、将redis安装包中的启动脚本复制一份放到/etc/init.d目录下
[root@mmjredis bin]# cp /usr/src/redis-6.0.1/utils/redis_init_script /etc/init.d/redisd
4、设置redis开机自启动
先切换到/etc/init.d目录下
然后执行自启命令
[root@mmjredis bin]# cd /etc/init.d
[root@mmjredis init.d]# ls
aegis functions netconsole network README redisd
[root@mmjredis init.d]# chkconfig redisd on
5、现在可以直接以服务的形式启动和关闭redis了
启动:
service redisd start
[root@mmjredis init.d]# chkconfig redisd on
提示路径不正确的错误:
[root@mmjredis init.d]# service redisd start
Starting Redis server...
/etc/init.d/redisd: line 28: /usr/local/bin/redis-server: No such file or directory
解决办法:
打开redisd 修改为正确的路径
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
再次启动
[root@mmjredis init.d]# service redisd start
Starting Redis server...
7573:C 06 May 2020 13:05:09.487 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7573:C 06 May 2020 13:05:09.487 # Redis version=6.0.1, bits=64, commit=00000000, modified=0, pid=7573, just started
7573:C 06 May 2020 13:05:09.487 # Configuration loaded
关闭:
方法1:service redisd stop
[root@mmjredis init.d]# service redisd stop
Stopping ...
Redis stopped
方法2: /usr/local/redis/bin/redis-cli SHUTDOWN
推荐个redis 命令手册
http://doc.redisfans.com/index.html