Redis 单点部署
服务器信息
ip | 系统 | 配置 | 目录 |
---|---|---|---|
172.24.32.200 | centos7.7 | 2c4g | /data/redis/ |
部署
官网
https://redis.io/topics/quickstart
1、单机部署
关闭防火墙
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0
systemctl stop firewalld
systemctl disable firewalld
安装依赖
yum install wget vim net-tools gcc -y
创建目录
mkdir -p /data/redis && cd /data/redis
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
踩坑1
cd src && make all
make[1]: Entering directory `/data/redis/redis-stable/src'
CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
#include <jemalloc/jemalloc.h>
^
compilation terminated.
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/data/redis/redis-stable/src'
make: *** [all] Error 2
查看README
Allocator
---------
Selecting a non-default memory allocator when building Redis is done by setting
the `MALLOC` environment variable. Redis is compiled and linked against libc
malloc by default, with the exception of jemalloc being the default on Linux
systems. This default was picked because jemalloc has proven to have fewer
fragmentation problems than libc malloc.
To force compiling against libc malloc, use:
% make MALLOC=libc
To compile against jemalloc on Mac OS X systems, use:
% make MALLOC=jemalloc
Verbose build
重新编译
make MALLOC=libc
踩坑2
^
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’:
查看gcc版本并且升级
[root@localhost redis-stable]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
升级gcc
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
##临时生效
scl enable devtoolset-9 bash
##永久生效
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
重新编译
make && make install
2、修改配置文件
mkdir -p /etc/redis
cp redis.conf /etc/redis/redis_16379.conf
###绑定的ip
sed -i 's|bind 127.0.0.1|bind 172.24.32.200|g' /etc/redis/redis_16379.conf
###修改默认端口
sed -i 's|port 6379|port 16379|g' /etc/redis/redis_16379.conf
###守护进程
sed -i 's|daemonize no|daemonize yes|g' /etc/redis/redis_16379.conf
###加密码
sed -i '$arequirepass aj3jaHSk3n4' /etc/redis/redis_16379.conf
###redis日志
sed -i 's|logfile ""|logfile "/var/log/redis.log"|g' /etc/redis/redis_16379.conf
启动文件
cat >>/usr/lib/systemd/system/redis16379.service<<EOF
[Unit]
Description=redis16379
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis_16379.pid
ExecStart=/usr/local/bin/redis-server /etc/redis/redis_16379.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
启动和开机自启动
systemctl start redis16379
systemctl enable redis16379
查看/var/log/redis.log,解决告警
20627:M 10 May 2020 22:39:22.774 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
20627:M 10 May 2020 22:39:22.774 # Server initialized
20627:M 10 May 2020 22:39:22.775 # 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.
20627:M 10 May 2020 22:39:22.775 # 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.
20627:M 10 May 2020 22:39:22.775 * Ready to accept connections
解决告警
echo 511 > /proc/sys/net/core/somaxconn
echo "net.core.somaxconn= 1024" >>/etc/sysctl.conf
sysctl -p
echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf
sysctl vm.overcommit_memory=1
echo never > /sys/kernel/mm/transparent_hugepage/enabled
开机自启动文件
cat>>/etc/rc.local<<EOF
##kernel
echo never > /sys/kernel/mm/transparent_hugepage/enabled
EOF
chmod +x /etc/rc.local
网友评论