redis3.2.3安装
admin
2023-06-06 05:01:30
0

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


相关内容

热门资讯

美国特勤局:白宫附近枪击案嫌疑... 央视记者当地时间5月23日获悉,美国特勤局表示,当天白宫附近枪击案嫌疑人在医院死亡。美国特勤局表示,...
浙江宣传:年轻干部,不要怕普通 有没有那么一瞬间,你会觉得自己很普通,置身人潮人海中没有任何特别之处?其实,普通既是初入职场的年轻干...
Find My进入第三方时代:... 新闻引入 2026年1月,苹果发布AirTag 2代,精确查找范围提升50%、扬声器音量提升50%,...
精密散热行业的技术跃迁:从“被... 在功率密度持续攀升、热流密度逼近物理极限的行业节点,精密散热已经从一个“辅助性功能模块”演变为决定系...
湖南衡阳发生火灾致5死1伤 5月24日0时45分,衡阳市祁东县上正社区一商铺发生火灾,造成5人死亡,1人受轻微伤,伤者正在积极救...
警惕!澳大利亚密集加码关键矿产... 5月18日,澳大利亚以“国家安全”为由,向北方矿业公司6名与中国有关联的股东发出强制出售令,要求在1...
AI行情狂热,三星电子未成年股... 近段时间,AI行情再次成为全球资本市场主线,但舞台中央的“主角”发生了变化:投资者不再只偏好云厂商和...
俄称乌无人机袭击卢甘斯克一学校... 当地时间5月23日,据俄罗斯紧急情况部通报称,遭乌方袭击的斯塔罗比尔斯克职业学院死亡人数升至21人,...
美加州故障化学品储罐持续升温,... 新华社洛杉矶5月23日电(记者高山 谭晶晶)美国加利福尼亚州南部奥兰治县官员23日说,当地21日开始...
真实感,AI时代写作的生命力所... AI时代,对于许多人来说,因为有了各种智能工具的加持,写作似乎变得容易了。通过提出命题、投喂内容,无...