CentOS安装Redis 6.0.9

什么是Redis?


 

Redis通常被称为数据结构服务器。这意味着Redis通过一组命令提供对可变数据结构的访问,这些命令是使用带有TCP套接字和简单协议服务器-客户端模型发送的因此,不同的进程可以以共享的方式查询和修改相同的数据结构。

在Redis中实现的数据结构具有一些特殊属性:

  • 即使始终为它们提供服务并将它们修改到服务器内存中,Redis也会将它们存储在磁盘上。这意味着Redis速度很快,但它也是非易失性的。
  • 数据结构的实现强调内存效率,因此与使用高级编程语言建模的相同数据结构相比,Redis内部的数据结构可能使用较少的内存。
  • Redis提供了许多自然可以在数据库中找到的功能,例如复制,持久性的可调级别,集群和高可用性。

另一个很好的例子是将Redis视为memcached的一个更复杂的版本,其中的操作不仅是SET和GET,而且还适用于诸如列表,集合,有序数据结构等复杂数据类型的操作。

 

Redis 6.0 新特性


Redis 6.0引入了SSL,新的RESP3协议,ACL,客户端缓存,无盘副本,I / O线程,更快的RDB加载,新的模块API以及许多其他改进。

 

安装依赖包

[root@Mike-Node1 ~]#  yum -y install tcl gcc gcc-c++  make zlib zlib-devel

 

下载编译安装

[root@Mike-Node1 ~]# wget https://download.redis.io/releases/redis-6.0.9.tar.gz
[root@Mike-Node1 ~]# tar zxvf redis-6.0.9.tar.gz -C /usr/local/ && rm -rf redis-6.0.9.tar.gz
[root@Mike-Node1 ~]# cd /usr/local/redis-6.0.9/
[root@Mike-Node1 /usr/local/redis-6.0.9]# make && make install PREFIX=/usr/local/redis

遇到报错

server.c: In function ‘allPersistenceDisabled’:
server.c:1484:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
server.c: In function ‘writeCommandsDeniedByDiskError’:
server.c:3934:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
server.c: In function ‘iAmMaster’:
server.c:5134:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
make[1]: *** [server.o] Error 1
make[1]: Leaving directory `/usr/local/redis-6.0.9/src'
make: *** [all] Error 2

出现这种错误是由于Redis6.0版本以上要求gcc需要5.3版本以上,升级gcc即可

默认gcc版本

[root@Mike-Node1 ~]# gcc -v
***********

gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
[root@Mike-Node1 ~]#

升级gcc版本

[root@Mike-Node1 ~]# yum -y install centos-release-scl
[root@Mike-Node1 ~]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
[root@Mike-Node1 ~]# echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
[root@Mike-Node1 ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-9/root/usr --mandir=/opt/rh/devtoolset-9/root/usr/share/man --infodir=/opt/rh/devtoolset-9/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-9.3.1-20200408/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC) 
[root@Mike-Node1 ~]# 

 

修改配置文件

[root@Mike-Node1 /usr/local/redis-6.0.9]# cp -rf redis.conf /usr/local/redis/
[root@Mike-Node1 /usr/local/redis-6.0.9]# cd /usr/local/redis
[root@Mike-Node1 /usr/local/redis]# vim redis.conf

bind 127.0.0.1
daemonize yes
requirepass mike666
protected-mode no
logfile /usr/local/redis/logs/redis.log
dir /usr/local/redis/data

[root@Mike-Node1 /usr/local/redis]#
[root@Mike-Node1 /usr/local/redis]# mkdir logs data
[root@Mike-Node1 /usr/local/redis]# 

设置 redis密码  mike666,日志路径和数据存储路径

 

启动Redis

[root@Mike-Node1 /usr/local/redis]# vim /etc/systemd/system/redis.service

[Unit]
Description=redis-server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

[root@Mike-Node1 /usr/local/redis]#
[root@Mike-Node1 /usr/local/redis]# systemctl daemon-reload
[root@Mike-Node1 /usr/local/redis]# systemctl start redis.service
[root@Mike-Node1 /usr/local/redis]# systemctl enable redis.service
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /etc/systemd/system/redis.service.
[root@Mike-Node1 /usr/local/redis]# 

 

设置软连接

[root@Mike-Node1 ~]# ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis

 

启动警告解决

17468:M 16 Dec 2020 10:54:26.205 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
17468:M 16 Dec 2020 10:54:26.205 # Server initialized
17468:M 16 Dec 2020 10:54:26.205 # 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.
17468:M 16 Dec 2020 10:54:26.205 # 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 madvise > /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 (set to 'madvise' or 'never').
17468:M 16 Dec 2020 10:54:26.205 * Ready to accept connections

解决一

[root@Mike-Node1 ~]# vim /etc/sysctl.conf 

net.core.somaxconn = 1024
vm.overcommit_memory = 1


[root@Mike-Node1 ~]# sysctl -p

解决二

[root@Mike-Node1 ~]# vim /etc/rc.local

echo never > /sys/kernel/mm/transparent_hugepage/enabled


[root@Mike-Node1 ~]# source /etc/rc.local 
[root@Mike-Node1 ~]# systemctl restart redis

 

服务操作命令

systemctl start redis.service     #启动redis服务

systemctl stop redis.service     #停止redis服务

systemctl restart redis.service   #重新启动服务

systemctl status redis.service   #查看服务当前状态

systemctl enable redis.service   #设置开机自启动

systemctl disable redis.service   #停止开机自启动

 

客户端连接

[root@Mike-Node1 ~]# redis -h 127.0.0.1 -p 6379
127.0.0.1:6379> AUTH mike666
OK
127.0.0.1:6379> 

 

本文分享完毕,感谢支持点赞~~

posted @ 2020-12-16 11:31  背锅的Mike  阅读(448)  评论(0编辑  收藏  举报