redis 高阶(一)linux环境安装redis

https://www.bilibili.com/video/BV1XV411o7xP

1.linux环境下载安装

http://www.redis.cn/download.html

1.1 下载安装包

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


1.2 解压

tar –xvf 文件名.tar.gz

1.3 编译

make

1.3.1 编译错误zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory

解决办法: 使用以下命令

make MALLOC=libc

原因分析:

在README 有这个一段话。

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

说关于分配器allocator, 如果有MALLOC 这个 环境变量, 会有用这个环境变量的 去建立Redis。

而且libc 并不是默认的 分配器, 默认的是 jemalloc, 因为 jemalloc 被证明 有更少的 fragmentation problems 比libc。

但是如果你又没有jemalloc 而只有 libc 当然 make 出错。 所以加这么一个参数

 

1.3.2 编译redis报错/deps/hiredis/libhiredis.a解决

进入源码包目录下的deps目录中执行

make lua hiredis linenoise
[root@iZ2zecxzxrta513fg5rl58Z deps]# make lua hiredis linenoise
MAKE lua
cd lua/src && make all CFLAGS="-O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' " MYLDFLAGS="" AR="ar rcu"
make[1]: Entering directory `/usr/local/redis-5.0.9/deps/lua/src'
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=''    -c -o lapi.o lapi.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=''    -c -o lcode.o lcode.c
......
......
make[1]: Entering directory `/usr/local/redis-5.0.9/deps/linenoise'
cc  -Wall -Os -g  -c linenoise.c
make[1]: Leaving directory `/usr/local/redis-5.0.9/deps/linenoise'
[root@iZ2zecxzxrta513fg5rl58Z deps]# 

1.4 安装

make install [destdir=/目录]

2.安装中常碰到的问题

2.1 -bash: make: command not found

centos

 yum -y install gcc automake autoconf libtool make

ubuntu

sudo apt-get update

sudo apt-get install make 

3.Redis基础环境设置

创建软链接
ln -s 原始目录名 快速访问目录名
创建配置文件管理目录

mkdir conf
mkdir config

创建数据文件管理目录

mkdir data

4.Redis服务启动

默认配置启动

redis-server
redis-server –-port 6379
redis-server –-port 6380 ……

指定配置文件启动

redis-server redis.conf
redis-server redis-6379.conf
redis-server redis-6380.conf ……
redis-server conf/redis-6379.conf
redis-server config/redis-6380.conf ……

5.Redis客户端连接

默认连接

redis-cli

连接指定服务器

redis-cli -h 127.0.0.1
redis-cli –port 6379
redis-cli -h 127.0.0.1 –port 6379

6.Redis服务端配置

/usr/local/redis-5.0.5/redis.conf

配置查看

cat redis.conf

过滤掉注释以及留下的空白

cat redis.conf | grep -v "#" | grep -v "^$"
bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes

基本配置

#以守护进程方式启动,使用本启动方式,redis将以服务的形式存在,日志将不再打印到命令窗口中
daemonize yes
#设定当前服务启动端口号`
port 6379
#设定当前服务文件保存位置,包含日志文件、持久化文件(后面详细讲解)等
dir "/usr/local/redis-5.0.5/data"
#设定日志文件名,便于查阅
logfile "redis-6379.log"

7.决redis远程连接不上的问题

redis现在的版本开启redis-server后,redis-cli只能访问到127.0.0.1,因为在配置文件中固定了ip,因此需要修改redis.conf(有的版本不是这个文件名,只要找到相对应的conf后缀的文件即可)文件以下几个地方。

1.bind 127.0.0.1改为 #bind 127.0.0.1 (注释掉)

2.protected-mode yes 改为 protected-mode no

3.加入 daemonize no(这个是是否在后台启动不占用一个主程窗口)

 

vim打开编辑:

dd 删除当前行

按下3dd  删除光标往下3行

按下gg,光标自动到首行

按下dG,删除光标所在行以及其下面所有行内容

 

 

 

申明:内容来自网络,仅供学习使用。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值