redis的安装(linux)

1.下载安装包并复制到/opt目录下

[root@localhost ~]# cd /opt
[root@localhost opt]# ls
apache-tomcat-8.5.35         jdk-8u121-linux-x64.tar.gz                 redis-5.0.2.tar.gz
apache-tomcat-8.5.35.tar.gz  mysql-5.7.18                               rh
jdk1.8.0_121                 mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

2.解压

[root@localhost opt]# tar -zxvf redis-5.0.2.tar.gz -C /opt
redis-5.0.2/
redis-5.0.2/.gitignore
redis-5.0.2/00-RELEASENOTES

3.编译redis,进入解压目录,并且执行make命令:

[root@localhost opt]# cd redis-5.0.2/
[root@localhost redis-5.0.2]# make
//会发现报错,这是因为redis是由c语言写的,所以要安装c语言编译器
make[3]: gcc:命令未找到
make[3]: *** [net.o] 错误 127

4.安装gcc

//执行以下命令必须连接网络(在执行中还需按下y键)
[root@localhost redis-5.0.2]# yum install gcc
已加载插件:fastestmirror, langpacks
base                                                                  | 3.6 kB  00:00:01     
extras                                                                | 2.9 kB  00:00:00     
updates                                                               | 2.9 kB  00:00:00    

5.查看gcc是否安装成功,执行gcc –v查看Linux内核版本

[root@localhost redis-5.0.2]# gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
目标:x86_64-redhat-linux
配置为:../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
线程模型:posix
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) //版本,表示安装成功

6.再次编译redis:进入解压目录,并且执行make命令

//上次编译生成垃圾文件.
[root@localhost redis-5.0.2]# make
cd src && make all
make[1]: 进入目录“/opt/redis-5.0.2/src”
    CC Makefile.dep
make[1]: 离开目录“/opt/redis-5.0.2/src”
make[1]: 进入目录“/opt/redis-5.0.2/src”
    CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录
 #include <jemalloc/jemalloc.h>
                               ^
编译中断。
make[1]: *** [adlist.o] 错误 1
make[1]: 离开目录“/opt/redis-5.0.2/src”
make: *** [all] 错误 2

7.清理上次编译生成的垃圾文件

[root@localhost redis-5.0.2]# make distclean
cd src && make distclean
make[1]: 进入目录“/opt/redis-5.0.2/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]: 进入目录“/opt/redis-5.0.2/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]: 离开目录“/opt/redis-5.0.2/deps”
(rm -f .make-*)
make[1]: 离开目录“/opt/redis-5.0.2/src”

8.再次编译redis:进入解压目录,并且执行make命令

//下面会加载很多东西
[root@localhost redis-5.0.2]# make

9.执行make install安装redis(为了在任何目录下运行命令)

//该操作则将 src下的许多可执行文件复制到/usr/local/bin 目录下,这样做可以在任意目录执行redis的软件的命令(例如启动,停止,客户端连接服务器等), make install 可以不用执行,
[root@localhost redis-5.0.2]# make install
cd src && make install
make[1]: 进入目录“/opt/redis-5.0.2/src”
    CC Makefile.dep
make[1]: 离开目录“/opt/redis-5.0.2/src”
make[1]: 进入目录“/opt/redis-5.0.2/src”

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

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: 离开目录“/opt/redis-5.0.2/src”

10.启动redis服务端

a)方式一:
前台启动:在任意目录下执行:redis-server
b)方式二:
后台启动:在任意目录下执行:redis-server &
c)方式三:启动redis服务时,指定配置文件.(默认不以配置文件方式启动)
在redis.conf所在目录下执行:redis-server redis.conf &

//启动完成
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.2 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 8695
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

11.启动redis客户端连接服务端

a)方式一:默认连接本机上的6379端口上的redis服务.
在任意目录下执行:redis-cli
b)方式二:连接指定机器上的指定端口上的redis服务:
在任意目录下执行:redis-cli -p 端口号 -h ip

[root@localhost redis-5.0.2]# redis-cli
127.0.0.1:6379> 

12.退出客户端

127.0.0.1:6379> exit
[root@localhost redis-5.0.2]# 

13.关闭Redis

a)杀死redis服务进程:
ps -ef|grep redis
kill -9 PID
b)使用redis-cli向服务端发送shutdown指令:(推荐)
redis-cli shutdown
redis-cli -p port -h ip shutdown

[root@localhost redis-5.0.2]# redis-cli shutdown
8695:M 29 Oct 2020 19:27:05.003 # User requested shutdown...
8695:M 29 Oct 2020 19:27:05.003 * Saving the final RDB snapshot before exiting.
8695:M 29 Oct 2020 19:27:05.013 * DB saved on disk
8695:M 29 Oct 2020 19:27:05.014 # Redis is now ready to exit, bye bye...
[1]+  完成                  redis-server
//我们查看redis进程发现已经关闭
[root@localhost redis-5.0.2]# ps -ef | grep redis
root       8753   3568  0 19:27 pts/0    00:00:00 grep --color=auto redis
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值