linux Redis下载以及安装

Redis下载

当前redis最新版本是4.0,它是一个测试版本,稳定版本是3.2版本。
可以直接在windows上下载,通过用FileZilla文件传输器,上传到linux系统,也可以在linux下直接
最新稳定版本下载链接:http://download.redis.io/releases/redis-3.2.8.tar.gz

Redis安装

1.创建安装目录 mkdir /usr/local/redis
2.将下载的 redis-3.2.8.tar.gz 放到上一步创建的redis目录中
3.解压

tar -zxvf redis-3.2.8.tar.gz

4.进去解压后的目录 cd redis-3.2.8
5.对redis进行编译 命令make
编译失败时,可能是由于没有安装GCC环境

安装GCC环境
yum install gcc-c++

6.安装GCC环境完成后,再进入redis所在的目录路径 /usr/local/redis/redis-3.2.8
7.使用make命令进行编译,如果出现错误
错误:

zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/usr/local/src/redis-3.2.9/src'
make: *** [all] Error 2

README.md文件中有写

Allocator
---------
Selecting a non-default memory allocator when building Redis is done by setting
the `MALLOC` environment variable. Redis is compiled and linked against libc
malloc by default, with the exception of jemalloc being the default on Linux
systems. This default was picked because jemalloc has proven to have fewer
fragmentation problems than libc malloc.
To force compiling against libc malloc, use:
% make MALLOC=libc
To compile against jemalloc on Mac OS X systems, use:
% make MALLOC=jemalloc

解决:因为Redis默认加载的是jemalloc中的配置文件,有时候没有就会报错,可以使用

[root@Centos7 redis-3.2.8]# make MALLOC=libc

8.安装到指定目录

注意点:解压完成后,需要先进入解压后的目录中 cd /usr/local/redis/redis-3.2.8 执行make命令,主要是将redis相关的命令进行注册到/usr/local/bin目录中

先进入到redis的src文件中	
	cd /usr/local/redis/redis-3.2.8/src
再键入命令:
	make PREFIX=/usr/local/redis/redis install   --->安装到指定的目录

在这里插入图片描述
9.启动redis服务 redis-server & 用于启动后台服务,按下Ctrl+C不会退出服务,此时redis 并不会关闭,而是会再后台运行。
在这里插入图片描述
可通过命令查看: ps aux | grep redis
在这里插入图片描述
10.配置redis服务开机自启动
在解压文件夹 /usr/local/redis/redis-3.2.8 中拷贝 redis.config/usr/local/bin目录中,并且修改该配置信息
命令:cp /usr/local/redis-3.2.8/redis.conf /usr/local/bin
修改目录/usr/local/bin/redis.conf配置文件
把protected-mode yes改为protected-mode no(在没有密码的情况下,关闭保护模式)
注释掉bind 127.0.0.1 (取消绑定本地地址)
在这里插入图片描述
同时键入命令vim /etc/systemd/system/redis-server.service配置开机启动服务

[Unit]
Description=Redis Server Manager
After=syslog.target
After=network.target
 
[Service]
Type=simple
User=redis
Group=redis
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/bin/redis-server /usr/local/bin/redis.conf --->各自存放的路径
ExecStop=/usr/local/bin/redis-cli shutdown --->各自存放的路径
Restart=always
 
[Install]
WantedBy=multi-user.target

11.//登录
[root@Centos7 bin]# ./redis-server /usr/local/bin/redis.conf
14405:C 13 Apr 15:16:49.806 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
14405:C 13 Apr 15:16:49.806 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=14405, just started
14405:C 13 Apr 15:16:49.806 # Configuration loaded
[root@Centos7 bin]# ./redis-cli
[root@Centos7 bin]# ps -ef | grep redis
root 13437 1 0 14:17 ? 00:00:01 ./redis-server *:6379
root 13825 8950 0 14:45 pts/2 00:00:00 grep --color=auto redis
//退出
[root@Centos7 bin]# ./redis-cli shutdown
[root@Centos7 bin]# ps -ef|grep redis //查看状态
root 14379 14246 0 15:15 pts/0 00:00:00 grep --color=auto redis

另外可以使用iptables服务:
yum install iptables-services 安装iptables服务

#开放6379端口
iptables -A INPUT -p tcp --dport 6379 -j ACCEPT
#保存上述规则
service iptables save
#开启服务
systemctl restart iptables.service

经过一系列骚操作,终于可以在宿主机上面通过redis客户端连接到虚拟机的redis
在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值