翼度科技»论坛 云主机 LINUX 查看内容

【Redis】Redis 编译安装配置优化,多实例配置

4

主题

4

帖子

12

积分

新手上路

Rank: 1

积分
12
1、下载redis源码包,并进行解压缩操作
https://download.redis.io/releases/
  1. [root@Redis-Ubuntu-1804-p21:~]# wget https://download.redis.io/releases/redis-5.0.14.tar.gz
  2. --2023-04-13 21:21:40--  https://download.redis.io/releases/redis-5.0.14.tar.gz
  3. Resolving download.redis.io (download.redis.io)... 45.60.125.1
  4. Connecting to download.redis.io (download.redis.io)|45.60.125.1|:443... connected.
  5. HTTP request sent, awaiting response... 200 OK
  6. Length: 2000179 (1.9M) [application/octet-stream]
  7. Saving to: ‘redis-5.0.14.tar.gz’
  8. redis-5.0.14.tar.gz                 100%[=================================================================>]   1.91M  3.35MB/s    in 0.6s   
  9. 2023-04-13 21:21:43 (3.35 MB/s) - ‘redis-5.0.14.tar.gz’ saved [2000179/2000179]
  10. [root@Redis-Ubuntu-1804-p21:~]# tar xf redis-5.0.14.tar.gz
  11. [root@Redis-Ubuntu-1804-p21:~]# ls
  12. disk.sh  issue  os.version  redis-5.0.14  redis-5.0.14.tar.gz  system_info.sh
复制代码
 
 
 
 2、创建redis用户,创建redis目录结构并授权
  1. [root@Redis-Ubuntu-1804-p21:~]# useradd redis -s /sbin/nologin
  2. [root@Redis-Ubuntu-1804-p21:~]# mkdir /app/redis/{etc,log,data,run} -p
  3. [root@Redis-Ubuntu-1804-p21:~]# chown redis.redis /app/redis/ -R
  4. [root@Redis-Ubuntu-1804-p21:~]# id redis
  5. uid=2006(redis) gid=2006(redis) groups=2006(redis)
  6. [root@Redis-Ubuntu-1804-p21:~]# ll /app/redis/
  7. total 24
  8. drwxr-xr-x 6 redis redis 4096 Apr 13 21:36 ./
  9. drwxr-xr-x 3 root  root  4096 Apr 13 21:36 ../
  10. drwxr-xr-x 2 redis redis 4096 Apr 13 21:36 data/
  11. drwxr-xr-x 2 redis redis 4096 Apr 13 21:36 etc/
  12. drwxr-xr-x 2 redis redis 4096 Apr 13 21:36 log/
  13. drwxr-xr-x 2 redis redis 4096 Apr 13 21:36 run/
复制代码
3、准备编译环境,安装 build-essential (如已具备可忽略)
  1. [root@Redis-Ubuntu-1804-p21:~]# apt-get install build-essential -y
  2. Reading package lists... Done
  3. Building dependency tree      
  4. Reading state information... Done
  5. The following additional packages will be installed:
  6.   binutils binutils-common binutils-x86-64-linux-gnu cpp cpp-7 dpkg-dev fakeroot g++ g++-7 gcc gcc-7 gcc-7-base libalgorithm-diff-perl
  7.   libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan4 libatomic1 libbinutils libc-dev-bin libc6 libc6-dev libcc1-0 libcilkrts5
  8.   libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-7-dev libgomp1 libisl19 libitm1 liblsan0 libmpc3 libmpx2 libquadmath0
  9.   libstdc++-7-dev libtsan0 libubsan0 linux-libc-dev manpages-dev
  10. Suggested packages:
  11.   binutils-doc cpp-doc gcc-7-locales debian-keyring g++-multilib g++-7-multilib gcc-7-doc libstdc++6-7-dbg gcc-multilib autoconf automake
  12.   libtool flex bison gdb gcc-doc gcc-7-multilib libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg libasan4-dbg liblsan0-dbg libtsan0-dbg
  13.   libubsan0-dbg libcilkrts5-dbg libmpx2-dbg libquadmath0-dbg glibc-doc bzr libstdc++-7-doc
  14. The following NEW packages will be installed:
  15.   binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-7 dpkg-dev fakeroot g++ g++-7 gcc gcc-7 gcc-7-base
  16.   libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan4 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0
  17.   libcilkrts5 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-7-dev libgomp1 libisl19 libitm1 liblsan0 libmpc3 libmpx2 libquadmath0
  18.   libstdc++-7-dev libtsan0 libubsan0 linux-libc-dev manpages-dev
  19. The following packages will be upgraded:
  20.   libc6
  21. 1 upgraded, 39 newly installed, 0 to remove and 114 not upgraded.
  22. Need to get 45.7 MB of archives.
  23. After this operation, 165 MB of additional disk space will be used.
  24. Get:1 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libc6 amd64 2.27-3ubuntu1.6 [2831 kB]
  25. Get:2 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 binutils-common amd64 2.30-21ubuntu1~18.04.8 [197 kB]                    
  26. Get:3 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libbinutils amd64 2.30-21ubuntu1~18.04.8 [488 kB]                        
  27. Get:4 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 binutils-x86-64-linux-gnu amd64 2.30-21ubuntu1~18.04.8 [1839 kB]         
  28. Get:5 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 binutils amd64 2.30-21ubuntu1~18.04.8 [3388 B]                           
  29. Get:6 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libc-dev-bin amd64 2.27-3ubuntu1.6 [71.9 kB]                             
  30. Get:7 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 linux-libc-dev amd64 4.15.0-208.220 [997 kB]                             
  31. Get:8 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libc6-dev amd64 2.27-3ubuntu1.6 [2587 kB]                                
  32. Get:9 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 gcc-7-base amd64 7.5.0-3ubuntu1~18.04 [18.3 kB]                          
  33. Get:10 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libisl19 amd64 0.19-1 [551 kB]                                                  
  34. Get:11 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libmpc3 amd64 1.1.0-1 [40.8 kB]                                                
  35. Get:12 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 cpp-7 amd64 7.5.0-3ubuntu1~18.04 [8591 kB]                              
  36. Get:13 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 cpp amd64 4:7.4.0-1ubuntu2.3 [27.7 kB]                                 
  37. Get:14 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libcc1-0 amd64 8.4.0-1ubuntu1~18.04 [39.4 kB]                           
  38. Get:15 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libgomp1 amd64 8.4.0-1ubuntu1~18.04 [76.5 kB]                           
  39. Get:16 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libitm1 amd64 8.4.0-1ubuntu1~18.04 [27.9 kB]                           
  40. Get:17 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libatomic1 amd64 8.4.0-1ubuntu1~18.04 [9192 B]                          
  41. Get:18 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libasan4 amd64 7.5.0-3ubuntu1~18.04 [358 kB]                           
  42. Get:19 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 liblsan0 amd64 8.4.0-1ubuntu1~18.04 [133 kB]                           
  43. Get:20 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libtsan0 amd64 8.4.0-1ubuntu1~18.04 [288 kB]                           
  44. Get:21 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libubsan0 amd64 7.5.0-3ubuntu1~18.04 [126 kB]                           
  45. Get:22 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libcilkrts5 amd64 7.5.0-3ubuntu1~18.04 [42.5 kB]                        
  46. Get:23 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libmpx2 amd64 8.4.0-1ubuntu1~18.04 [11.6 kB]                           
  47. Get:24 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libquadmath0 amd64 8.4.0-1ubuntu1~18.04 [134 kB]                        
  48. Get:25 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libgcc-7-dev amd64 7.5.0-3ubuntu1~18.04 [2378 kB]                       
  49. Get:26 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 gcc-7 amd64 7.5.0-3ubuntu1~18.04 [9381 kB]                              
  50. Get:27 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 gcc amd64 4:7.4.0-1ubuntu2.3 [5184 B]                                   
  51. Get:28 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libstdc++-7-dev amd64 7.5.0-3ubuntu1~18.04 [1471 kB]                    
  52. Get:29 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 g++-7 amd64 7.5.0-3ubuntu1~18.04 [9697 kB]                              
  53. Get:30 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 g++ amd64 4:7.4.0-1ubuntu2.3 [1568 B]                                   
  54. Get:31 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 libdpkg-perl all 1.19.0.5ubuntu2.4 [212 kB]                             
  55. Get:32 http://cn.archive.ubuntu.com/ubuntu bionic-updates/main amd64 dpkg-dev all 1.19.0.5ubuntu2.4 [607 kB]                                 
  56. Get:33 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 build-essential amd64 12.4ubuntu1 [4758 B]                                      
  57. Get:34 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libfakeroot amd64 1.22-2ubuntu1 [25.9 kB]                                       
  58. Get:35 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 fakeroot amd64 1.22-2ubuntu1 [62.3 kB]                                          
  59. Get:36 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libalgorithm-diff-perl all 1.19.03-1 [47.6 kB]                                 
  60. Get:37 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libalgorithm-diff-xs-perl amd64 0.04-5 [11.1 kB]                                
  61. Get:38 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libalgorithm-merge-perl all 0.08-3 [12.0 kB]                                    
  62. Get:39 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 libfile-fcntllock-perl amd64 0.22-3build2 [33.2 kB]                             
  63. Get:40 http://cn.archive.ubuntu.com/ubuntu bionic/main amd64 manpages-dev all 4.15-1 [2217 kB]                                               
  64. Fetched 45.7 MB in 35s (1308 kB/s)                                                                                                           
  65. Extracting templates from packages: 100%
  66. Preconfiguring packages ...
  67. (Reading database ... 103420 files and directories currently installed.)
  68. Preparing to unpack .../libc6_2.27-3ubuntu1.6_amd64.deb ...
  69. Unpacking libc6:amd64 (2.27-3ubuntu1.6) over (2.27-3ubuntu1.5) ...
  70. Setting up libc6:amd64 (2.27-3ubuntu1.6) ...
  71. Selecting previously unselected package binutils-common:amd64.
  72. (Reading database ... 103420 files and directories currently installed.)
  73. Preparing to unpack .../00-binutils-common_2.30-21ubuntu1~18.04.8_amd64.deb ...
  74. Unpacking binutils-common:amd64 (2.30-21ubuntu1~18.04.8) ...
  75. Selecting previously unselected package libbinutils:amd64.
  76. Preparing to unpack .../01-libbinutils_2.30-21ubuntu1~18.04.8_amd64.deb ...
  77. Unpacking libbinutils:amd64 (2.30-21ubuntu1~18.04.8) ...
  78. Selecting previously unselected package binutils-x86-64-linux-gnu.
  79. Preparing to unpack .../02-binutils-x86-64-linux-gnu_2.30-21ubuntu1~18.04.8_amd64.deb ...
  80. Unpacking binutils-x86-64-linux-gnu (2.30-21ubuntu1~18.04.8) ...
  81. Selecting previously unselected package binutils.
  82. Preparing to unpack .../03-binutils_2.30-21ubuntu1~18.04.8_amd64.deb ...
  83. Unpacking binutils (2.30-21ubuntu1~18.04.8) ...
  84. Selecting previously unselected package libc-dev-bin.
  85. Preparing to unpack .../04-libc-dev-bin_2.27-3ubuntu1.6_amd64.deb ...
  86. Unpacking libc-dev-bin (2.27-3ubuntu1.6) ...
  87. Selecting previously unselected package linux-libc-dev:amd64.
  88. Preparing to unpack .../05-linux-libc-dev_4.15.0-208.220_amd64.deb ...
  89. Unpacking linux-libc-dev:amd64 (4.15.0-208.220) ...
  90. Selecting previously unselected package libc6-dev:amd64.
  91. Preparing to unpack .../06-libc6-dev_2.27-3ubuntu1.6_amd64.deb ...
  92. Unpacking libc6-dev:amd64 (2.27-3ubuntu1.6) ...
  93. Selecting previously unselected package gcc-7-base:amd64.
  94. Preparing to unpack .../07-gcc-7-base_7.5.0-3ubuntu1~18.04_amd64.deb ...
  95. Unpacking gcc-7-base:amd64 (7.5.0-3ubuntu1~18.04) ...
  96. Selecting previously unselected package libisl19:amd64.
  97. Preparing to unpack .../08-libisl19_0.19-1_amd64.deb ...
  98. Unpacking libisl19:amd64 (0.19-1) ...
  99. Selecting previously unselected package libmpc3:amd64.
  100. Preparing to unpack .../09-libmpc3_1.1.0-1_amd64.deb ...
  101. Unpacking libmpc3:amd64 (1.1.0-1) ...
  102. Selecting previously unselected package cpp-7.
  103. Preparing to unpack .../10-cpp-7_7.5.0-3ubuntu1~18.04_amd64.deb ...
  104. Unpacking cpp-7 (7.5.0-3ubuntu1~18.04) ...
  105. Selecting previously unselected package cpp.
  106. Preparing to unpack .../11-cpp_4%3a7.4.0-1ubuntu2.3_amd64.deb ...
  107. Unpacking cpp (4:7.4.0-1ubuntu2.3) ...
  108. Selecting previously unselected package libcc1-0:amd64.
  109. Preparing to unpack .../12-libcc1-0_8.4.0-1ubuntu1~18.04_amd64.deb ...
  110. Unpacking libcc1-0:amd64 (8.4.0-1ubuntu1~18.04) ...
  111. Selecting previously unselected package libgomp1:amd64.
  112. Preparing to unpack .../13-libgomp1_8.4.0-1ubuntu1~18.04_amd64.deb ...
  113. Unpacking libgomp1:amd64 (8.4.0-1ubuntu1~18.04) ...
  114. Selecting previously unselected package libitm1:amd64.
  115. Preparing to unpack .../14-libitm1_8.4.0-1ubuntu1~18.04_amd64.deb ...
  116. Unpacking libitm1:amd64 (8.4.0-1ubuntu1~18.04) ...
  117. Selecting previously unselected package libatomic1:amd64.
  118. Preparing to unpack .../15-libatomic1_8.4.0-1ubuntu1~18.04_amd64.deb ...
  119. Unpacking libatomic1:amd64 (8.4.0-1ubuntu1~18.04) ...
  120. Selecting previously unselected package libasan4:amd64.
  121. Preparing to unpack .../16-libasan4_7.5.0-3ubuntu1~18.04_amd64.deb ...
  122. Unpacking libasan4:amd64 (7.5.0-3ubuntu1~18.04) ...
  123. Selecting previously unselected package liblsan0:amd64.
  124. Preparing to unpack .../17-liblsan0_8.4.0-1ubuntu1~18.04_amd64.deb ...
  125. Unpacking liblsan0:amd64 (8.4.0-1ubuntu1~18.04) ...
  126. Selecting previously unselected package libtsan0:amd64.
  127. Preparing to unpack .../18-libtsan0_8.4.0-1ubuntu1~18.04_amd64.deb ...
  128. Unpacking libtsan0:amd64 (8.4.0-1ubuntu1~18.04) ...
  129. Selecting previously unselected package libubsan0:amd64.
  130. Preparing to unpack .../19-libubsan0_7.5.0-3ubuntu1~18.04_amd64.deb ...
  131. Unpacking libubsan0:amd64 (7.5.0-3ubuntu1~18.04) ...
  132. Selecting previously unselected package libcilkrts5:amd64.
  133. Preparing to unpack .../20-libcilkrts5_7.5.0-3ubuntu1~18.04_amd64.deb ...
  134. Unpacking libcilkrts5:amd64 (7.5.0-3ubuntu1~18.04) ...
  135. Selecting previously unselected package libmpx2:amd64.
  136. Preparing to unpack .../21-libmpx2_8.4.0-1ubuntu1~18.04_amd64.deb ...
  137. Unpacking libmpx2:amd64 (8.4.0-1ubuntu1~18.04) ...
  138. Selecting previously unselected package libquadmath0:amd64.
  139. Preparing to unpack .../22-libquadmath0_8.4.0-1ubuntu1~18.04_amd64.deb ...
  140. Unpacking libquadmath0:amd64 (8.4.0-1ubuntu1~18.04) ...
  141. Selecting previously unselected package libgcc-7-dev:amd64.
  142. Preparing to unpack .../23-libgcc-7-dev_7.5.0-3ubuntu1~18.04_amd64.deb ...
  143. Unpacking libgcc-7-dev:amd64 (7.5.0-3ubuntu1~18.04) ...
  144. Selecting previously unselected package gcc-7.
  145. Preparing to unpack .../24-gcc-7_7.5.0-3ubuntu1~18.04_amd64.deb ...
  146. Unpacking gcc-7 (7.5.0-3ubuntu1~18.04) ...
  147. Selecting previously unselected package gcc.
  148. Preparing to unpack .../25-gcc_4%3a7.4.0-1ubuntu2.3_amd64.deb ...
  149. Unpacking gcc (4:7.4.0-1ubuntu2.3) ...
  150. Selecting previously unselected package libstdc++-7-dev:amd64.
  151. Preparing to unpack .../26-libstdc++-7-dev_7.5.0-3ubuntu1~18.04_amd64.deb ...
  152. Unpacking libstdc++-7-dev:amd64 (7.5.0-3ubuntu1~18.04) ...
  153. Selecting previously unselected package g++-7.
  154. Preparing to unpack .../27-g++-7_7.5.0-3ubuntu1~18.04_amd64.deb ...
  155. Unpacking g++-7 (7.5.0-3ubuntu1~18.04) ...
  156. Selecting previously unselected package g++.
  157. Preparing to unpack .../28-g++_4%3a7.4.0-1ubuntu2.3_amd64.deb ...
  158. Unpacking g++ (4:7.4.0-1ubuntu2.3) ...
  159. Selecting previously unselected package libdpkg-perl.
  160. Preparing to unpack .../29-libdpkg-perl_1.19.0.5ubuntu2.4_all.deb ...
  161. Unpacking libdpkg-perl (1.19.0.5ubuntu2.4) ...
  162. Selecting previously unselected package dpkg-dev.
  163. Preparing to unpack .../30-dpkg-dev_1.19.0.5ubuntu2.4_all.deb ...
  164. Unpacking dpkg-dev (1.19.0.5ubuntu2.4) ...
  165. Selecting previously unselected package build-essential.
  166. Preparing to unpack .../31-build-essential_12.4ubuntu1_amd64.deb ...
  167. Unpacking build-essential (12.4ubuntu1) ...
  168. Selecting previously unselected package libfakeroot:amd64.
  169. Preparing to unpack .../32-libfakeroot_1.22-2ubuntu1_amd64.deb ...
  170. Unpacking libfakeroot:amd64 (1.22-2ubuntu1) ...
  171. Selecting previously unselected package fakeroot.
  172. Preparing to unpack .../33-fakeroot_1.22-2ubuntu1_amd64.deb ...
  173. Unpacking fakeroot (1.22-2ubuntu1) ...
  174. Selecting previously unselected package libalgorithm-diff-perl.
  175. Preparing to unpack .../34-libalgorithm-diff-perl_1.19.03-1_all.deb ...
  176. Unpacking libalgorithm-diff-perl (1.19.03-1) ...
  177. Selecting previously unselected package libalgorithm-diff-xs-perl.
  178. Preparing to unpack .../35-libalgorithm-diff-xs-perl_0.04-5_amd64.deb ...
  179. Unpacking libalgorithm-diff-xs-perl (0.04-5) ...
  180. Selecting previously unselected package libalgorithm-merge-perl.
  181. Preparing to unpack .../36-libalgorithm-merge-perl_0.08-3_all.deb ...
  182. Unpacking libalgorithm-merge-perl (0.08-3) ...
  183. Selecting previously unselected package libfile-fcntllock-perl.
  184. Preparing to unpack .../37-libfile-fcntllock-perl_0.22-3build2_amd64.deb ...
  185. Unpacking libfile-fcntllock-perl (0.22-3build2) ...
  186. Selecting previously unselected package manpages-dev.
  187. Preparing to unpack .../38-manpages-dev_4.15-1_all.deb ...
  188. Unpacking manpages-dev (4.15-1) ...
  189. Setting up libquadmath0:amd64 (8.4.0-1ubuntu1~18.04) ...
  190. Setting up libgomp1:amd64 (8.4.0-1ubuntu1~18.04) ...
  191. Setting up libatomic1:amd64 (8.4.0-1ubuntu1~18.04) ...
  192. Setting up libcc1-0:amd64 (8.4.0-1ubuntu1~18.04) ...
  193. Setting up libtsan0:amd64 (8.4.0-1ubuntu1~18.04) ...
  194. Setting up linux-libc-dev:amd64 (4.15.0-208.220) ...
  195. Setting up libdpkg-perl (1.19.0.5ubuntu2.4) ...
  196. Setting up liblsan0:amd64 (8.4.0-1ubuntu1~18.04) ...
  197. Setting up gcc-7-base:amd64 (7.5.0-3ubuntu1~18.04) ...
  198. Setting up binutils-common:amd64 (2.30-21ubuntu1~18.04.8) ...
  199. Setting up libfile-fcntllock-perl (0.22-3build2) ...
  200. Setting up libmpx2:amd64 (8.4.0-1ubuntu1~18.04) ...
  201. Setting up libfakeroot:amd64 (1.22-2ubuntu1) ...
  202. Setting up libalgorithm-diff-perl (1.19.03-1) ...
  203. Setting up libmpc3:amd64 (1.1.0-1) ...
  204. Setting up libc-dev-bin (2.27-3ubuntu1.6) ...
  205. Setting up manpages-dev (4.15-1) ...
  206. Setting up libc6-dev:amd64 (2.27-3ubuntu1.6) ...
  207. Setting up libitm1:amd64 (8.4.0-1ubuntu1~18.04) ...
  208. Setting up libisl19:amd64 (0.19-1) ...
  209. Setting up libasan4:amd64 (7.5.0-3ubuntu1~18.04) ...
  210. Setting up libbinutils:amd64 (2.30-21ubuntu1~18.04.8) ...
  211. Setting up libcilkrts5:amd64 (7.5.0-3ubuntu1~18.04) ...
  212. Setting up libubsan0:amd64 (7.5.0-3ubuntu1~18.04) ...
  213. Setting up fakeroot (1.22-2ubuntu1) ...
  214. update-alternatives: using /usr/bin/fakeroot-sysv to provide /usr/bin/fakeroot (fakeroot) in auto mode
  215. Setting up libgcc-7-dev:amd64 (7.5.0-3ubuntu1~18.04) ...
  216. Setting up cpp-7 (7.5.0-3ubuntu1~18.04) ...
  217. Setting up libstdc++-7-dev:amd64 (7.5.0-3ubuntu1~18.04) ...
  218. Setting up libalgorithm-merge-perl (0.08-3) ...
  219. Setting up libalgorithm-diff-xs-perl (0.04-5) ...
  220. Setting up binutils-x86-64-linux-gnu (2.30-21ubuntu1~18.04.8) ...
  221. Setting up cpp (4:7.4.0-1ubuntu2.3) ...
  222. Setting up binutils (2.30-21ubuntu1~18.04.8) ...
  223. Setting up gcc-7 (7.5.0-3ubuntu1~18.04) ...
  224. Setting up g++-7 (7.5.0-3ubuntu1~18.04) ...
  225. Setting up gcc (4:7.4.0-1ubuntu2.3) ...
  226. Setting up dpkg-dev (1.19.0.5ubuntu2.4) ...
  227. Setting up g++ (4:7.4.0-1ubuntu2.3) ...
  228. update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode
  229. Setting up build-essential (12.4ubuntu1) ...
  230. Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
  231. Processing triggers for libc-bin (2.27-3ubuntu1.5) ...
  232. [root@Redis-Ubuntu-1804-p21:~]#
复制代码
 
4、切换解压的到redis目录下,进行编译安装到目录 /app/redis
  1. [root@Redis-Ubuntu-1804-p21:~]# cd redis-5.0.14/
  2. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]# make PREFIX=/app/redis/ install
  3. cd src && make install
  4. make[1]: Entering directory '/root/redis-5.0.14/src'
  5. 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
  6. (cd ../deps && make distclean)
  7. make[2]: Entering directory '/root/redis-5.0.14/deps'
  8. (cd hiredis && make clean) > /dev/null || true
  9. (cd linenoise && make clean) > /dev/null || true
  10. (cd lua && make clean) > /dev/null || true
  11. (cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
  12. (rm -f .make-*)
  13. make[2]: Leaving directory '/root/redis-5.0.14/deps'
  14. (rm -f .make-*)
  15. echo STD=-std=c99 -pedantic -DREDIS_STATIC= >> .make-settings
  16. echo WARN=-Wall -W -Wno-missing-field-initializers >> .make-settings
  17. echo OPT=-O2 >> .make-settings
  18. echo MALLOC=libc >> .make-settings
  19. echo CFLAGS= >> .make-settings
  20. echo LDFLAGS= >> .make-settings
  21. echo REDIS_CFLAGS= >> .make-settings
  22. echo REDIS_LDFLAGS= >> .make-settings
  23. echo PREV_FINAL_CFLAGS=-std=c99 -pedantic -DREDIS_STATIC= -Wall -W -Wno-missing-field-initializers -O2 -g -ggdb -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src >> .make-settings
  24. echo PREV_FINAL_LDFLAGS= -g -ggdb -rdynamic >> .make-settings
  25. (cd ../deps && make hiredis linenoise lua)
  26. make[2]: Entering directory '/root/redis-5.0.14/deps'
  27. (cd hiredis && make clean) > /dev/null || true
  28. (cd linenoise && make clean) > /dev/null || true
  29. (cd lua && make clean) > /dev/null || true
  30. (cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
  31. (rm -f .make-*)
  32. (echo "" > .make-cflags)
  33. (echo "" > .make-ldflags)
  34. MAKE hiredis
  35. cd hiredis && make static
  36. make[3]: Entering directory '/root/redis-5.0.14/deps/hiredis'
  37. cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb net.c
  38. cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb hiredis.c
  39. hiredis.c: In function ‘createArrayObject’:
  40. hiredis.c:142:44: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  41. if (SIZE_MAX / sizeof(redisReply*) < elements) return NULL; /* Don't overflow */
  42. ^
  43. cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb sds.c
  44. cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb async.c
  45. cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb read.c
  46. ar rcs libhiredis.a net.o hiredis.o sds.o async.o read.o
  47. make[3]: Leaving directory '/root/redis-5.0.14/deps/hiredis'
  48. MAKE linenoise
  49. cd linenoise && make
  50. make[3]: Entering directory '/root/redis-5.0.14/deps/linenoise'
  51. cc -Wall -Os -g -c linenoise.c
  52. make[3]: Leaving directory '/root/redis-5.0.14/deps/linenoise'
  53. MAKE lua
  54. cd lua/src && make all CFLAGS="-O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' " MYLDFLAGS="" AR="ar rcu"
  55. make[3]: Entering directory '/root/redis-5.0.14/deps/lua/src'
  56. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lapi.o lapi.c
  57. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lcode.o lcode.c
  58. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o ldebug.o ldebug.c
  59. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o ldo.o ldo.c
  60. ldo.c: In function ‘f_parser’:
  61. ldo.c:496:7: warning: unused variable ‘c’ [-Wunused-variable]
  62. int c = luaZ_lookahead(p->z);
  63. ^
  64. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o ldump.o ldump.c
  65. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lfunc.o lfunc.c
  66. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lgc.o lgc.c
  67. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o llex.o llex.c
  68. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lmem.o lmem.c
  69. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lobject.o lobject.c
  70. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lopcodes.o lopcodes.c
  71. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lparser.o lparser.c
  72. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lstate.o lstate.c
  73. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lstring.o lstring.c
  74. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o ltable.o ltable.c
  75. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o ltm.o ltm.c
  76. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lundump.o lundump.c
  77. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lvm.o lvm.c
  78. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lzio.o lzio.c
  79. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o strbuf.o strbuf.c
  80. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o fpconv.o fpconv.c
  81. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lauxlib.o lauxlib.c
  82. lauxlib.c: In function ‘luaL_loadfile’:
  83. lauxlib.c:577:4: warning: this ‘while’ clause does not guard... [-Wmisleading-indentation]
  84. while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
  85. ^~~~~
  86. lauxlib.c:578:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘while’
  87. lf.extraline = 0;
  88. ^~
  89. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lbaselib.o lbaselib.c
  90. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o ldblib.o ldblib.c
  91. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o liolib.o liolib.c
  92. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lmathlib.o lmathlib.c
  93. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o loslib.o loslib.c
  94. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o ltablib.o ltablib.c
  95. ltablib.c: In function ‘addfield’:
  96. ltablib.c:137:3: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
  97. if (!lua_isstring(L, -1))
  98. ^~
  99. ltablib.c:140:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
  100. luaL_addvalue(b);
  101. ^~~~~~~~~~~~~
  102. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lstrlib.o lstrlib.c
  103. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o loadlib.o loadlib.c
  104. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o linit.o linit.c
  105. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lua_cjson.o lua_cjson.c
  106. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lua_struct.o lua_struct.c
  107. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lua_cmsgpack.o lua_cmsgpack.c
  108. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lua_bit.o lua_bit.c
  109. ar rcu liblua.a lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o strbuf.o fpconv.o lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o lstrlib.o loadlib.o linit.o lua_cjson.o lua_struct.o lua_cmsgpack.o lua_bit.o # DLL needs all object files
  110. ar: `u' modifier ignored since `D' is the default (see `U')
  111. ranlib liblua.a
  112. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o lua.o lua.c
  113. cc -o lua lua.o liblua.a -lm
  114. liblua.a(loslib.o): In function `os_tmpname':
  115. loslib.c:(.text+0x290): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
  116. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o luac.o luac.c
  117. cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' -c -o print.o print.c
  118. cc -o luac luac.o print.o liblua.a -lm
  119. make[3]: Leaving directory '/root/redis-5.0.14/deps/lua/src'
  120. make[2]: Leaving directory '/root/redis-5.0.14/deps'
  121. CC adlist.o
  122. CC quicklist.o
  123. CC ae.o
  124. CC anet.o
  125. CC dict.o
  126. CC server.o
  127. CC sds.o
  128. CC zmalloc.o
  129. CC lzf_c.o
  130. CC lzf_d.o
  131. CC pqsort.o
  132. CC zipmap.o
  133. CC sha1.o
  134. CC ziplist.o
  135. CC release.o
  136. CC networking.o
  137. CC util.o
  138. CC object.o
  139. CC db.o
  140. CC replication.o
  141. CC rdb.o
  142. CC t_string.o
  143. CC t_list.o
  144. CC t_set.o
  145. CC t_zset.o
  146. CC t_hash.o
  147. CC config.o
  148. CC aof.o
  149. CC pubsub.o
  150. CC multi.o
  151. CC debug.o
  152. CC sort.o
  153. CC intset.o
  154. CC syncio.o
  155. CC cluster.o
  156. CC crc16.o
  157. CC endianconv.o
  158. CC slowlog.o
  159. CC scripting.o
  160. CC bio.o
  161. CC rio.o
  162. CC rand.o
  163. CC memtest.o
  164. CC crc64.o
  165. CC bitops.o
  166. CC sentinel.o
  167. CC notify.o
  168. CC setproctitle.o
  169. CC blocked.o
  170. CC hyperloglog.o
  171. CC latency.o
  172. CC sparkline.o
  173. CC redis-check-rdb.o
  174. CC redis-check-aof.o
  175. CC geo.o
  176. CC lazyfree.o
  177. CC module.o
  178. CC evict.o
  179. CC expire.o
  180. CC geohash.o
  181. CC geohash_helper.o
  182. CC childinfo.o
  183. CC defrag.o
  184. CC siphash.o
  185. CC rax.o
  186. CC t_stream.o
  187. CC listpack.o
  188. CC localtime.o
  189. CC lolwut.o
  190. CC lolwut5.o
  191. LINK redis-server
  192. INSTALL redis-sentinel
  193. CC redis-cli.o
  194. LINK redis-cli
  195. CC redis-benchmark.o
  196. LINK redis-benchmark
  197. INSTALL redis-check-rdb
  198. INSTALL redis-check-aof
  199. Hint: It's a good idea to run 'make test' ;)
  200. INSTALL install
  201. INSTALL install
  202. INSTALL install
  203. INSTALL install
  204. INSTALL install
  205. make[1]: Leaving directory '/root/redis-5.0.14/src'
  206. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]#
复制代码
  1. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]#
  2. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]# tree /app/redis
  3. /app/redis
  4. ├── bin
  5. │   ├── redis-benchmark
  6. │   ├── redis-check-aof
  7. │   ├── redis-check-rdb
  8. │   ├── redis-cli
  9. │   ├── redis-sentinel -> redis-server
  10. │   └── redis-server
  11. ├── data
  12. ├── etc
  13. ├── log
  14. └── run
复制代码
安装过程如出现下方报错提示,返回第3步重新安装编译环境,或安装 gcc
  1. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]# make PREFIX=/app/redis/ install
  2. cd src && make install
  3. make[1]: Entering directory '/root/redis-5.0.14/src'
  4.     CC Makefile.dep
  5. 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
  6. (cd ../deps && make distclean)
  7. make[2]: Entering directory '/root/redis-5.0.14/deps'
  8. (cd hiredis && make clean) > /dev/null || true
  9. (cd linenoise && make clean) > /dev/null || true
  10. (cd lua && make clean) > /dev/null || true
  11. (cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
  12. (rm -f .make-*)
  13. make[2]: Leaving directory '/root/redis-5.0.14/deps'
  14. (rm -f .make-*)
  15. echo STD=-std=c99 -pedantic -DREDIS_STATIC='' >> .make-settings
  16. echo WARN=-Wall -W -Wno-missing-field-initializers >> .make-settings
  17. echo OPT=-O2 >> .make-settings
  18. echo MALLOC=jemalloc >> .make-settings
  19. echo CFLAGS= >> .make-settings
  20. echo LDFLAGS= >> .make-settings
  21. echo REDIS_CFLAGS= >> .make-settings
  22. echo REDIS_LDFLAGS= >> .make-settings
  23. echo PREV_FINAL_CFLAGS=-std=c99 -pedantic -DREDIS_STATIC='' -Wall -W -Wno-missing-field-initializers -O2 -g -ggdb   -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -DUSE_JEMALLOC -I../deps/jemalloc/include >> .make-settings
  24. echo PREV_FINAL_LDFLAGS=  -g -ggdb -rdynamic >> .make-settings
  25. (cd ../deps && make hiredis linenoise lua jemalloc)
  26. make[2]: Entering directory '/root/redis-5.0.14/deps'
  27. (cd hiredis && make clean) > /dev/null || true
  28. (cd linenoise && make clean) > /dev/null || true
  29. (cd lua && make clean) > /dev/null || true
  30. (cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
  31. (rm -f .make-*)
  32. (echo "" > .make-cflags)
  33. (echo "" > .make-ldflags)
  34. MAKE hiredis
  35. cd hiredis && make static
  36. make[3]: Entering directory '/root/redis-5.0.14/deps/hiredis'
  37. gcc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  net.c
  38. make[3]: gcc: Command not found
  39. Makefile:156: recipe for target 'net.o' failed
  40. make[3]: *** [net.o] Error 127
  41. make[3]: Leaving directory '/root/redis-5.0.14/deps/hiredis'
  42. Makefile:45: recipe for target 'hiredis' failed
  43. make[2]: *** [hiredis] Error 2
  44. make[2]: Leaving directory '/root/redis-5.0.14/deps'
  45. Makefile:199: recipe for target 'persist-settings' failed
  46. make[1]: [persist-settings] Error 2 (ignored)
  47.     CC adlist.o
  48. /bin/sh: 1: cc: not found
  49. Makefile:257: recipe for target 'adlist.o' failed
  50. make[1]: *** [adlist.o] Error 127
  51. make[1]: Leaving directory '/root/redis-5.0.14/src'
  52. Makefile:9: recipe for target 'install' failed
  53. make: *** [install] Error 2
  54. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]#
复制代码
 
 
 
 重新编译安装出现 zmalloc.h:50:10: fatal error: jemalloc/jemalloc.h: No such file or directory 报错,执行 make MALLOC=libc PREFIX=/app/redis/ install
  1. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]# make PREFIX=/app/redis/ install
  2. cd src && make install
  3. make[1]: Entering directory '/root/redis-5.0.14/src'
  4.     CC adlist.o
  5. In file included from adlist.c:34:0:
  6. zmalloc.h:50:10: fatal error: jemalloc/jemalloc.h: No such file or directory
  7. #include <jemalloc/jemalloc.h>
  8.           ^~~~~~~~~~~~~~~~~~~~~
  9. compilation terminated.
  10. Makefile:257: recipe for target 'adlist.o' failed
  11. make[1]: *** [adlist.o] Error 1
  12. make[1]: Leaving directory '/root/redis-5.0.14/src'
  13. Makefile:9: recipe for target 'install' failed
  14. make: *** [install] Error 2
  15. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]# make MALLOC=libc PREFIX=/app/redis/ install
复制代码
 
 
 
 
5、创建命令软连接
  1. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]# tree /app/redis
  2. /app/redis
  3. ├── bin
  4. │   ├── redis-benchmark
  5. │   ├── redis-check-aof
  6. │   ├── redis-check-rdb
  7. │   ├── redis-cli
  8. │   ├── redis-sentinel -> redis-server
  9. │   └── redis-server
  10. ├── data
  11. ├── etc
  12. ├── log
  13. └── run
  14. 5 directories, 6 files
  15. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]# ln -s /app/redis/bin/* /usr/bin/
  16. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]# which red
  17. red              redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli        redis-sentinel   redis-server
复制代码
6、复制并准备Redis配置文件
  1. ##方法1:手动修改
  2. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]# cp redis.conf /app/redis/etc/redis_bak.conf
  3. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]# cd /app/redis/etc/
  4. [root@Redis-Ubuntu-1804-p21:etc]# ll
  5. total 72
  6. drwxr-xr-x 2 redis redis  4096 Apr 13 22:36 ./
  7. drwxr-xr-x 7 redis redis  4096 Apr 13 22:21 ../
  8. -rw-r--r-- 1 root  root  63088 Apr 13 22:36 redis_bak.conf
  9. [root@Redis-Ubuntu-1804-p21:etc]# vim redis_bak.conf
  10. bind 0.0.0.0
  11. port 6379
  12. pidfile /app/redis/run/redis_6379.pid
  13. logfile "redis_6379.log"
  14. always-show-logo no
  15. dbfilename dump_6379.rdb
  16. dir /app/redis/data
  17. appendfilename "appendonly_6379.aof"
  18. [root@Redis-Ubuntu-1804-p21:etc]# cat redis_bak.conf | grep ^[A-z] > redis_6379.confcat redis_bak.conf | grep ^[A-z] > redis_6379.conf
  19. [root@Redis-Ubuntu-1804-p21:etc]# sed 's/6379/6380/g' redis_6379.conf > redis_6380.conf
  20. [root@Redis-Ubuntu-1804-p21:etc]# sed 's/6379/6381/g' redis_6379.conf > redis_6381.conf
  21. [root@Redis-Ubuntu-1804-p21:etc]# chown redis.redis /app/redis/ -R
  22. [root@Redis-Ubuntu-1804-p21:etc]# ll
  23. total 84
  24. drwxr-xr-x 2 redis redis  4096 Apr 13 22:52 ./
  25. drwxr-xr-x 7 redis redis  4096 Apr 13 22:21 ../
  26. -rw-r--r-- 1 redis redis  1452 Apr 13 22:51 redis_6379.conf
  27. -rw-r--r-- 1 redis redis  1452 Apr 13 22:52 redis_6380.conf
  28. -rw-r--r-- 1 redis redis  1452 Apr 13 22:52 redis_6381.conf
  29. -rw-r--r-- 1 redis redis 63115 Apr 13 22:47 redis_bak.conf
  30. [root@Redis-Ubuntu-1804-p21:etc]#
复制代码
 
  1. ##方法2 sed修改并写入新配置文件
  2. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]# sed -e 's/^bind 127.0.0.1/bind 0.0.0.0/g' -e 's/^pidfile \/var\/run\/redis_6379.pid/pidfile \/app\/redis\/run\/redis_6379.pid/g' -e 's/^logfile ""/logfile "\/app\/redis\/log\/redis_6379.log"/g' -e 's/^always-show-logo yes/always-show-logo no/g' -e 's/^appendfilename "appendonly.aof"/appendfilename "appendonly_6379.aof"/g' -e 's/^dbfilename dump.rdb/dbfilename dump_6379.rdb/g' -e 's/^dir \.\//dir \/app\/redis\/data/g' redis.conf > /app/redis/etc/redis_6379.conf
  3. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]# sed 's/6379/6380/g' /app/redis/etc/redis_6379.conf > /app/redis/etc/redis_6380.conf
  4. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]# sed 's/6379/6381/g' /app/redis/etc/redis_6379.conf > /app/redis/etc/redis_6381.conf
  5. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]# chown redis.redis /app/redis/ -R
  6. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]# ll /app/redis/etc
  7. total 200
  8. drwxr-xr-x 2 redis redis  4096 Apr 13 23:46 ./
  9. drwxr-xr-x 7 redis redis  4096 Apr 13 22:21 ../
  10. -rw-r--r-- 1 redis redis 63128 Apr 13 23:34 redis_6379.conf
  11. -rw-r--r-- 1 redis redis 63128 Apr 13 23:47 redis_6380.conf
  12. -rw-r--r-- 1 redis redis 63128 Apr 13 23:47 redis_6381.conf
  13. [root@Redis-Ubuntu-1804-p21:redis-5.0.14]#
复制代码
 
 
 
7、redis service服务配置
  1. [root@Redis-Ubuntu-1804-p21:~]# vim /etc/systemd/system/redis_6379.service
  2. [Unit]
  3. Description=Redis persistent key-value database
  4. After=network.target
  5. [Service]
  6. ExecStart=/app/redis/bin/redis-server /app/redis/etc/redis_6379.conf --supervised systemd
  7. ExecStop=/bin/kill -s QUIT
  8. Type=notify
  9. User=redis
  10. Group=redis
  11. RuntimeDirectory=redis
  12. RuntimeDirectoryMode=0755
  13. LimitNOFILE=65536
  14. [Install]
  15. WantedBy=multi-user.target<br>
  16. [root@Redis-Ubuntu-1804-p21:~]# sed 's/6379/6380/g' /etc/systemd/system/redis_6379.service > /etc/systemd/system/redis_6380.service
  17. [root@Redis-Ubuntu-1804-p21:~]# sed 's/6379/6381/g' /etc/systemd/system/redis_6379.service > /etc/systemd/system/redis_6381.service
  18. [root@Redis-Ubuntu-1804-p21:~]# systemctl daemon-reload<br>
复制代码
 
8、启动服务并设置开机自启动
 
  1. [root@Redis-Ubuntu-1804-p21:~]# systemctl enable --now redis_6379.service redis_6380.service redis_6381.service
  2. Created symlink /etc/systemd/system/multi-user.target.wants/redis_6379.service → /etc/systemd/system/redis_6379.service.
  3. Created symlink /etc/systemd/system/multi-user.target.wants/redis_6380.service → /etc/systemd/system/redis_6380.service.
  4. Created symlink /etc/systemd/system/multi-user.target.wants/redis_6381.service → /etc/systemd/system/redis_6381.service.
  5. [root@Redis-Ubuntu-1804-p21:~]# ps -ef | grep redis-server
  6. redis     10491      1  0 00:24 ?        00:00:00 /app/redis/bin/redis-server 0.0.0.0:6381
  7. redis     10492      1  0 00:24 ?        00:00:00 /app/redis/bin/redis-server 0.0.0.0:6380
  8. redis     10493      1  0 00:24 ?        00:00:00 /app/redis/bin/redis-server 0.0.0.0:6379
  9. root      10512   1247  0 00:25 pts/0    00:00:00 grep --color=auto redis-server
  10. [root@Redis-Ubuntu-1804-p21:~]# ss -ntl
  11. State             Recv-Q             Send-Q                          Local Address:Port                           Peer Address:Port            
  12. LISTEN            0                  128                             127.0.0.53%lo:53                                  0.0.0.0:*               
  13. LISTEN            0                  128                                   0.0.0.0:22                                  0.0.0.0:*               
  14. LISTEN            0                  128                                 127.0.0.1:6010                                0.0.0.0:*               
  15. LISTEN            0                  128                                 127.0.0.1:6011                                0.0.0.0:*               
  16. LISTEN            0                  128                                   0.0.0.0:6379                                0.0.0.0:*               
  17. LISTEN            0                  128                                   0.0.0.0:6380                                0.0.0.0:*               
  18. LISTEN            0                  128                                   0.0.0.0:6381                                0.0.0.0:*               
  19. LISTEN            0                  128                                      [::]:22                                     [::]:*               
  20. LISTEN            0                  128                                     [::1]:6010                                   [::]:*               
  21. LISTEN            0                  128                                     [::1]:6011                                   [::]:*               
  22. [root@Redis-Ubuntu-1804-p21:~]#
复制代码
[root@Redis-Ubuntu-1804-p21:~]# tree /app/redis
/app/redis
├── bin
│   ├── redis-benchmark
│   ├── redis-check-aof
│   ├── redis-check-rdb
│   ├── redis-cli
│   ├── redis-sentinel -> redis-server
│   └── redis-server
├── data
│   └── dump_6379.rdb
├── etc
│   ├── redis_6379.conf
│   ├── redis_6380.conf
│   └── redis_6381.conf
├── log
│   ├── redis_6379.log
│   ├── redis_6380.log
│   └── redis_6381.log
└── run
    ├── redis_6379.pid
    ├── redis_6380.pid
    └── redis_6381.pid
5 directories, 16 files
[root@Redis-Ubuntu-1804-p21:~]#
 
 
 
9、观察启动日志,优化系统环境配置
 
  1. 10492:C 14 Apr 2023 00:24:57.118 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
  2. 10492:C 14 Apr 2023 00:24:57.118 # Redis version=5.0.14, bits=64, commit=00000000, modified=0, pid=10492, just started
  3. 10492:C 14 Apr 2023 00:24:57.118 # Configuration loaded
  4. 10492:C 14 Apr 2023 00:24:57.118 * supervised by systemd, will signal readiness
  5. 10492:M 14 Apr 2023 00:24:57.127 * Running mode=standalone, port=6380.
  6. 10492:M 14 Apr 2023 00:24:57.127 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
  7. 10492:M 14 Apr 2023 00:24:57.127 # Server initialized
  8. 10492:M 14 Apr 2023 00:24:57.127 # 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.
  9. 10492:M 14 Apr 2023 00:24:57.127 # 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.
  10. 10492:M 14 Apr 2023 00:24:57.132 * Ready to accept connections
复制代码
 
  1. [root@Redis-Ubuntu-1804-p21:~]# cat /proc/sys/net/core/somaxconn
  2. 128
  3. [root@Redis-Ubuntu-1804-p21:~]# cat /proc/sys/vm/overcommit_memory
  4. 0
  5. ## 补充2个参赛
  6. [root@Redis-Ubuntu-1804-p21:~]# vim /etc/sysctl.conf
  7. net.core.somaxconn=1024
  8. vm.overcommit_memory=1
  9. [root@Redis-Ubuntu-1804-p21:~]# tail /etc/sysctl.conf
  10. # Protected links
  11. #
  12. # Protects against creating or following links under certain conditions
  13. # Debian kernels have both set to 1 (restricted)
  14. # See https://www.kernel.org/doc/Documentation/sysctl/fs.txt
  15. #fs.protected_hardlinks=0
  16. #fs.protected_symlinks=0
  17. net.core.somaxconn=1024
  18. vm.overcommit_memory=1
  19. [root@Redis-Ubuntu-1804-p21:~]# sysctl -p
  20. net.core.somaxconn = 1024
  21. vm.overcommit_memory = 1
  22. [root@Redis-Ubuntu-1804-p21:~]# cat /proc/sys/net/core/somaxconn
  23. 1024
  24. [root@Redis-Ubuntu-1804-p21:~]# cat /proc/sys/vm/overcommit_memory
  25. 1
  26. <br>
复制代码
禁用透明大页
  1. #临时修改
  2. [root@Redis-Ubuntu-1804-p21:~]# cat /sys/kernel/mm/transparent_hugepage/enabled
  3. always [madvise] never
  4. [root@Redis-Ubuntu-1804-p21:~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
  5. [root@Redis-Ubuntu-1804-p21:~]# cat /sys/kernel/mm/transparent_hugepage/enabled
  6. always madvise [never]
  7. #永久修改生效 在开机启动过程中禁用
  8. [root@Redis-Ubuntu-1804-p21:~]# cat > /etc/init.d/disable_transparent_hugepage << EOF
  9. > !/bin/bash
  10. > echo never > /sys/kernel/mm/transparent_hugepage/enabled
  11. > EOF
  12. [root@Redis-Ubuntu-1804-p21:~]# chmod 755 /etc/init.d/disable_transparent_hugepage
  13. [root@Redis-Ubuntu-1804-p21:~]# cd /etc/rcS.d/
  14. [root@Redis-Ubuntu-1804-p21:rcS.d]# ln -s ../init.d/disable_transparent_hugepage disable_transparent_hugepage
  15. [root@Redis-Ubuntu-1804-p21:rcS.d]# ll /etc/init.d/ | grep disable_trans
  16. -rwxr-xr-x  1 root root   68 Apr 14 00:44 disable_transparent_hugepage*
  17. [root@Redis-Ubuntu-1804-p21:rcS.d]# ll | grep disable
  18. lrwxrwxrwx  1 root root   38 Apr 14 00:45 disable_transparent_hugepage -> ../init.d/disable_transparent_hugepage*
复制代码
 
 
10、重启Redis服务、重启服务器验证
 
  1. [root@Redis-Ubuntu-1804-p21:~]# systemctl restart redis_6380.service
  2. [root@Redis-Ubuntu-1804-p21:~]# tail -f /app/redis/log/redis_6380.log
  3. 0492:M 14 Apr 2023 00:24:57.127 # 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.
  4. 10492:M 14 Apr 2023 00:24:57.132 * Ready to accept connections
  5. 10492:signal-handler (1681404602) Received SIGTERM scheduling shutdown...
  6. 10492:M 14 Apr 2023 00:50:02.103 # User requested shutdown...
  7. 10492:M 14 Apr 2023 00:50:02.103 * Saving the final RDB snapshot before exiting.
  8. 10492:M 14 Apr 2023 00:50:02.113 * DB saved on disk
  9. 10492:M 14 Apr 2023 00:50:02.113 * Removing the pid file.
  10. 10492:M 14 Apr 2023 00:50:02.113 # Redis is now ready to exit, bye bye...
  11. 10710:C 14 Apr 2023 00:50:02.131 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
  12. 10710:C 14 Apr 2023 00:50:02.131 # Redis version=5.0.14, bits=64, commit=00000000, modified=0, pid=10710, just started
  13. 10710:C 14 Apr 2023 00:50:02.132 # Configuration loaded
  14. 10710:C 14 Apr 2023 00:50:02.132 * supervised by systemd, will signal readiness
  15. 10710:M 14 Apr 2023 00:50:02.137 * Running mode=standalone, port=6380.
  16. 10710:M 14 Apr 2023 00:50:02.137 # Server initialized
  17. 10710:M 14 Apr 2023 00:50:02.137 * DB loaded from disk: 0.000 seconds
  18. 10710:M 14 Apr 2023 00:50:02.138 * Ready to accept connections
复制代码
 
  1. [root@Redis-Ubuntu-1804-p21:~]# reboot
  2. --------------------
  3. [root@Redis-Ubuntu-1804-p21:~]# ps -ef | grep redis-server
  4. redis       858      1  0 00:52 ?        00:00:00 /app/redis/bin/redis-server 0.0.0.0:6380
  5. redis       926      1  0 00:52 ?        00:00:00 /app/redis/bin/redis-server 0.0.0.0:6381
  6. redis       928      1  0 00:52 ?        00:00:00 /app/redis/bin/redis-server 0.0.0.0:6379
  7. root       1419   1403  0 00:53 pts/0    00:00:00 grep --color=auto redis-server
  8. [root@Redis-Ubuntu-1804-p21:~]# ss -ntl
  9. State             Recv-Q             Send-Q                          Local Address:Port                           Peer Address:Port            
  10. LISTEN            0                  511                                   0.0.0.0:6379                                0.0.0.0:*               
  11. LISTEN            0                  511                                   0.0.0.0:6380                                0.0.0.0:*               
  12. LISTEN            0                  511                                   0.0.0.0:6381                                0.0.0.0:*               
  13. LISTEN            0                  128                             127.0.0.53%lo:53                                  0.0.0.0:*               
  14. LISTEN            0                  128                                   0.0.0.0:22                                  0.0.0.0:*               
  15. LISTEN            0                  128                                 127.0.0.1:6010                                0.0.0.0:*               
  16. LISTEN            0                  128                                 127.0.0.1:6011                                0.0.0.0:*               
  17. LISTEN            0                  128                                      [::]:22                                     [::]:*               
  18. LISTEN            0                  128                                     [::1]:6010                                   [::]:*               
  19. LISTEN            0                  128                                     [::1]:6011                                   [::]:*               
  20. [root@Redis-Ubuntu-1804-p21:~]# tail -f /app/redis/log/redis_6380.log
  21. 10710:M 14 Apr 2023 00:52:27.248 # Redis is now ready to exit, bye bye...
  22. 858:C 14 Apr 2023 00:52:41.166 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
  23. 858:C 14 Apr 2023 00:52:41.166 # Redis version=5.0.14, bits=64, commit=00000000, modified=0, pid=858, just started
  24. 858:C 14 Apr 2023 00:52:41.166 # Configuration loaded
  25. 858:C 14 Apr 2023 00:52:41.166 * supervised by systemd, will signal readiness
  26. 858:M 14 Apr 2023 00:52:41.170 * Running mode=standalone, port=6380.
  27. 858:M 14 Apr 2023 00:52:41.170 # Server initialized
  28. 858:M 14 Apr 2023 00:52:41.170 # 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.
  29. 858:M 14 Apr 2023 00:52:41.171 * DB loaded from disk: 0.001 seconds
  30. 858:M 14 Apr 2023 00:52:41.171 * Ready to accept connections
复制代码
 
 
11、连接数据库,验证数据读写
  1. [root@Redis-Ubuntu-1804-p21:~]# redis-cli set name janzen
  2. OK
  3. [root@Redis-Ubuntu-1804-p21:~]# redis-cli get name
  4. "janzen"
  5. [root@Redis-Ubuntu-1804-p21:~]# redis-cli -p 6380 set name janzen80
  6. OK
  7. [root@Redis-Ubuntu-1804-p21:~]# redis-cli -p 6380 get name
  8. "janzen80"
  9. [root@Redis-Ubuntu-1804-p21:~]# redis-cli -p 6381 set name janzen81
  10. OK
  11. [root@Redis-Ubuntu-1804-p21:~]# redis-cli -p 6381 get name
  12. "janzen81"
  13. [root@Redis-Ubuntu-1804-p21:~]#
复制代码
 

来源:https://www.cnblogs.com/Janzen-q/p/17314922.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

举报 回复 使用道具