编译安装redis-server

                         **

编译安装过程

**

如果支持systemd需要安装下面包

[root@centos7 ~]#yum -y install gcc jemalloc-devel systemd-devel

下载源码

[root@centos7 ~]#wget http://download.redis.io/releases/redis-6.2.4.tar.gz

解包

[root@centos7 ~]#tar xvf redis-6.2.4.tar.gz

编译安装

[root@centos7 ~]#cd redis-6.2.4/

指定redis安装目录

[root@centos7 redis-5.0.7]#make PREFIX=/apps/redis install

如果支持systemd,需要执行下面

[root@centos7 redis-6.2.4]#make USE_SYSTEMD=yes PREFIX=/apps/redis install

配置变量

[root@centos7 ~]#echo 'PATH=/apps/redis/bin:$PATH' > /etc/profile.d/redis.sh
[root@centos7 ~]#. /etc/profile.d/redis.sh

目录结构

[root@centos7 ~]#tree /apps/redis/ 

准备相关目录和配置文件

[root@centos7 ~]#mkdir /apps/redis/{etc,log,data,run}          #创建配置文件、日志、数据等目录
[root@centos7 redis-6.2.4]#cp redis.conf /apps/redis/etc/ 

前台启动 redis

[root@centos7 ~]#redis-server /apps/redis/etc/redis.conf

[root@centos7 ~]#ss -ntl
LISTEN       0     128       127.0.0.1:6379          *:* 

开启 redis 多实例

[root@centos7 ~]#redis-server --port 6380
[root@centos7 ~]#ss -ntl
LISTEN   0    511       *:6379        *:*
LISTEN   0    511       *:6380        *:* 
[root@centos7 ~]#ps -ef|grep redis
[root@centos7 ~]#redis-cli -p 6380   

解决启动时的三个警告提示

WARNING: The TCP backlog setting of 511 cannot be enforced because
/proc/sys/net/core/somaxconn is set to the lower value of 128.

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

第一个: backlog参数控制的是三次握手的时候server端收到client ack确认号之后的队列值,即全连接队列

第二个: 内核参数说明:
0、表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内
存申请失败,并把错误返回给应用进程。
1、表示内核允许分配所有的物理内存,而不管当前的内存状态如何
2、表示内核允许分配超过所有物理内存和交换空间总和的内存

直接添加下面的配置

[root@centos7 ~]#vim /etc/sysctl.conf
net.core.somaxconn = 1024
vm.overcommit_memory = 1
[root@centos7 ~]#sysctl -p

第三个: transparent hugepage

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.

警告:您在内核中启用了透明大页面(THP,不同于一般内存页的4k为2M)支持。 这将在Redis中造成延迟和
内存使用问题。 要解决此问题,请以root 用户身份运行命令“echo never>
/sys/kernel/mm/transparent_hugepage/enabled”,并将其添加到您的/etc/rc.local中,以便在
重启后保留设置。禁用THP后,必须重新启动Redis。

进行重定向,然后查看

[root@centos7 ~]#echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled'
>> /etc/rc.d/rc.local
[root@centos7 ~]#cat /etc/rc.d/rc.local

再次启动 redis

[root@centos7 ~]#redis-server /apps/redis/etc/redis.conf

创建 redis 用户和数据目录

[root@centos7 ~]#useradd -r -s /sbin/nologin redis

#设置目录权限
[root@centos7 ~]#chown -R redis.redis /apps/redis/

编辑 redis 服务启动文件
可以参考yum安装的service进行复制

[root@centos7 ~]#cat /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis persistent key-value database
After=network.target

[Service]
ExecStart=/apps/redis/bin/redis-server /apps/redis/etc/redis.conf --supervised systemd
ExecStop=/bin/kill -s QUIT $MAINPID
#Type=notify   如果支持systemd可以启用此行
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target

验证 redis 启动

[root@centos7 ~]#systemctl daemon-reload
[root@centos7 ~]#systemctl start redis
[root@centos7 ~]#systemctl status redis

使用客户端连接 redis

[root@centos7 ~]#redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> info

创建软链接

[root@centos7 ~]#ln -sv /apps/redis/bin/redis-* /usr/bin/

编译安装后的命令

[root@centos7 ~]#ll /apps/redis/bin/
total 32772
-rwxr-xr-x 1 root root 4366792 Feb 16 21:12 redis-benchmark #redis性能测试工具
-rwxr-xr-x 1 root root 8125184 Feb 16 21:12 redis-check-aof #AOF文件检查工具
-rwxr-xr-x 1 root root 8125184 Feb 16 21:12 redis-check-rdb #RDB文件检查工具
-rwxr-xr-x 1 root root 4807856 Feb 16 21:12 redis-cli       #客户端工具
lrwxrwxrwx 1 root root 12 Feb 16 21:12 redis-sentinel -> redis-server #哨兵,软连接到server
-rwxr-xr-x 1 root root 8125184 Feb 16 21:12 redis-server    #redis 服务启动命令

这就实现了redis的编译安装全程

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值