Linux 安装 Redis

3 篇文章 0 订阅
3 篇文章 0 订阅
本文档详细介绍了如何在Linux系统中安装Redis,包括启动运行步骤,以及配置Redis以允许外网访问、设置守护进程后台运行和设置密码。同时,讲解了如何使用redis-cli连接Redis服务。
摘要由CSDN通过智能技术生成

Linux 安装 Redis

本例子在 redis-5.0.5.tar.gz 中测试成功

安装

# 下载
wget http://download.redis.io/releases/redis-5.0.5.tar.gz

# 解压
tar -zxvf redis-5.0.5.tar.gz 

# 进入解压目录
cd redis-5.0.5/

# 指定目录并安装,服务被安装在 /home/shaw/server/redis5 中
make PREFIX=/home/shaw/server/redis5 install

# 测试是否安装成功
make test

# 删除解压缩文件
cd ../
rm -rf redis-5.0.5/

启动运行

# 使用指定的 Redis 配置文件进行运行
/home/shaw/server/redis5/bin/redis-server /home/shaw/server/redis5/redis.conf

常用配置(redis.conf)

允许外网访问

注释掉 bind 127.0.0.1 即可

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
# 
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1

开启守护进程(后台运行)

设置 daemonize yes 即可

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize no

设置密码

取消 requirepass foobared 注释,并将 foobared 修改为自己期望的密码即可;

################################## SECURITY ###################################

# Require clients to issue AUTH <PASSWORD> before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
# 
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
# 
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
# 
# requirepass foobared

使用 redis 自带工具配置 Redis

shaw@shaw-pc:~/server/redis-install/utils$ cd /home/shaw/server/redis-install/
shaw@shaw-pc:~/server/redis-install$ cd utils/
shaw@shaw-pc:~/server/redis-install/utils$ sudo su
root@shaw-pc:/home/shaw/server/redis-install/utils#
root@shaw-pc:/home/shaw/server/redis-install/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] /home/shaw/server/redis5/635^C
root@shaw-pc:/home/shaw/server/redis-install/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] /home/shaw/server/redis5/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] /home/shaw/server/redis5/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] /home/shaw/server/redis5/6379
Please select the redis executable path [] /home/shaw/server/redis5/bin/redis-server
Selected config:
Port : 6379
Config file : /home/shaw/server/redis5/6379.conf
Log file : /home/shaw/server/redis5/redis_6379.log
Data dir : /home/shaw/server/redis5/6379
Executable : /home/shaw/server/redis5/bin/redis-server
Cli Executable : /home/shaw/server/redis5/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Success!
Starting Redis server...
Installation successful!

redis-cli

连接服务

redis-cli -h localhost -p 6379 -a myredispassword
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值