资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

redis3.2.3安装

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

从策划到设计制作,每一步都追求做到细腻,制作可持续发展的企业网站。为客户提供网站设计制作、网站建设、网站策划、网页设计、域名注册虚拟主机、网络营销、VI设计、 网站改版、漏洞修补等服务。为客户提供更好的一站式互联网解决方案,以客户的口碑塑造优易品牌,携手广大客户,共同发展进步。

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  #在开机脚本里追加此命令


文章题目:redis3.2.3安装
新闻来源:http://cdkjz.cn/article/gesgpc.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220