Linux安装Redis(小白必备)

上篇刚装完MySQL,现在我们再来装Redis

1、大家先下载Redis安装包

[root@izbp1g3d9v59h2hak283f2z ~]# wget http://download.redis.io/releases/redis-5.0.5.tar.gz
--2019-12-30 14:24:03--  http://download.redis.io/releases/redis-5.0.5.tar.gz
Resolving download.redis.io (download.redis.io)... 109.74.203.151
Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1975750 (1.9M) [application/x-gzip]
Saving to: ‘redis-5.0.5.tar.gz’

100%[=============================================================================================================================================>] 1,975,750   18.2KB/s   in 2m 14s 

2019-12-30 14:26:19 (14.4 KB/s) - ‘redis-5.0.5.tar.gz’ saved [1975750/1975750]

我是直接通过网络下载的,大家也可以现在Windows下下载好在通过工具上传至Linux服务器

2、解压

[root@izbp1g3d9v59h2hak283f2z ~]# tar -zxf redis-5.0.5.tar.gz 
[root@izbp1g3d9v59h2hak283f2z ~]# ll
total 631756
-rw-r--r-- 1 root root 644930593 Oct  4  2018 mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
drwxrwxr-x 6 root root      4096 May 16  2019 redis-5.0.5
-rw-r--r-- 1 root root   1975750 May 16  2019 redis-5.0.5.tar.gz

3、移动

[root@izbp1g3d9v59h2hak283f2z ~]# mv redis-5.0.5 /usr/local/redis
[root@izbp1g3d9v59h2hak283f2z ~]# cd /usr/local/
[root@izbp1g3d9v59h2hak283f2z local]# ll
total 52
drwxr-xr-x   6 root  root  4096 Dec 24 02:24 aegis
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 bin
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 etc
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 games
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 include
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 lib
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 lib64
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 libexec
drwxr-xr-x  10 mysql mysql 4096 Dec 30 11:21 mysql
drwxrwxr-x   6 root  root  4096 May 16  2019 redis
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 sbin
drwxr-xr-x.  6 root  root  4096 Dec 23 16:19 share
drwxr-xr-x.  2 root  root  4096 Nov  5  2016 src
[root@izbp1g3d9v59h2hak283f2z local]# cd redis

4、编译

进入解压后的Redis目录,输入 make 进行编译

[root@izbp1g3d9v59h2hak283f2z redis]# make
cd src && make all
make[1]: Entering directory `/usr/local/redis/src'
    CC Makefile.dep
make[1]: Leaving directory `/usr/local/redis/src'
make[1]: Entering directory `/usr/local/redis/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep dict-benchmark
(cd ../deps && make distclean)
make[2]: Entering directory `/usr/local/redis/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
make[2]: Leaving directory `/usr/local/redis/deps'
(rm -f .make-*)
echo STD=-std=c99 -pedantic -DREDIS_STATIC='' >> .make-settings
echo WARN=-Wall -W -Wno-missing-field-initializers >> .make-settings
echo OPT=-O2 >> .make-settings
echo MALLOC=jemalloc >> .make-settings
echo CFLAGS= >> .make-settings
echo LDFLAGS= >> .make-settings

编译完成后,发现Redis目录下会有对应的src、conf等文件夹

Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory `/usr/local/redis/src'
[root@izbp1g3d9v59h2hak283f2z redis]# ll
total 268
-rw-rw-r--  1 root root 106874 May 16  2019 00-RELEASENOTES
-rw-rw-r--  1 root root     53 May 16  2019 BUGS
-rw-rw-r--  1 root root   2381 May 16  2019 CONTRIBUTING
-rw-rw-r--  1 root root   1487 May 16  2019 COPYING
drwxrwxr-x  6 root root   4096 Dec 30 14:36 deps
-rw-rw-r--  1 root root     11 May 16  2019 INSTALL
-rw-rw-r--  1 root root    151 May 16  2019 Makefile
-rw-rw-r--  1 root root   6888 May 16  2019 MANIFESTO
-rw-rw-r--  1 root root  20555 May 16  2019 README.md
-rw-rw-r--  1 root root  61797 May 16  2019 redis.conf
-rwxrwxr-x  1 root root    275 May 16  2019 runtest
-rwxrwxr-x  1 root root    280 May 16  2019 runtest-cluster
-rwxrwxr-x  1 root root    341 May 16  2019 runtest-moduleapi
-rwxrwxr-x  1 root root    281 May 16  2019 runtest-sentinel
-rw-rw-r--  1 root root   9710 May 16  2019 sentinel.conf
drwxrwxr-x  3 root root   4096 Dec 30 14:37 src
drwxrwxr-x 11 root root   4096 May 16  2019 tests
drwxrwxr-x  8 root root   4096 May 16  2019 utils

5、安装 

进入src目录,执行 make install 命令

[root@izbp1g3d9v59h2hak283f2z redis]# cd src
[root@izbp1g3d9v59h2hak283f2z src]# make install
    CC Makefile.dep

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
[root@izbp1g3d9v59h2hak283f2z src]# ll

至此,Linux服务器上已成功安装Redis

6、部署

为了方便管理,将Redis文件中的conf配置文件和常用命令移动到统一文件中

1)、创建bin和etc文件

[root@izbp1g3d9v59h2hak283f2z redis]# mkdir etc
[root@izbp1g3d9v59h2hak283f2z redis]# mkdir bin
[root@izbp1g3d9v59h2hak283f2z redis]# ll
total 276
-rw-rw-r--  1 root root 106874 May 16  2019 00-RELEASENOTES
drwxr-xr-x  2 root root   4096 Dec 30 14:41 bin
-rw-rw-r--  1 root root     53 May 16  2019 BUGS
-rw-rw-r--  1 root root   2381 May 16  2019 CONTRIBUTING
-rw-rw-r--  1 root root   1487 May 16  2019 COPYING
drwxrwxr-x  6 root root   4096 Dec 30 14:36 deps
drwxr-xr-x  2 root root   4096 Dec 30 14:41 etc
-rw-rw-r--  1 root root     11 May 16  2019 INSTALL
-rw-rw-r--  1 root root    151 May 16  2019 Makefile
-rw-rw-r--  1 root root   6888 May 16  2019 MANIFESTO
-rw-rw-r--  1 root root  20555 May 16  2019 README.md
-rw-rw-r--  1 root root  61797 May 16  2019 redis.conf
-rwxrwxr-x  1 root root    275 May 16  2019 runtest
-rwxrwxr-x  1 root root    280 May 16  2019 runtest-cluster
-rwxrwxr-x  1 root root    341 May 16  2019 runtest-moduleapi
-rwxrwxr-x  1 root root    281 May 16  2019 runtest-sentinel
-rw-rw-r--  1 root root   9710 May 16  2019 sentinel.conf
drwxrwxr-x  3 root root   4096 Dec 30 14:39 src
drwxrwxr-x 11 root root   4096 May 16  2019 tests
drwxrwxr-x  8 root root   4096 May 16  2019 utils

 2)、配置文件及常用命令移动

[root@izbp1g3d9v59h2hak283f2z redis]# mv redis.conf /usr/local/redis/etc/
[root@izbp1g3d9v59h2hak283f2z redis]# cd src
[root@izbp1g3d9v59h2hak283f2z src]# mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server /usr/local/redis/bin/
[root@izbp1g3d9v59h2hak283f2z src]# cd ..
[root@izbp1g3d9v59h2hak283f2z redis]# cd etc/
[root@izbp1g3d9v59h2hak283f2z etc]# ll
total 64
-rw-rw-r-- 1 root root 61797 May 16  2019 redis.conf
[root@izbp1g3d9v59h2hak283f2z etc]# cd ..
[root@izbp1g3d9v59h2hak283f2z redis]# cd bin
[root@izbp1g3d9v59h2hak283f2z bin]# ll
total 32748
-rwxrwxr-x 1 root root     734 May 16  2019 mkreleasehdr.sh
-rwxr-xr-x 1 root root 4365912 Dec 30 14:37 redis-benchmark
-rwxr-xr-x 1 root root 8116448 Dec 30 14:37 redis-check-aof
-rwxr-xr-x 1 root root 8116448 Dec 30 14:37 redis-check-rdb
-rwxr-xr-x 1 root root 4806248 Dec 30 14:37 redis-cli
-rwxr-xr-x 1 root root 8116448 Dec 30 14:37 redis-server

7、启动服务

进入 bin 目录 以 etc 目录下的配置文件作为 Redis 服务的配置文件

[root@izbp1g3d9v59h2hak283f2z bin]# redis-server /usr/local/redis/etc/redis.conf 
20597:C 30 Dec 2019 15:12:25.112 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
20597:C 30 Dec 2019 15:12:25.112 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=20597, just started
20597:C 30 Dec 2019 15:12:25.112 # Configuration loaded
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 20597
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

20597:M 30 Dec 2019 15:12:25.113 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
20597:M 30 Dec 2019 15:12:25.113 # Server initialized
20597:M 30 Dec 2019 15:12:25.113 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
20597:M 30 Dec 2019 15:12:25.113 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
20597:M 30 Dec 2019 15:12:25.113 * DB loaded from disk: 0.000 seconds
20597:M 30 Dec 2019 15:12:25.113 * Ready to accept connections

redis.conf  配置解析 (vim redis.conf)

daemonize:如需要在后台运行,把该项的值改为yes
 
pdifile:把pid文件放在/var/run/redis.pid,可以配置到其他地址
 
bind:指定redis只接收来自该IP的请求,如果不设置,那么将处理所有请求,在生产环节中最好设置该项

            (设置0.0.0.0 则改为用iptables来控制访问权限)
 
port:监听端口,默认为6379
 
timeout:设置客户端连接时的超时时间,单位为秒
 
loglevel:等级分为4级,debug,revbose,notice和warning。生产环境下一般开启notice
 
logfile:配置log文件地址,默认使用标准输出,即打印在命令行终端的端口上
 
database:设置数据库的个数,默认使用的数据库是0
 
save:设置redis进行数据库镜像的频率
 
rdbcompression:在进行镜像备份时,是否进行压缩
 
dbfilename:镜像备份文件的文件名
 
dir:数据库镜像备份的文件放置的路径
 
slaveof:设置该数据库为其他数据库的从数据库
 
masterauth:当主数据库连接需要密码验证时,在这里设定
 
requirepass:设置客户端连接后进行任何其他指定前需要使用的密码
 
maxclients:限制同时连接的客户端数量
 
maxmemory:设置redis能够使用的最大内存
 
appendonly:开启appendonly模式后,redis会把每一次所接收到的写操作都追加到appendonly.aof文件中,当redis重新启动时,会从该文件恢复出之前的状态
 
appendfsync:设置appendonly.aof文件进行同步的频率
 
vm_enabled:是否开启虚拟内存支持
 
vm_swap_file:设置虚拟内存的交换文件的路径
 
vm_max_momery:设置开启虚拟内存后,redis将使用的最大物理内存的大小,默认为0
 
vm_page_size:设置虚拟内存页的大小
 
vm_pages:设置交换文件的总的page数量
 
vm_max_thrrads:设置vm IO同时使用的线程数量

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值