Linux系统安装redis详细步骤

目录

一: 下载和安装redis

1.下载redis

2.解压文件

3.安装gcc

4.安装redis

二: 配置环境变量

三: 在系统中安装redis服务

四: 关闭防火墙

五: 对外开放访问权限


一: 下载和安装redis

1.下载redis

1)https://download.redis.io/releases/  下载redis

2)通过Xftp工具进行上传,选择下载好的redis文件拖到右侧对应的目录即可

2.解压文件

在Linux中, 将redis压缩包解压到指定的目录,这里是将redis解压到/opt文件夹下,可以使用-C指定到解压的文件夹

# tar -zvxf redis-7.0.10.tar.gz -C /opt

3.安装gcc

GCC 全称是GNU Compiler Collection,它是一个由GNU项目开发的编译器套件,包含了C、C++、Objective-C、Fortran、Ada 和Go等多个语言的编译器。

1)由于redis是c语言编写的,所以我们需要先安装gcc,安装的命令如下:yum -y install gcc

# yum -y install gcc

 2)安装成功后输入 : gcc -v 查看版本

4.安装redis

1)然后进入到redis目录,进入 redis-7.0.10,然后输入:make,控制台会输出一编译的信息

# cd redis-7.0.10

# make

2)编译成功后,输入:make install ,自此redis就安装成功了。

# make install

3)输入:redis-server 启动redis,启动成功。

三种启动方式:

- 通过redis-server指令启动:

        在任何目录下执行 redis-server

- 通过配置文件的方式启动:

        redis-server redis6379.conf

- 后台启动方式:

        在任何目录下执行 redis-server &

二: 配置环境变量

export REDIS_HOME=/opt/redis
export PATH=$PATH:$REDIS_HOME/bin
保存退出
source /etc/profile  --刷新环境变量

三: 在系统中安装redis服务

[root@localhost utils]# ./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server

This systems seems to use systemd.
Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!
------------------------------------------出现上述问题,将如下内容注释掉即可------------------------------------------
vim /redis/utils/install_server.sh

#bail if this system is managed by systemd
#_pid_1_exe="$(readlink -f /proc/1/exe)"
#if [ "${_pid_1_exe##*/}" = systemd ]
#then
#       echo "This systems seems to use systemd."
#       echo "Please take a look at the provided ece unit files in this directory, and adapt and install them. Sorry!"
#       exit 1
#fi

 通过命令去修改文件,或者xftp上找到文件进行编辑

再次安装服务

[root@localhost utils]# ./install_server.sh 
----------------------------------------------------------------------------------------------------
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379]      ---端口号
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]     ----配置文件
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]     ----日志文件
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]   -----数据文件
Selected default - /var/lib/redis/6379
Please select the redis executable path [/opt/redis/bin/redis-server]     -----服务安装路径(根据配置好得path得来的)
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /opt/redis/bin/redis-server
Cli Executable : /opt/redis/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.     ----提示回车表示同意执行  Ctrl-C取消
Copied /tmp/6379.conf => /etc/init.d/redis_6379               ----可执行文件得位置
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
/var/run/redis_6379.pid exists, process is already running or crashed
Installation successful!

 测试是否可以执行 redis的执行文件

[root@localhost /]# service redis_6379 status
Redis is not running

如果是 Redis is running 说明已经成功 ,如果是上面的结果请继续往下走:

四: 关闭防火墙

执行下面两条命令:

setenforce 0          #setenforce 0 表示关闭selinux防火墙

systemctl stop firewalld.service      #关闭防火墙*

五: 对外开放访问权限

1、 vim /etc/redis/6379.conf
protected-mode no ----注释掉redis.window.conf文件中的bind属性设置
#bind 127.0.0.1   ----注释掉redis.window.conf文件中的bind属性设置

2、重启redis
service redis_6379 stop
service redis_6379 start

大功告成!!!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值