编译安装redisd的方法示例详解

 更新时间:2021年1月15日 13:19  点击:2313

安装方法:

yum安装

查看yum仓库redis版本

[root@centos ~]# yum list redis
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Available Packages
redis.x86_64  3.2.12-2.el7  myepel

yum安装

[root@centos ~]# yum install redis -y

启动服务并设为开机启动

[root@centos ~]# systemctl enable --now redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service. 

查看redis端口

[root@centos ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port 
LISTEN 0 128 127.0.0.1:631  *:*  
LISTEN 0 100 127.0.0.1:25  *:*  
LISTEN 0 128 127.0.0.1:6010  *:*  
LISTEN 0 128 *:54909  *:*  
LISTEN 0 128 127.0.0.1:6379  *:*  # 这个是redis端口
LISTEN 0 128 *:111  *:*  
LISTEN 0 5 192.168.122.1:53  *:* 

测试登录redis

[root@centos ~]# redis-cli
127.0.0.1:6379> info
# Server
redis_version:3.2.12
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:7897e7d0e13773f
redis_mode:standalone
os:Linux 3.10.0-1062.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.5
process_id:2914
run_id:c75137717c54caa78bb05757d05c91471ef5817f
tcp_port:6379
uptime_in_seconds:175
uptime_in_days:0
hz:10
lru_clock:4329484
executable:/usr/bin/redis-server
config_file:/etc/redis.conf

# Clients
connected_clients:1
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

测试使用

127.0.0.1:6379> set key1 value1
OK
127.0.0.1:6379> get key1
"value1"

编译安装

下载当前最新release版本redis源码包:http://download.redis.io/releases/

编译安装命令

官方安装命令:https://redis.io/download

# 源码包存放目录
[root@centos ~]# cd /usr/local/src/
# 下载源码包
[root@centos src]# wget http://download.redis.io/releases/redis-5.0.7.tar.gz
--2020-02-11 10:37:54-- http://download.redis.io/releases/redis-5.0.7.tar.gz
Resolving download.redis.io (download.redis.io)... 109.74.203.151
Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1984203 (1.9M) [application/x-gzip]
Saving to: ‘redis-5.0.7.tar.gz'
100%[===============================================>] 1,984,203 6.75KB/s in 3m 35s 
2020-02-11 10:41:39 (9.02 KB/s) - ‘redis-5.0.7.tar.gz' saved [1984203/1984203]
# 查看下载好的源码包
[root@centos src]# ll
total 1940
-rw-r--r-- 1 root root 1984203 Nov 20 01:06 redis-5.0.7.tar.gz

解压源码包

[root@centos src]# tar xf redis-5.0.7.tar.gz 
[root@centos src]# ll
total 1940
drwxrwxr-x 6 root root 334 Nov 20 01:05 redis-5.0.7
-rw-r--r-- 1 root root 1984203 Nov 20 01:06 redis-5.0.7.tar.gz

创建配置文件、日志、数据等目录

[root@centos ~]# mkdir /apps/redis/{etc,logs,data,run} -p
# 查看目录结构
[root@centos ~]# tree /apps/
/apps/
└── redis
 ├── data
 ├── etc
 ├── logs
 └── run

进入redis目录编译安装

[root@centos ~]# cd /usr/local/src/redis-5.0.7/
[root@centos redis-5.0.7]# make PREFIX=/apps/redis install
cd src && make install
make[1]: Entering directory `/usr/local/src/redis-5.0.7/src'
 CC Makefile.dep
make[1]: Leaving directory `/usr/local/src/redis-5.0.7/src'
make[1]: Entering directory `/usr/local/src/redis-5.0.7/src'
 CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/usr/local/src/redis-5.0.7/src'
make: *** [install] Error 2

# 出现以上报错是没有gcc编译器导致的
# 下载gcc编译器
[root@centos redis-5.0.7]# yum install gcc
# 记得这里要把之前的redis目录删除重新解压
[root@centos src]# rm -rf redis-5.0.7
[root@centos src]# tar xf redis-5.0.7.tar.gz 

# 重新进入目录进行编译
[root@centos src]# cd redis-5.0.7/
[root@centos redis-5.0.7]# make PREFIX=/apps/redis install # 指定安装目录
cd src && make install
make[1]: Entering directory `/usr/local/src/redis-5.0.7/src'
 CC Makefile.dep
make[1]: Leaving directory `/usr/local/src/redis-5.0.7/src'
make[1]: Entering directory `/usr/local/src/redis-5.0.7/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep dict-benchmark
(cd ../deps && make distclean)
make[2]: Entering directory `/usr/local/src/redis-5.0.7/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
make[2]: Leaving directory `/usr/local/src/redis-5.0.7/deps'
(rm -f .make-*)
....(省略)
Hint: It's a good idea to run 'make test' ;)

 INSTALL install
 INSTALL install
 INSTALL install
 INSTALL install
 INSTALL install
make[1]: Leaving directory `/usr/local/src/redis-5.0.7/src'
# 最后报这个就是编译完成

拷贝配置文件

[root@centos redis-5.0.7]# ll 
total 276
-rw-rw-r-- 1 root root 115100 Nov 20 01:05 00-RELEASENOTES
-rw-rw-r-- 1 root root 53 Nov 20 01:05 BUGS
-rw-rw-r-- 1 root root 2381 Nov 20 01:05 CONTRIBUTING
-rw-rw-r-- 1 root root 1487 Nov 20 01:05 COPYING
drwxrwxr-x 6 root root 192 Feb 11 11:32 deps
-rw-rw-r-- 1 root root 11 Nov 20 01:05 INSTALL
-rw-rw-r-- 1 root root 151 Nov 20 01:05 Makefile
-rw-rw-r-- 1 root root 6888 Nov 20 01:05 MANIFESTO
-rw-rw-r-- 1 root root 20555 Nov 20 01:05 README.md
-rw-rw-r-- 1 root root 61797 Nov 20 01:05 redis.conf
-rwxrwxr-x 1 root root 275 Nov 20 01:05 runtest
-rwxrwxr-x 1 root root 280 Nov 20 01:05 runtest-cluster
-rwxrwxr-x 1 root root 373 Nov 20 01:05 runtest-moduleapi
-rwxrwxr-x 1 root root 281 Nov 20 01:05 runtest-sentinel
-rw-rw-r-- 1 root root 9710 Nov 20 01:05 sentinel.conf
drwxrwxr-x 3 root root 8192 Feb 11 11:33 src
drwxrwxr-x 11 root root 182 Nov 20 01:05 tests
drwxrwxr-x 8 root root 4096 Nov 20 01:05 utils
[root@centos redis-5.0.7]# cp redis.conf /apps/redis/etc/

启动redis(这个启动方式)

[root@centos redis-5.0.7]# /apps/redis/bin/redis-server /apps/redis/etc/redis.conf 
8315:C 11 Feb 2020 11:40:12.016 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8315:C 11 Feb 2020 11:40:12.016 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=8315, just started
8315:C 11 Feb 2020 11:40:12.016 # Configuration loaded
8315:M 11 Feb 2020 11:40:12.017 * Increased maximum number of open files to 10032 (it was originally set to 1024).
 _._    
 _.-``__ ''-._   
 _.-`` `. `_. ''-._ Redis 5.0.7 (00000000/0) 64 bit
 .-`` .-```. ```\/ _.,_ ''-._   
 ( ' , .-` | `, ) Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
 | `-._ `._ / _.-' | PID: 8315
 `-._ `-._ `-./ _.-' _.-'   
 |`-._`-._ `-.__.-' _.-'_.-'|   
 | `-._`-._ _.-'_.-' | http://redis.io 
 `-._ `-._`-.__.-'_.-' _.-'   
 |`-._`-._ `-.__.-' _.-'_.-'|   
 | `-._`-._ _.-'_.-' |   
 `-._ `-._`-.__.-'_.-' _.-'   
 `-._ `-.__.-' _.-'   
 `-._ _.-'   
 `-.__.-'   

8315:M 11 Feb 2020 11:40:12.017 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
8315:M 11 Feb 2020 11:40:12.017 # Server initialized
8315:M 11 Feb 2020 11:40:12.017 # 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.
8315:M 11 Feb 2020 11:40:12.017 # 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.
8315:M 11 Feb 2020 11:40:12.018 * Ready to accept connections

解决当前的警告提示

tcp-backlog
The backlog argument defines the maximum length to which the queue of pending connections for sockfdmay grow. If a connection request arrives when the queue is full, the client may receive an error with an indication of ECONNREFUSED or, if the underlying protocol supports retransmission, the request may be ignored so that a later reattempt at connection succeeds.

backlog参数控制的是三次握手的时候server端收到client ack确认号之后的队列值。

[root@centos ~]# echo 511 > /proc/sys/net/core/somaxconn
vm.overcommit_memory

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

[root@centos ~]# echo "vm.overcommit_memory = 1" >/etc/sysctl.conf
transparent hugepage
大页内存动态分配,需要关闭让redis 负责内存管理。
[root@centos ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled

重启一下服务

# 再次启动服务,警告信息没有了。
[root@centos ~]# /apps/redis/bin/redis-server /apps/redis/etc/redis.conf 
1847:C 13 Feb 2020 12:03:59.281 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1847:C 13 Feb 2020 12:03:59.281 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=1847, just started
1847:C 13 Feb 2020 12:03:59.281 # Configuration loaded
1847:M 13 Feb 2020 12:03:59.282 * Increased maximum number of open files to 10032 (it was originally set to 1024).
 _._    
 _.-``__ ''-._   
 _.-`` `. `_. ''-._ Redis 5.0.7 (00000000/0) 64 bit
 .-`` .-```. ```\/ _.,_ ''-._   
 ( ' , .-` | `, ) Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
 | `-._ `._ / _.-' | PID: 1847
 `-._ `-._ `-./ _.-' _.-'   
 |`-._`-._ `-.__.-' _.-'_.-'|   
 | `-._`-._ _.-'_.-' | http://redis.io 
 `-._ `-._`-.__.-'_.-' _.-'   
 |`-._`-._ `-.__.-' _.-'_.-'|   
 | `-._`-._ _.-'_.-' |   
 `-._ `-._`-.__.-'_.-' _.-'   
 `-._ `-.__.-' _.-'   
 `-._ _.-'   
 `-.__.-'   

1847:M 13 Feb 2020 12:03:59.282 # Server initialized
1847:M 13 Feb 2020 12:03:59.282 * DB loaded from disk: 0.000 seconds
1847:M 13 Feb 2020 12:03:59.282 * Ready to accept connections

编辑redis服务启动脚本

[root@centos ~]# cat /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
#ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd
ExecStart=/apps/redis/bin/redis-server /apps/redis/etc/redis.conf --supervised systemd
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
Type=notify
User=redis
Group=redisRuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target

添加redis用户

# 添加用户和组
[root@centos ~]# groupadd -g 1001 redis && useradd -u 1001 -g 1001 redis -s /sbin/nologin
# 数据目录设置所有者所属组
[root@centos ~]# chown redis.redis -R /apps/redis/
system启动测试
# 开启redis并设为开机启动
[root@centos ~]# systemctl enable --now redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.
# 查看端口
[root@centos ~]# ss -tnl
State Recv-Q Send-Q   Local Address:Port    Peer Address:Port 
LISTEN 0 128   127.0.0.1:631     *:*  
LISTEN 0 100   127.0.0.1:25     *:*  
LISTEN 0 128   127.0.0.1:6010     *:*  
LISTEN 0 128   127.0.0.1:6011     *:*  
LISTEN 0 128    *:43108     *:*  
LISTEN 0 511   127.0.0.1:6379     *:* # 这个为redis端口 
LISTEN 0 128    *:111     *:*  
LISTEN 0 5   192.168.122.1:53     *:*  
LISTEN 0 128    *:22     *:*  
LISTEN 0 128    [::1]:631     [::]:*  
LISTEN 0 100    [::1]:25     [::]:*  
LISTEN 0 128    [::1]:6010    [::]:*  
LISTEN 0 128    [::1]:6011    [::]:*  
LISTEN 0 128    [::]:59279    [::]:*  
LISTEN 0 128    [::]:111     [::]:*  
LISTEN 0 128 [::]:22     [::]:* 

客户端连接redis测试

# 这里还没有把这个命令加到PATH变量里
[root@centos ~]# /apps/redis/bin/redis-cli 
127.0.0.1:6379> info
# Server
redis_version:5.0.7
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:b0887378c143d6e9
redis_mode:standalone
os:Linux 3.10.0-1062.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:4.8.5
process_id:2088
run_id:e0bbd2dc1561d1610565c6c8fb61aa817e30924c
tcp_port:6379

创建命令软连接(也可以把这个路径加到PATH变量里面)

[root@centos ~]# ln -sv /apps/redis/bin/redis-* /usr/bin/
‘/usr/bin/redis-benchmark' -> ‘/apps/redis/bin/redis-benchmark'
‘/usr/bin/redis-check-aof' -> ‘/apps/redis/bin/redis-check-aof'
‘/usr/bin/redis-check-rdb' -> ‘/apps/redis/bin/redis-check-rdb'
‘/usr/bin/redis-cli' -> ‘/apps/redis/bin/redis-cli'
‘/usr/bin/redis-sentinel' -> ‘/apps/redis/bin/redis-sentinel'
‘/usr/bin/redis-server' -> ‘/apps/redis/bin/redis-server'
# 命令连接测试
[root@centos ~]# redis-cli 
127.0.0.1:6379> info
# Server
redis_version:5.0.7
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:b0887378c143d6e9
redis_mode:standalone
os:Linux 3.10.0-1062.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:4.8.5
process_id:2088
run_id:e0bbd2dc1561d1610565c6c8fb61aa817e30924c
tcp_port:6379
uptime_in_seconds:755
uptime_in_days:0
[root@centos ~]# ll /apps/redis/bin/
total 32772
-rwxr-xr-x 1 redis redis 4366824 Feb 11 11:33 redis-benchmark # redis性能测试工具
-rwxr-xr-x 1 redis redis 8125216 Feb 11 11:33 redis-check-aof # AOF文件检查工具
-rwxr-xr-x 1 redis redis 8125216 Feb 11 11:33 redis-check-rdb # RDB文件检查工具 
-rwxr-xr-x 1 redis redis 4807896 Feb 11 11:33 redis-cli # 客户端工具
lrwxrwxrwx 1 redis redis 12 Feb 11 11:33 redis-sentinel -> redis-server # 哨兵软连接到server
-rwxr-xr-x 1 redis redis 8125216 Feb 11 11:33 redis-server # redis 服务启动命令

**以上就是redis的安装方法和一些小问题的解决方法了!**

总结

以上所述是小编给大家介绍的编译安装redisd的方法示例详解,希望对大家有所帮助,也非常感谢大家对猪先飞网站的支持!

[!--infotagslink--]

相关文章

  • PHP7快速编译安装的步骤

    编译安装非常的简单了我们现在的php版本已经到了php7了,下文小编来为各位介绍一篇关于PHP7快速编译安装的步骤,希望文章能够帮助到各位。 一、安装必要一些依赖 yum...2016-11-25
  • Rstudio中安装package出现的问题及解决

    这篇文章主要介绍了Rstudio中安装package出现的问题及解决方案,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-05-06
  • PHP编译安装后PHP-FPM使用笔记

    PHP-FPM我们相信各位用高版本的php经常使用到了,下面整理了一些关于PHP-FPM的笔记,有兴趣的可进来看看。 今天赶上了123System OPenVZ VPS全场半价的机会,购入了一...2016-11-25
  • 安装和使用percona-toolkit来辅助操作MySQL的基本教程

    一、percona-toolkit简介 percona-toolkit是一组高级命令行工具的集合,用来执行各种通过手工执行非常复杂和麻烦的mysql和系统任务,这些任务包括: 检查master和slave数据的一致性 有效地对记录进行归档 查找重复的索...2015-11-24
  • Linux安装Pytorch1.8GPU(CUDA11.1)的实现

    这篇文章主要介绍了Linux安装Pytorch1.8GPU(CUDA11.1)的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-25
  • vscode安装git及项目开发过程

    这篇文章主要介绍了vscode安装git及项目开发过程,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-05-19
  • Visual Studio 2015下载和安装图文教程

    这篇文章主要为大家详细介绍了Visual Studio 2015下载和安装图文教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-09-22
  • Node调试工具JSHint的安装及配置教程

    现在我们介绍一种在Node下检查简单错误的JS代码验证工具JSHint。  JSHint的具体介绍参考http://www.jshint.com/about/,说直白点儿,JSHint就是一个检查JS代码规范与否的工具,它可以用来检查任何(包括server端和client端...2014-05-31
  • Centos中彻底删除Mysql(rpm、yum安装的情况)

    我用的centos6,mysql让我整出了各种问题,我想重装一个全新的mysql,yum remove mysql-server mysql之后再install并不能得到一个干净的mysql,原来的/etc/my.cnf依然没变,datadir里面的数据已没有任何变化,手动删除/etc/my.cn...2015-03-15
  • Ubuntu20.04安装cuda10.1的步骤(图文教程)

    这篇文章主要介绍了Ubuntu20.04安装cuda10.1的步骤(图文教程),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-07-30
  • 在PyCharm中安装PaddlePaddle的方法

    这篇文章主要介绍了在PyCharm中安装PaddlePaddle的方法,本文给大家介绍的非常想详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-02-05
  • Postman安装与使用详细教程 附postman离线安装包

    这篇文章主要介绍了Postman安装与使用详细教程 附postman离线安装包,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-03-05
  • VSCode C++多文件编译的简单使用方法

    这篇文章主要介绍了VSCode C++多文件编译的简单使用方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-03-29
  • linux服务器快速卸载安装node环境(简单上手)

    这篇文章主要介绍了linux服务器快速卸载安装node环境(简单上手),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-22
  • Vue3 编译流程-源码解析

    今天将从 Vue 的入口文件开始,看看声明了一个 Vue 的单文件之后是如何被 compile-core 编译核心模块编译成渲染函数的。下面小编讲解并附上代码分析展现在文章里,感兴趣的小伙伴不要错过奥...2021-09-25
  • vs2019安装和使用详细图文教程

    这篇文章主要介绍了vs2019安装和使用详细图文教程,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • uni-app从安装到卸载的入门教程

    这篇文章主要介绍了uni-app从安装到卸载的入门教程,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-05-15
  • RHEL6.5编译安装MySQL5.6.26教程

    一、准备编译环境,安装所需依赖包yum groupinstall 'Development' -y yum install openssl openssl-devel zlib zlib-devel -y yum install readline-devel pcre-devel ncurses-devel bison-devel cmake -y二、编译安...2015-10-21
  • tomcat9 下载安装和配置+整合到eclipse的教程详解

    这篇文章主要介绍了tomcat9 下载安装和配置+整合到eclipse,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-07-28
  • vscode和cmake编译多个C++文件的实现方法

    这篇文章主要介绍了vscode和cmake编译多个C++文件的实现方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-10