温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

redis3.2.3安装

发布时间:2020-07-21 07:16:25 来源:网络 阅读:532 作者:qhd2004 栏目:数据库

要在centos7上安装redis的主从,下面记录一下安装过程。

cd /apps
wget http://download.redis.io/releases/redis-3.2.3.tar.gz
tar -zxvf redis-3.2.3.tar.gz
cd redis-3.2.3
make 
make install

安装过程中会显示把redis放在什么目录下:下面是安装过程中的一部分

XSLTPROC           : /usr/bin/xsltproc
XSLROOT            : 

PREFIX             : /usr/local
BINDIR             : /usr/local/bin
DATADIR            : /usr/local/share
INCLUDEDIR         : /usr/local/include
LIBDIR             : /usr/local/lib
MANDIR             : /usr/local/share/man

redis安装到/usr/local,/usr/local/bin,/usr/local/share,/usr/local/include,/usr/local/lib,/usr/local/share/man目录下


软件安装完成,下面是初始化数据:

切换到utils目录下,执行redis初始化脚本install_server.sh

cd utils
./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

初始化后

配置文件为/etc/redis/6379.conf,

日志文件为/var/log/redis_6379.log,

数据文件dump.rdb存放到/var/lib/redis/6379目录下,

启动脚本为/etc/init.d/redis_6379


查看日志发现有如下warning

28000:M 09 Sep 13:33:02.917 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
28000:M 09 Sep 13:33:02.917 # Server started, Redis version 3.2.3
28000:M 09 Sep 13:33:02.917 # 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.
28000:M 09 Sep 13:33:02.917 # 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.
28000:M 09 Sep 13:33:02.917 * The server is now ready to accept connections on port 6379

如下解决:

1,第一个错误大概是说somaxconn的值128设置过小,从/proc/sys/net/core/somaxconn这个路径也可大概知道这个值的设置是关于网络连接中某个最大值的限定设置,此值表示网络连接的队列大小,在配置文件redis.conf中的“tcp-backlog 511”就配置在高并发环境下的最大队列大小,此值受限于系统的somaxconn与tcp_max_syn_backlog这两个值,所以应该把这两个内核参数值调大,具体解决方法如下:


$ vim /etc/sysctl.conf

$ net.core.somaxconn = 20480  #最大队列长度,应付突发的大并发连接请求,默认为128

$ net.ipv4.tcp_max_syn_backlog = 20480  #半连接队列长度,此值受限于内存大小,默认为1024

$ sysctl -p  #使参数生效


2,警告:过量使用内存设置为0!在低内存环境下,后台保存可能失败。为了修正这个问题,请在/etc/sysctl.conf 添加一项 'vm.overcommit_memory = 1' ,然后重启(或者运行命令'sysctl vm.overcommit_memory=1' )使其生效。


vm.overcommit_memory不同的值说明:


0 表示检查是否有足够的内存可用,如果是,允许分配;如果内存不够,拒绝该请求,并返回一个错误给应用程序。

1 允许分配超出物理内存加上交换内存的请求

2 内核总是返回true


redis的数据回写机制分为两种


同步回写即SAVE命令。redis主进程直接写数据到磁盘。当数据量大时,这个命令将阻塞,响应时间长

异步回写即BGSAVE命令。redis 主进程fork一个子进程,复制主进程的内存并通过子进程回写数据到磁盘。

由于RDB文件写的时候fork一个子进程。相当于复制了一个内存镜像。当时系统的内存是4G,而redis占用了近3G的内存,因此肯定会报内存无法分配。如果 「vm.overcommit_memory」设置为0,在可用内存不足的情况下,就无法分配新的内存。如果 「vm.overcommit_memory」设置为1。 那么redis将使用交换内存。

解决方法


$ vim /etc/sysctl

$ vm.overcommit_memory = 1  #末尾追加

$ sysctl -p  #参数生效

注:使用交换内存并不是一个完美的方案。最好的办法是扩大物理内存。


3,Transparent Huge Pages (THP)告警,这是一个关于透明内存巨页的话题。简单来说内存可管理的最小单位是page,一个page通常是4kb,那1M内存就会有256个page,CPU通过内置的内存管理单元管理page表记录。Huge Pages就是表示page的大小已超过4kb了,一般是2M到1G,它的出现主要是为了管理超大内存。个人理解上TB的内存。而THP就是管理Huge Pages的一个抽象层次,根据一些资料显示THP会导致内存锁影响性能,所以一般建议关闭此功能。

   /sys/kernel/mm/transparent_hugepage/enabled有三个值,如下:

  $ cat /sys/kernel/mm/transparent_hugepage/enabled

    always [madvise] never

    ####

    # always 尽量使用透明内存,扫描内存,有512个 4k页面可以整合,就整合成一个2M的页面

    # never 关闭,不使用透明内存

    # madvise 避免改变内存占用

关于THP的内容就介绍到这里,现在根据警告是做些修改:


$ vim /etc/rc.local

$ echo never > /sys/kernel/mm/transparent_hugepage/enabled  #在开机脚本里追加此命令


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI