Ubuntu18.10下Redis安装与配置

一. Redis安装:

1. 下载Redis

wget http://download.redis.io/releases/redis-3.2.8.tar.gz

2. 解压安装文件

tar -zxvf redis-3.2.8.tar.gz

3. 解压后的文件移动到usr/local目录下

sudo mv ./redis-3.2.8 /usr/local/redis/

4. 进入redis目录

cd /usr/local/redis/

5. 生成可执行文件

sudo make

如果执行make命令时出现错误, 请保证make和gcc已安装成功

sudo apt-get install cpp
sudo apt-get install binutils
sudo apt-get install glibc
sudo apt-get install glibc-kernheaders
sudo apt-get install glibc-common
sudo apt-get install glibc-devel

sudo apt-get install glibc-source 
sudo apt-get install gcc
sudo apt-get install make

如果make和gcc已安装成功, 还报错, 执行下如下代码

cd /usr/local/redis/deps/
sudo make geohash-int hiredis jemalloc linenoise lua

6. 测试程序

sudo make test

7. 安装程序, 默认会安装到/usr/local/bin/

sudo make install

8.安装完成后,进入目录/usr/local/bin中查看

sudo cd /usr/local/bin

sudo ll

redis-server redis服务器
redis-cli redis命令行客户端
redis-benchmark redis性能测试工具
redis-check-aof AOF文件修复工具
redis-check-rdb RDB文件检索工具

9. 配置文件默认目录为/usr/local/redis/redis.conf,  移动到/etc/redis/目录下

sudo cp /usr/local/redis/redis.conf /etc/redis/

二. Redis的配置

打开配置文件

sudo vim /etc/redis/redis.conf

主要的配置信息


# 绑定ip, 如果需要远程访问, 则注释掉即可
# bind 127.0.0.1

# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
# 端口号, 默认是6379
port 6379

# 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.
# 是否以守护进程运行, 默认是no, 推荐使用yes
daemonize yes

注: 守护进程(daemon)是一类在后台运行的特殊进程,用于执行特定的系统任务。很多守护进程在系统引导的时候启动,并且一直运行直到系统关闭。另一些只在需要的时候才启动,完成任务后就自动结束。

# The filename where to dump the DB
# 数据库在做持久化时存储的文件名
dbfilename dump.rdb

# The working directory.
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
# The Append Only File will also be created inside this directory.
# Note that you must specify a directory here, not a file name.
# 数据持久化文件存放的目录(如果目录不存在, 需要手动创建), 默认 ./ 表示当前目录
# dir ./
dir /var/lib/redis

# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
# 日志文件存放目录, 默认没有
# logfile ""
logfile "/var/log/redis/redis-server.log"

# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and 'databases'-1
# 数据库数量, 默认16个, 编号0-15
databases 16


# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#
# 1) Redis replication is asynchronous, but you can configure a master to
#    stop accepting writes if it appears to be not connected with at least
#    a given number of slaves.
# 2) Redis slaves are able to perform a partial resynchronization with the
#    master if the replication link is lost for a relatively small amount of
#    time. You may want to configure the replication backlog size (see the next
#    sections of this file) with a sensible value depending on your needs.
# 3) Replication is automatic and does not need user intervention. After a
#    network partition slaves automatically try to reconnect to masters
#    and resynchronize with them.
# 主从配置, 默认不需要配置
# slaveof <masterip> <masterport>

启动redis服务: redis-server

启动redis客户端: redis-cli

更多配置信息, 请参考 http://blog.csdn.net/ljphilp/article/details/52934933

猜你喜欢

转载自blog.csdn.net/Javaer2014/article/details/84971962