欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 焦点 > 银河麒麟V10ServerSP3中Redis7源码编译与安装详细教程

银河麒麟V10ServerSP3中Redis7源码编译与安装详细教程

2025/3/16 22:59:40 来源:https://blog.csdn.net/yuanjinshenglife/article/details/146248281  浏览:    关键词:银河麒麟V10ServerSP3中Redis7源码编译与安装详细教程

银河麒麟V10ServerSP3中Redis7源码编译与安装详细教程

文章目录

  • 银河麒麟V10ServerSP3中Redis7源码编译与安装详细教程
  • 1. 下载
  • 2. 安装过程
    • 1. 解压
    • 2. 编译源码
    • 3. 测试编译结果(可选)
    • 4. 安装Redis
    • 5. 安装位置
    • 6. 复制配置文件
    • 7. 修改redis.conf文件
    • 8. 启动Redis服务
    • 9. 客户端测试
    • 10. 设置开机自启动
  • 3. 开启远程访问
    • 1. 编辑redis.conf
    • 2. 开启防火墙
    • 3.测试远程连接

1. 下载

官网

github地址

github中Redis源码直接下载地址

本下载的版本为redis-7.4.1.tar.gz

2. 安装过程

1. 解压

[root@localhost ~]# cd /opt/mysoftware/
[root@localhost mysoftware]# ll
总用量 4704
drwxr-xr-x 2 root root       27 125 00:50 dm8
drwxr-xr-x 9  502 games     186 125 00:54 nginx-1.26.2
-rw-r--r-- 1 root root  1244789 125 00:51 nginx-1.26.2.tar.gz
-rw-r--r-- 1 root root  3567859 125 01:49 redis-7.4.1.tar.gz
[root@localhost mysoftware]# tar -zxvf redis-7.4.1.tar.gz 
redis-7.4.1/
redis-7.4.1/.codespell/
redis-7.4.1/.codespell/.codespellrc
redis-7.4.1/.codespell/requirements.txt
redis-7.4.1/.codespell/wordlist.txt
redis-7.4.1/.gitattributes
redis-7.4.1/.github/
..... # 中间内容过多这里省略显示
.....
redis-7.4.1/utils/req-res-validator/requirements.txt
redis-7.4.1/utils/speed-regression.tcl
redis-7.4.1/utils/srandmember/
redis-7.4.1/utils/srandmember/README.md
redis-7.4.1/utils/srandmember/showdist.rb
redis-7.4.1/utils/srandmember/showfreq.rb
redis-7.4.1/utils/systemd-redis_multiple_servers@.service
redis-7.4.1/utils/systemd-redis_server.service
redis-7.4.1/utils/tracking_collisions.c
redis-7.4.1/utils/whatisdoing.sh
[root@localhost mysoftware]# 

2. 编译源码

# 1. 进入到解压后的源码目录
[root@localhost ~]# cd /opt/mysoftware/redis-7.4.1/
[root@localhost redis-7.4.1]# ll
总用量 280
-rw-rw-r--  1 root root  10420 103 03:04 00-RELEASENOTES
-rw-rw-r--  1 root root     51 103 03:04 BUGS
-rw-rw-r--  1 root root   5023 103 03:04 CODE_OF_CONDUCT.md
-rw-rw-r--  1 root root   7178 103 03:04 CONTRIBUTING.md
drwxrwxr-x  8 root root    133 103 03:04 deps
-rw-rw-r--  1 root root     11 103 03:04 INSTALL
-rw-rw-r--  1 root root  37493 103 03:04 LICENSE.txt
-rw-rw-r--  1 root root    151 103 03:04 Makefile
-rw-rw-r--  1 root root   6888 103 03:04 MANIFESTO
-rw-rw-r--  1 root root  23845 103 03:04 README.md
-rw-rw-r--  1 root root 108981 103 03:04 redis.conf
-rw-rw-r--  1 root root   1805 103 03:04 REDISCONTRIBUTIONS.txt
-rwxrwxr-x  1 root root    279 103 03:04 runtest
-rwxrwxr-x  1 root root    283 103 03:04 runtest-cluster
-rwxrwxr-x  1 root root   1804 103 03:04 runtest-moduleapi
-rwxrwxr-x  1 root root    285 103 03:04 runtest-sentinel
-rw-rw-r--  1 root root   1480 103 03:04 SECURITY.md
-rw-rw-r--  1 root root  14700 103 03:04 sentinel.conf
drwxrwxr-x  4 root root   8192 103 03:04 src
drwxrwxr-x 11 root root    199 103 03:04 tests
-rw-rw-r--  1 root root   3628 103 03:04 TLS.md
drwxrwxr-x  9 root root   4096 103 03:04 utils
## 2. 执行 make 命令进行编译
[root@localhost redis-7.4.1]# make
cd src && make all
make[1]: 进入目录“/opt/mysoftware/redis-7.4.1/src”CC Makefile.dep
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info ...
(cd ../deps && make distclean)
make[2]: 进入目录“/opt/mysoftware/redis-7.4.1/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
(cd hdr_histogram && make clean) > /dev/null || true
(cd fpconv && make clean) > /dev/null || true
(rm -f .make-*)
make[2]: 离开目录“/opt/mysoftware/redis-7.4.1/deps”
(cd modules && make clean)
make[2]: 进入目录“/opt/mysoftware/redis-7.4.1/src/modules”
rm -rf *.xo *.so
make[2]: 离开目录“/opt/mysoftware/redis-7.4.1/src/modules”
(cd ../tests/modules && make clean)
make[2]: 进入目录“/opt/mysoftware/redis-7.4.1/tests/modules”
.....
.....
===============================================================================
jemalloc version   : 5.3.0-0-g0
library revision   : 2CONFIG             : --disable-cxx --with-version=5.3.0-0-g0 --with-lg-quantum=3 --disable-cache-oblivious --with-jemalloc-prefix=je_ CFLAGS= LDFLAGS=
CC                 : gcc
CONFIGURE_CFLAGS   : -std=gnu11 -Wall -Wextra -Wsign-compare -Wundef -Wno-format-zero-length -Wpointer-arith -Wno-missing-braces -Wno-missing-field-initializers -Wno-missing-attributes -pipe -g3 -fvisibility=hidden -Wimplicit-fallthrough -O3 -funroll-loops
SPECIFIED_CFLAGS   : 
EXTRA_CFLAGS       : 
CPPFLAGS           : -D_GNU_SOURCE -D_REENTRANT
CXX                : 
CONFIGURE_CXXFLAGS : 
SPECIFIED_CXXFLAGS : 
EXTRA_CXXFLAGS     : 
LDFLAGS            : 
EXTRA_LDFLAGS      : 
DSO_LDFLAGS        : -shared -Wl,-soname,$(@F)
LIBS               : -lm  -pthread -ldl
RPATH_EXTRA        : XSLTPROC           : /usr/bin/xsltproc
XSLROOT            : /usr/share/sgml/docbook/xsl-stylesheetsPREFIX             : /usr/local
BINDIR             : /usr/local/bin
DATADIR            : /usr/local/share
INCLUDEDIR         : /usr/local/include
LIBDIR             : /usr/local/lib
MANDIR             : /usr/local/share/mansrcroot            : 
abs_srcroot        : /opt/mysoftware/redis-7.4.1/deps/jemalloc/
objroot            : 
abs_objroot        : /opt/mysoftware/redis-7.4.1/deps/jemalloc/JEMALLOC_PREFIX    : je_
JEMALLOC_PRIVATE_NAMESPACE: je_
install_suffix     : 
malloc_conf        : 
documentation      : 1
shared libs        : 1
static libs        : 1
autogen            : 0
debug              : 0
stats              : 1
experimental_smallocx : 0
prof               : 0
prof-libunwind     : 0
prof-libgcc        : 0
prof-gcc           : 0
fill               : 1
utrace             : 0
xmalloc            : 0
log                : 0
lazy_lock          : 0
cache-oblivious    : 0
cxx                : 0
===============================================================================
cd jemalloc && make lib/libjemalloc.a
make[3]: 进入目录“/opt/mysoftware/redis-7.4.1/deps/jemalloc”
gcc -std=gnu11 -Wall -Wextra -Wsign-compare -Wundef -Wno-format-zero-length -Wpointer-arith -Wno-missing-braces -Wno-missing-
.....
....
make[3]: 离开目录“/opt/mysoftware/redis-7.4.1/deps/jemalloc”
make[2]: 离开目录“/opt/mysoftware/redis-7.4.1/deps”CC threads_mngr.oCC adlist.oCC quicklist.oCC ae.oCC anet.oCC dict.oCC ebuckets.oCC mstr.oCC kvstore.oCC server.oCC sds.oCC zmalloc.oCC lzf_c.oCC lzf_d.oCC pqsort.oCC zipmap.oCC sha1.oCC ziplist.oCC release.oCC networking.oCC util.oCC object.oCC db.oCC replication.oCC rdb.oCC t_string.oCC t_list.oCC t_set.oCC t_zset.oCC t_hash.oCC config.oCC aof.oCC pubsub.oCC multi.oCC debug.oCC sort.oCC intset.oCC syncio.oCC cluster.oCC cluster_legacy.oCC crc16.oCC endianconv.oCC slowlog.oCC eval.oCC bio.oCC rio.oCC rand.oCC memtest.oCC syscheck.oCC crcspeed.oCC crc64.oCC bitops.oCC sentinel.oCC notify.oCC setproctitle.oCC blocked.oCC hyperloglog.oCC latency.oCC sparkline.oCC redis-check-rdb.oCC redis-check-aof.oCC geo.oCC lazyfree.oCC module.oCC evict.oCC expire.oCC geohash.oCC geohash_helper.oCC childinfo.oCC defrag.oCC siphash.oCC rax.oCC t_stream.oCC listpack.oCC localtime.oCC lolwut.oCC lolwut5.oCC lolwut6.oCC acl.oCC tracking.oCC socket.oCC tls.oCC sha256.oCC timeout.oCC setcpuaffinity.oCC monotonic.oCC mt19937-64.oCC resp_parser.oCC call_reply.oCC script_lua.oCC script.oCC functions.oCC function_lua.oCC commands.oCC strl.oCC connection.oCC unix.oCC logreqres.oLINK redis-serverINSTALL redis-sentinelCC redis-cli.oCC redisassert.oCC cli_common.oCC cli_commands.oLINK redis-cliCC redis-benchmark.oLINK redis-benchmarkINSTALL redis-check-rdbINSTALL redis-check-aofHint: It's a good idea to run 'make test' ;)make[1]: 离开目录“/opt/mysoftware/redis-7.4.1/src”
[root@localhost redis-7.4.1]# 

3. 测试编译结果(可选)

如果你想在安装前测试编译好的Redis是否正常工作,可以运行测试套件。

Last login: Thu Dec  5 01:53:01 2024 from 192.168.31.12
[root@localhost ~]# cd /opt/mysoftware/redis-7.4.1/
[root@localhost redis-7.4.1]# pwd
/opt/mysoftware/redis-7.4.1
[root@localhost redis-7.4.1]# make test
cd src && make test
make[1]: 进入目录“/opt/mysoftware/redis-7.4.1/src”CC Makefile.depCC release.oLINK redis-serverINSTALL redis-check-aofLINK redis-cliLINK redis-benchmark
Cleanup: may take some time... OK
Starting test server at port 21079
....
....
!!! WARNING The following tests failed:*** [err]: Active defrag - AOF loading in tests/unit/memefficiency.tcl
Expected 59 <= 40 (context: type eval line 37 cmd {assert {$max_latency <= 40}} proc ::test)
Cleanup: may take some time... OK
make[1]: *** [Makefile:476:test] 错误 1
make[1]: 离开目录“/opt/mysoftware/redis-7.4.1/src”
make: *** [Makefile:6:test] 错误 2
[root@localhost redis-7.4.1]# # 上面错误就是鄙视你的配置太低了,因为在虚拟机中测试的,不影响

4. 安装Redis

编译完成后,使用make install命令安装Redis。这将会把Redis二进制文件安装到系统的默认路径下

[root@localhost ~]# cd /opt/mysoftware/redis-7.4.1/
[root@localhost redis-7.4.1]# pwd
/opt/mysoftware/redis-7.4.1
[root@localhost redis-7.4.1]# make install
cd src && make install
make[1]: 进入目录“/opt/mysoftware/redis-7.4.1/src”INSTALL redis-sentinelINSTALL redis-check-rdbHint: It's a good idea to run 'make test' ;)INSTALL redis-serverINSTALL redis-benchmarkINSTALL redis-cli
make[1]: 离开目录“/opt/mysoftware/redis-7.4.1/src”
[root@localhost redis-7.4

5. 安装位置

Redis安装完成后在 /usr/local/bin/目录下可查看

[root@localhost redis-7.4.1]# whereis redis
redis:
[root@localhost redis-7.4.1]# cd /usr/local/bin/
[root@localhost bin]# ll
总用量 30296
-rwxr-xr-x 1 root root  7003992 125 16:28 redis-benchmark
lrwxrwxrwx 1 root root       12 125 16:28 redis-check-aof -> redis-server
lrwxrwxrwx 1 root root       12 125 16:28 redis-check-rdb -> redis-server
-rwxr-xr-x 1 root root  7864432 125 16:28 redis-cli
lrwxrwxrwx 1 root root       12 125 16:28 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 16148928 125 16:28 redis-server
[root@localhost bin]# 

6. 复制配置文件

Redis的配置文件在源码目录下可找到,如redis.confsentinel.conf

  1. 查看源码下的配置文件
[root@localhost ~]# cd /opt/mysoftware/redis-7.4.1/
[root@localhost redis-7.4.1]# ll
总用量 284
-rw-rw-r--  1 root root  10420 103 03:04 00-RELEASENOTES
-rw-rw-r--  1 root root     51 103 03:04 BUGS
-rw-rw-r--  1 root root   5023 103 03:04 CODE_OF_CONDUCT.md
-rw-rw-r--  1 root root   7178 103 03:04 CONTRIBUTING.md
drwxrwxr-x  8 root root    201 125 01:53 deps
-rw-rw-r--  1 root root     11 103 03:04 INSTALL
-rw-rw-r--  1 root root  37493 103 03:04 LICENSE.txt
-rw-rw-r--  1 root root    151 103 03:04 Makefile
-rw-rw-r--  1 root root   6888 103 03:04 MANIFESTO
-rw-rw-r--  1 root root  23845 103 03:04 README.md
-rw-rw-r--  1 root root 108981 103 03:04 redis.conf
-rw-rw-r--  1 root root   1805 103 03:04 REDISCONTRIBUTIONS.txt
-rwxrwxr-x  1 root root    279 103 03:04 runtest
-rwxrwxr-x  1 root root    283 103 03:04 runtest-cluster
-rwxrwxr-x  1 root root   1804 103 03:04 runtest-moduleapi
-rwxrwxr-x  1 root root    285 103 03:04 runtest-sentinel
-rw-rw-r--  1 root root   1480 103 03:04 SECURITY.md
-rw-rw-r--  1 root root  14700 103 03:04 sentinel.conf
drwxrwxr-x  4 root root  12288 125 16:28 src
drwxrwxr-x 11 root root    199 103 03:04 tests
-rw-rw-r--  1 root root   3628 103 03:04 TLS.md
drwxrwxr-x  9 root root   4096 103 03:04 utils
[root@localhost redis-7.4.1]# 
  1. 将配置文件复制到合适位置
# 1.在/opt目录下新建redis目录
[root@localhost opt]# mkdir redis
# 2. 拷贝redis配置
[root@localhost redis-7.4.1]# cp *.conf /opt/redis/
[root@localhost redis-7.4.1]
# 3. 查看配置文件
[root@localhost opt]# cd redis/
[root@localhost redis]# ll
总用量 124
-rw-r--r-- 1 root root 108981 125 16:39 redis.conf
-rw-r--r-- 1 root root  14700 125 16:39 sentinel.conf
[root@localhost redis]# 

7. 修改redis.conf文件

根据你的需求编辑/opt/redis/redis.conf文件。例如,设置绑定的IP地址、端口号、是否作为守护进程运行等。

Redis 4.0 及以上版本默认启用了保护模式(protected-mode)。如果客户端尝试连接但没有提供密码,并且服务器正在监听非本地地址,则会拒绝连接。如果你确实需要远程访问,你应该禁用保护模式或者设置密码。要禁用保护模式,将 protected-mode 设置为 no

# redis.conf默认
bind 127.0.0.1 -::1
protected-mode yes# 修改后
# bind 127.0.0.1 -::1 # 注释这一行
protected-mode no # 这里将默认的yes改为no

8. 启动Redis服务

启动命令redis-server /opt/redis/redis.conf

[root@localhost ~]# redis-server /opt/redis/redis.conf 
54696:C 05 Dec 2024 16:48:04.988 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. 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.
54696:C 05 Dec 2024 16:48:04.988 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
54696:C 05 Dec 2024 16:48:04.988 * Redis version=7.4.1, bits=64, commit=00000000, modified=1, pid=54696, just started
54696:C 05 Dec 2024 16:48:04.988 * Configuration loaded
54696:M 05 Dec 2024 16:48:04.988 * monotonic clock: POSIX clock_gettime_._                                                  _.-``__ ''-._                                             _.-``    `.  `_.  ''-._           Redis Community Edition      .-`` .-```.  ```\/    _.,_ ''-._     7.4.1 (00000000/1) 64 bit(    '      ,       .-`  | `,    )     Running in standalone mode|`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379|    `-._   `._    /     _.-'    |     PID: 54696`-._    `-._  `-./  _.-'    _.-'                                   |`-._`-._    `-.__.-'    _.-'_.-'|                                  |    `-._`-._        _.-'_.-'    |           https://redis.io       `-._    `-._`-.__.-'_.-'    _.-'                                   |`-._`-._    `-.__.-'    _.-'_.-'|                                  |    `-._`-._        _.-'_.-'    |                                  `-._    `-._`-.__.-'_.-'    _.-'                                   `-._    `-.__.-'    _.-'                                       `-._        _.-'                                           `-.__.-'                                               54696:M 05 Dec 2024 16:48:04.990 * Server initialized
54696:M 05 Dec 2024 16:48:04.990 * Ready to accept connections tcp

9. 客户端测试

[root@localhost ~]# redis-cli
127.0.0.1:6379> keys *
(empty array)
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> get k1
"v1"
127.0.0.1:6379>

10. 设置开机自启动

如果你希望Redis在系统启动时自动运行,可以创建一个systemd服务文件或使用其他初始化系统的方法。例如,创建一个名为redis.service的systemd服务文件并放置在/etc/systemd/system/目录下,

  1. 查看/etc/systemd/system下的问题就
[root@localhost systemd]# cd /etc/systemd/system/
[root@localhost system]# ll
总用量 4
drwxr-xr-x 2 root root   31 123 20:29 bluetooth.target.wants
lrwxrwxrwx 1 root root   37 123 20:27 cron.service -> /usr/lib/systemd/system/crond.service
lrwxrwxrwx 1 root root   37 123 20:27 ctrl-alt-del.target -> /usr/lib/systemd/system/reboot.target
lrwxrwxrwx 1 root root   41 123 20:29 dbus-org.bluez.service -> /usr/lib/systemd/system/bluetooth.service
lrwxrwxrwx 1 root root   41 123 20:29 dbus-org.fedoraproject.FirewallD1.service -> /usr/lib/systemd/system/firewalld.service
lrwxrwxrwx 1 root root   44 123 20:28 dbus-org.freedesktop.ModemManager1.service -> /usr/lib/systemd/system/ModemManager.service
lrwxrwxrwx 1 root root   57 123 20:29 dbus-org.freedesktop.nm-dispatcher.service -> /usr/lib/systemd/system/NetworkManager-dispatcher.service
lrwxrwxrwx 1 root root   40 123 20:31 default.target -> /usr/lib/systemd/system/graphical.target
lrwxrwxrwx 1 root root   39 123 20:28 display-manager.service -> /usr/lib/systemd/system/lightdm.service
drwxr-xr-x 2 root root   32 123 20:27 getty.target.wants
drwxr-xr-x 2 root root   88 123 20:35 graphical.target.wants
drwxr-xr-x 2 root root 4096 124 18:12 multi-user.target.wants
drwxr-xr-x 2 root root   48 123 20:29 network-online.target.wants
drwxr-xr-x 2 root root   26 123 20:29 printer.target.wants
drwxr-xr-x 2 root root   31 123 20:29 remote-fs.target.wants
drwxr-xr-x 2 root root   48 123 20:29 sockets.target.wants
drwxr-xr-x 2 root root   62 123 20:29 sysinit.target.wants
drwxr-xr-x 2 root root   64 123 20:29 sysstat.service.wants
lrwxrwxrwx 1 root root    9  322  2022 timedatex.service -> /dev/null
drwxr-xr-x 2 root root   33 123 20:29 timers.target.wants
[root@localhost system]# 
  1. 注册Redis开机自启动服务

新建vim /etc/systemd/system/redis.service,内容如下

[Unit]
Description=Redis In-Memory Data Store
After=network.target[Service]
User=root
Group=root
ExecStart=/usr/local/bin/redis-server /opt/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always[Install]
WantedBy=multi-user.target
  1. 启用服务
 systemctl enable redis.servicesystemctl start redis.service[root@localhost system]# systemctl enable redis.service
Created symlink /etc/systemd/system/multi-user.target.wants/redis.service → /etc/systemd/system/redis.service.
[root@localhost system]# systemctl start redis.service
[root@localhost system]# 

3. 开启远程访问

  1. 编辑/opt/redis/redis.conf文件
  2. 修改绑定IP地址
  3. 关闭保护模式
  4. 设置密码(推荐)
  5. 编辑完redis.conf文件后重启服务
  6. 开放端口

1. 编辑redis.conf

  1. redis7.4.1安装后,默认的配置如下
# redis.conf默认
bind 127.0.0.1 -::1
protected-mode yes
# requirepass foobared
  1. 配置可远程访问
# 注释此行,或改成 bind 0.0.0.0
# bind 127.0.0.1 -::1
# 将 protected-mode yes 改为如下
protected-mode no
# 打开 requirepass foobared 注释,并设置密码为 myRedisDb123
requirepass myRedisDb123

2. 开启防火墙

# 开放6379端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
# 重新加载防火墙
firewall-cmd --reload

3.测试远程连接

从另一台机器上,使用 redis-cli 或其他Redis客户端工具测试连接。请记得替换 和 your_strong_password 为你自己的服务器IP和设置的密码。

redis-cli连接命令redis-cli -h <host> -p 6379 -a your_password

# 如
redis-cli -h 192.168.31.100 -p 6379 -a myRedisDb123

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词