linux服务器上离线安装redis

Posted 健康平安的活着

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux服务器上离线安装redis相关的知识,希望对你有一定的参考价值。

一 离线安装redis

1.1 说明

Redis为c语言编写,因此安装需要配置c语言编译环境gcc,查看linux是否安装了该编译环境。

[uredis@localhost ~]$ gcc -v
bash: gcc: command not found...
[uredis@localhost ~]$ 

1.2 软件包下载地址

1.gcc

https://download.csdn.net/download/u011066470/20488382

gcc的下载包

2.redis各种软件包版本

各版本下载地址:http://download.redis.io/releases/

1.3 将软件包上传到服务器上

本次使用redis的软件包版本为6.2.1,如下图所示:

 1.4 安装gcc

安装gcc,可以从官网下载iso镜像,从里面packages找出来,这里已经将其汇总好了,如

下图所示 

1.解压gcc

[uredis@localhost ~]$ unzip gcc.zip 
Archive:  gcc.zip
   creating: gcc/
  inflating: gcc/binutils-2.27-27.base.el7.x86_64.rpm  
  inflating: gcc/cpp-4.8.5-28.el7.x86_64.rpm  
  inflating: gcc/gcc-4.8.5-28.el7.x86_64.rpm  
  inflating: gcc/gcc-c++-4.8.5-28.el7.x86_64.rpm  
  inflating: gcc/glib2-2.54.2-2.el7.x86_64.rpm  
  inflating: gcc/glib2-devel-2.54.2-2.el7.x86_64.rpm  
  inflating: gcc/kernel-headers-3.10.0-862.el7.x86_64.rpm  
  inflating: gcc/libgcc-4.8.5-28.el7.x86_64.rpm  
  inflating: gcc/libgomp-4.8.5-28.el7.x86_64.rpm  
  inflating: gcc/libmpc-1.0.1-3.el7.x86_64.rpm  
  inflating: gcc/libstdc++-devel-4.8.5-28.el7.x86_64.rpm  
  inflating: gcc/mpfr-3.1.1-4.el7.x86_64.rpm  
  inflating: gcc/zlib-1.2.7-17.el7.x86_64.rpm  
  inflating: gcc/glibc-devel-2.17-222.el7.x86_64.rpm  
  inflating: gcc/glibc-headers-2.17-222.el7.x86_64.rpm  
[uredis@localhost ~]$ ls

2.查看软件包

[uredis@localhost ~]$ cd gcc
[uredis@localhost gcc]$ ls
binutils-2.27-27.base.el7.x86_64.rpm  glib2-2.54.2-2.el7.x86_64.rpm          kernel-headers-3.10.0-862.el7.x86_64.rpm  libstdc++-devel-4.8.5-28.el7.x86_64.rpm
cpp-4.8.5-28.el7.x86_64.rpm           glib2-devel-2.54.2-2.el7.x86_64.rpm    libgcc-4.8.5-28.el7.x86_64.rpm            mpfr-3.1.1-4.el7.x86_64.rpm
gcc-4.8.5-28.el7.x86_64.rpm           glibc-devel-2.17-222.el7.x86_64.rpm    libgomp-4.8.5-28.el7.x86_64.rpm           zlib-1.2.7-17.el7.x86_64.rpm
gcc-c++-4.8.5-28.el7.x86_64.rpm       glibc-headers-2.17-222.el7.x86_64.rpm  libmpc-1.0.1-3.el7.x86_64.rpm
[uredis@localhost gcc]$ ls -l
total 50184
-rw-rw-r--. 1 uredis uredis  6188360 Apr 25  2018 binutils-2.27-27.base.el7.x86_64.rpm
-rw-rw-r--. 1 uredis uredis  6234536 Apr 25  2018 cpp-4.8.5-28.el7.x86_64.rpm
-rw-rw-r--. 1 uredis uredis 16967040 Apr 25  2018 gcc-4.8.5-28.el7.x86_64.rpm
-rw-rw-r--. 1 uredis uredis  7528828 Apr 25  2018 gcc-c++-4.8.5-28.el7.x86_64.rpm
-rw-rw-r--. 1 uredis uredis  2529644 Apr 25  2018 glib2-2.54.2-2.el7.x86_64.rpm
-rw-rw-r--. 1 uredis uredis   456800 Apr 25  2018 glib2-devel-2.54.2-2.el7.x86_64.rpm
-rw-rw-r--. 1 uredis uredis  1116252 Apr 25  2018 glibc-devel-2.17-222.el7.x86_64.rpm
-rw-rw-r--. 1 uredis uredis   694524 Apr 25  2018 glibc-headers-2.17-222.el7.x86_64.rpm
-rw-rw-r--. 1 uredis uredis  7442492 Apr 25  2018 kernel-headers-3.10.0-862.el7.x86_64.rpm
-rw-rw-r--. 1 uredis uredis   102940 Apr 25  2018 libgcc-4.8.5-28.el7.x86_64.rpm
-rw-rw-r--. 1 uredis uredis   160032 Apr 25  2018 libgomp-4.8.5-28.el7.x86_64.rpm
-rw-rw-r--. 1 uredis uredis    51732 Jul  4  2014 libmpc-1.0.1-3.el7.x86_64.rpm
-rw-rw-r--. 1 uredis uredis  1578996 Apr 25  2018 libstdc++-devel-4.8.5-28.el7.x86_64.rpm
-rw-rw-r--. 1 uredis uredis   208316 Jul  4  2014 mpfr-3.1.1-4.el7.x86_64.rpm
-rw-rw-r--. 1 uredis uredis    91872 Nov 21  2016 zlib-1.2.7-17.el7.x86_64.rpm

3.进行安装

输入命令:rpm -Uvh *.rpm --nodeps --force

[root@localhost gcc]# rpm -Uvh *.rpm --nodeps --force
warning: binutils-2.27-27.base.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:zlib-1.2.7-17.el7                ################################# [  5%]
   2:mpfr-3.1.1-4.el7                 ################################# [ 10%]
   3:libmpc-1.0.1-3.el7               ################################# [ 14%]
   4:libgcc-4.8.5-28.el7              ################################# [ 19%]
   5:glib2-2.54.2-2.el7               ################################# [ 24%]
   6:cpp-4.8.5-28.el7                 ################################# [ 29%]
   7:binutils-2.27-27.base.el7        ################################# [ 33%]
   8:libstdc++-devel-4.8.5-28.el7     ################################# [ 38%]
   9:libgomp-4.8.5-28.el7             ################################# [ 43%]
  10:kernel-headers-3.10.0-862.el7    ################################# [ 48%]
  11:glibc-headers-2.17-222.el7       ################################# [ 52%]
  12:glibc-devel-2.17-222.el7         ################################# [ 57%]
  13:gcc-4.8.5-28.el7                 ################################# [ 62%]
  14:gcc-c++-4.8.5-28.el7             ################################# [ 67%]
  15:glib2-devel-2.54.2-2.el7         ################################# [ 71%]
Cleaning up / removing...
  16:gcc-c++-4.4.7-4.el6              ################################# [ 76%]
  17:libstdc++-devel-4.4.7-4.el6      ################################# [ 81%]
  18:gcc-4.4.7-4.el6                  ################################# [ 86%]
  19:glibc-devel-2.12-1.132.el6       ################################# [ 90%]
  20:glibc-headers-2.12-1.132.el6     ################################# [ 95%]
  21:kernel-headers-2.6.32-431.el6    ################################# [100%]

4.查看版本gcc,c++的版本

查看:

1. gcc  -v 

 2. g++ -v

[root@localhost gcc]# 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-28) (GCC) 
[root@localhost gcc]# g++ -v
Using built-in specs.
COLLECT_GCC=g++
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-28) (GCC) 

可以看到gcc,c++这些需要的编译环境均已经按照ok

  1.5 安装redis

1.解压redis

[root@localhost uredis]# tar -zxvf redis-6.2.1.tar.gz 
redis-6.2.1/
redis-6.2.1/.github/
redis-6.2.1/.github/ISSUE_TEMPLATE/
redis-6.2.1/.github/ISSUE_TEMPLATE/bug_report.md
redis-6.2.1/.github/ISSUE_TEMPLATE/crash_report.md
redis-6.2.1/.github/ISSUE_TEMPLATE/feature_request.md
redis-6.2.1/.github/ISSUE_TEMPLATE/other_stuff.md
redis-6.2.1/.github/ISSUE_TEMPLATE/question.md
redis-6.2.1/.github/workflows/
redis-6.2.1/.github/workflows/ci.yml
redis-6.2.1/.github/workflows/daily.yml
redis-6.2.1/.gitignore
redis-6.2.1/00-RELEASENOTES
redis-6.2.1/BUGS
redis-6.2.1/CONDUCT
redis-6.2.1/CONTRIBUTIN

2.使用make进行编译安装

输入命令: make MALLOC=libc

[root@localhost uredis]# ls
gcc  gcc_rpm.tar.gz  gcc.zip  redis-6.2.1  redis-6.2.1.tar.gz
[root@localhost uredis]# cd redis-6.2.1/
[root@localhost redis-6.2.1]# ls
00-RELEASENOTES  CONDUCT       COPYING  INSTALL   MANIFESTO  redis.conf  runtest-cluster    runtest-sentinel  src    TLS.md
BUGS             CONTRIBUTING  deps     Makefile  README.md  runtest     runtest-moduleapi  sentinel.conf     tests  utils
[root@localhost redis-6.2.1]# make MALLOC=libc
cd src && make all
make[1]: Entering directory `/home/uredis/redis-6.2.1/src'
    CC Makefile.dep
make[1]: Leaving directory `/home/uredis/redis-6.2.1/src'
make[1]: Entering directory `/home/uredis/redis-6.2.1/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
rm -f adlist.d quicklist.d ae.d anet.d dict.d server.d sds.d zmalloc.d lzf_c.d lzf_d.d pqsort.d zipmap.d sha1.d ziplist.d release.d networking.d util.d object.d db.d replication.d rdb.d t_string.d t_list.d t_set.d t_zset.d t_hash.d config.d aof.d pubsub.d multi.d debug.d sort.d intset.d syncio.d cluster.d crc16.d endianconv.d slowlog.d scripting.d bio.d rio.d rand.d memtest.d crcspeed.d crc64.d bitops.d sentinel.d notify.d setproctitle.d blocked.d hyperloglog.d latency.d sparkline.d redis-check-rdb.d redis-check-aof.d geo.d lazyfree.d module.d evict.d expire.d geohash.d geohash_helper.d childinfo.d defrag.d siphash.d rax.d t_stream.d listpack.d localtime.d lolwut.d lolwut5.d lolwut6.d acl.d gopher.d tracking.d connection.d tls.d sha256.d timeout.d setcpuaffinity.d monotonic.d mt19937-64.d anet.d adlist.d dict.d redis-cli.d zmalloc.d release.d ae.d crcspeed.d crc64.d siphash.d crc16.d monotonic.d cli_common.d mt19937-64.d ae.d anet.d redis-benchmark.d adlist.d dict.d zmalloc.d release.d crcspeed.d crc64.d siphash.d crc16.d monotonic.d cli_common.d mt19937-64.d
(cd ../deps && make distclean)
....
make[2]: Leaving directory `/home/uredis/redis-6.2.1/deps'
    CC adlist.o
    CC quicklist.o
    CC ae.o
    CC anet.o
    CC dict.o
    CC server.o
    CC sds.o
    CC zmalloc.o
    CC lzf_c.o
    CC lzf_d.o
    CC pqsort.o
    CC zipmap.o
    CC sha1.o
    CC ziplist.o
    CC release.o
    CC networking.o
    CC util.o
    CC object.o
    CC db.o
    CC replication.o
    CC rdb.o
    CC t_string.o
    CC t_list.o
    CC t_set.o
    CC t_zset.o
    CC t_hash.o
    CC config.o
    CC aof.o
    CC pubsub.o
    CC multi.o
    CC debug.o
    CC sort.o
    CC intset.o
    CC syncio.o
    CC cluster.o
    CC crc16.o
    CC endianconv.o
    CC slowlog.o
    CC scripting.o
    CC bio.o
    CC rio.o
    CC rand.o
    CC memtest.o
    CC crcspeed.o
    CC crc64.o
    CC bitops.o
    CC sentinel.o
    CC notify.o
    CC setproctitle.o
    CC blocked.o
    CC hyperloglog.o
    CC latency.o
    CC sparkline.o
    CC redis-check-rdb.o
    CC redis-check-aof.o
    CC geo.o
    CC lazyfree.o
    CC module.o
    CC evict.o
    CC expire.o
    CC geohash.o
    CC geohash_helper.o
    CC childinfo.o
    CC defrag.o
    CC siphash.o
    CC rax.o
    CC t_stream.o
    CC listpack.o
    CC localtime.o
    CC lolwut.o
    CC lolwut5.o
    CC lolwut6.o
    CC acl.o
    CC gopher.o
    CC tracking.o
    CC connection.o
    CC tls.o
    CC sha256.o
    CC timeout.o
    CC setcpuaffinity.o
    CC monotonic.o
    CC mt19937-64.o
    LINK redis-server
    INSTALL redis-sentinel
    CC redis-cli.o
    CC cli_common.o
    LINK redis-cli
    CC redis-benchmark.o
    LINK redis-benchmark
    INSTALL redis-check-rdb
    INSTALL redis-check-aof

Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory `/home/uredis/redis-6.2.1/src'

截图如下所示:

 3.src的安装

输入命令: cd src && make install

[root@localhost redis-6.2.1]# cd src && make install
    CC Makefile.dep

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install

  1.6 启动redis服务

进入到/home/uredis/redis-6.2.1/src 目录下: 输入命令: ./redis-server

[root@localhost src]# ./redis-server
8374:C 27 Jul 2021 16:24:05.224 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8374:C 27 Jul 2021 16:24:05.224 # Redis version=6.2.1, bits=64, commit=00000000, modified=0, pid=8374, just started
8374:C 27 Jul 2021 16:24:05.224 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
8374:M 27 Jul 2021 16:24:05.225 * Increased maximum number of open files to 10032 (it was originally set to 1024).
8374:M 27 Jul 2021 16:24:05.225 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 6.2.1 (00000000/0) 64 bit
  .-`` .-```.  ```\\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 8374
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

8374:M 27 Jul 2021 16:24:05.232 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
8374:M 27 Jul 2021 16:24:05.232 # Server initialized
8374:M 27 Jul 2021 16:24:05.232 # 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.
8374:M 27 Jul 2021 16:24:05.233 * Ready to accept connections

  1.7 启动redis客户端

打开一个新的窗口,进入到/home/uredis/redis-6.2.1/src 这个目录下,执行: ./redis-cli

[root@localhost src]# pwd
/home/uredis/redis-6.2.1/src
[root@localhost src]#  ./redis-cli
127.0.0.1:6379> keys *
(empty array)
127.0.0.1:6379> 

ok,到此redis安装完毕,且启动服务端,客户端

  1.8 将redis作为系统服务,开机自启动

1.复制redis配置文件

[root@localhost src]# mkdir /etc/redis
[root@localhost src]# cd ..
[root@localhost redis-6.2.1]# cp redis.conf /etc/redis/6379.conf

2、将启动文件拷贝到init.d中

[root@localhost redis-6.2.1]# cp utils/redis_init_script /etc/init.d/redisd

3.修改启动脚本

[root@localhost redis-6.2.1]# vi /etc/init.d/redisd

修改成真实的地址

 4、增加脚本执行权限

[root@localhost redis-6.2.1]# chmod +x /etc/init.d/redisd
5.增加系统服务

[root@localhost redis-6.2.1]# chkconfig --add redisd
[root@localhost redis-6.2.1]# chkconfig --list redisd


Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

redisd             0:off    1:off    2:on    3:on    4:on    5:on    6:off

6.测试服务启动

启动命令:service redisd start

[root@localhost redis-6.2.1]#  service redisd start
Starting Redis server...
9813:C 27 Jul 2021 18:10:14.829 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
9813:C 27 Jul 2021 18:10:14.829 # Redis version=6.2.1, bits=64, commit=00000000, modified=0, pid=9813, just started
9813:C 27 Jul 2021 18:10:14.829 # Configuration loaded
9813:M 27 Jul 2021 18:10:14.829 * Increased maximum number of open files to 10032 (it was originally set to 1024).
9813:M 27 Jul 2021 18:10:14.829 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 6.2.1 (00000000/0) 64 bit
  .-`` .-```.  ```\\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 9813
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

9813:M 27 Jul 2021 18:10:14.831 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
9813:M 27 Jul 2021 18:10:14.831 # Server initialized
9813:M 27 Jul 2021 18:10:14.831 # 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.
9813:M 27 Jul 2021 18:10:14.831 * Ready to accept connections

查看端口号:

 

https://blog.csdn.net/qq_35197601/article/details/83374162

以上是关于linux服务器上离线安装redis的主要内容,如果未能解决你的问题,请参考以下文章

三台服务器上离线安装redis哨兵集群,一主二从三哨兵

2linux上离线安装python

1linux上离线安装jdk

在Linux上离线安装SQL Server 2017

在linux上离线安装harbor的docker 私有仓库

在linux上离线安装harbor的docker 私有仓库