Linux下安装Redis详解
1、下载安装Redis
推荐在官方网站下载:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tkqpOMgn-1617804973561)(/Users/yanlongwu/Library/Application Support/typora-user-images/image-20210328143001926.png)]
1)、下载获得安装包:
这里使用的是Redis5.08:redis-5.0.8.tar.gz
2)、上传安装包到腾讯云服务器
yanlongwu@yanlongdeMBP ~ % scp /Users/yanlongwu/Desktop/自学笔记/Redis/Redis安装包(Linux)/redis-5.0.8.tar.gz root@81.68.114.33:/home/ltwuyanlong
The authenticity of host '81.68.114.33 (81.68.114.33)' can't be established.
ECDSA key fingerprint is SHA256:dZgkoNxUv0FnKwhyxEH4Se3GFnhFCshtYNOf1XX0+OI.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Failed to add the host to the list of known hosts (/Users/yanlongwu/.ssh/known_hosts).
root@81.68.114.33's password:
redis-5.0.8.tar.gz 0% 0 0.0KB/s --:-- ETA
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2aqRKcj9-1617804973562)(/Users/yanlongwu/Library/Application Support/typora-user-images/image-20210328144951023.png)]
文件上传成功!
由于之前我安装过Redis,因此这里先卸载一波:
#查看进程 ps aux |grep redis #杀掉进程 kill -9 进程号 #查看相关文件 find / -name "redis" #删除文件 rm -rf 文件
程序一般建议放在/opt
目录下面。
[root@VM-0-9-centos ltwuyanlong]# ls
apache-tomcat-9.0.44.tar.gz build Dockerfile jdk-8u161-linux-x64.tar.gz readme.txt redis-5.0.8.tar.gz
[root@VM-0-9-centos ltwuyanlong]# pwd
/home/ltwuyanlong
[root@VM-0-9-centos ltwuyanlong]# mv redis-5.0.8.tar.gz /opt
[root@VM-0-9-centos ltwuyanlong]# cd /opt/
[root@VM-0-9-centos opt]# ls
containerd redis-5.0.8.tar.gz rh
[root@VM-0-9-centos opt]# pwd
/opt
[root@VM-0-9-centos opt]#
3)、解压安装包:
[root@VM-0-9-centos opt]# tar -zxvf redis-5.0.8.tar.gz
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WLVTLLN1-1617804973563)(/Users/yanlongwu/Library/Application Support/typora-user-images/image-20210328150549989.png)]
4)、进入Redis之后查看有哪些文件:
[root@VM-0-9-centos redis-5.0.8]# ls -al
总用量 288
drwxrwxr-x 6 root root 4096 3月 12 2020 .
drwxr-xr-x. 5 root root 4096 3月 28 15:04 ..
-rw-rw-r-- 1 root root 118338 3月 12 2020 00-RELEASENOTES
-rw-rw-r-- 1 root root 53 3月 12 2020 BUGS
-rw-rw-r-- 1 root root 2381 3月 12 2020 CONTRIBUTING
-rw-rw-r-- 1 root root 1487 3月 12 2020 COPYING
drwxrwxr-x 6 root root 4096 3月 12 2020 deps
-rw-rw-r-- 1 root root 376 3月 12 2020 .gitignore
-rw-rw-r-- 1 root root 11 3月 12 2020 INSTALL
-rw-rw-r-- 1 root root 151 3月 12 2020 Makefile
-rw-rw-r-- 1 root root 6888 3月 12 2020 MANIFESTO
-rw-rw-r-- 1 root root 20555 3月 12 2020 README.md
-rw-rw-r-- 1 root root 61797 3月 12 2020 redis.conf
-rwxrwxr-x 1 root root 275 3月 12 2020 runtest
-rwxrwxr-x 1 root root 280 3月 12 2020 runtest-cluster
-rwxrwxr-x 1 root root 373 3月 12 2020 runtest-moduleapi
-rwxrwxr-x 1 root root 281 3月 12 2020 runtest-sentinel
-rw-rw-r-- 1 root root 9710 3月 12 2020 sentinel.conf
drwxrwxr-x 3 root root 4096 3月 12 2020 src
drwxrwxr-x 11 root root 4096 3月 12 2020 tests
drwxrwxr-x 8 root root 4096 3月 12 2020 utils
[root@VM-0-9-centos redis-5.0.8]#
5)、基本的环境安装:gcc
[root@VM-0-9-centos redis-5.0.8]# yum install gcc-c++
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
docker-ce-stable | 3.5 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
mysql-connectors-community | 2.6 kB 00:00:00
mysql-tools-community | 2.6 kB 00:00:00
mysql80-community | 2.6 kB 00:00:00
os | 3.6 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/5): epel/7/x86_64/group_gz | 96 kB 00:00:00
(2/5): epel/7/x86_64/updateinfo | 1.0 MB 00:00:00
(3/5): extras/7/x86_64/primary_db | 230 kB 00:00:00
(4/5): epel/7/x86_64/primary_db | 6.9 MB 00:00:00
(5/5): updates/7/x86_64/primary_db | 6.5 MB 00:00:00
软件包 gcc-c++-4.8.5-44.el7.x86_64 已安装并且是最新版本
无须任何处理
[root@VM-0-9-centos redis-5.0.8]#
[root@VM-0-9-centos redis-5.0.8]# gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
目标:x86_64-redhat-linux
配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
线程模型:posix
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
[root@VM-0-9-centos redis-5.0.8]#
6)、make命令执行:
[root@VM-0-9-centos redis-5.0.8]# make
cd src && make all
make[1]: 进入目录“/opt/redis-5.0.8/src”
CC Makefile.dep
make[1]: 离开目录“/opt/redis-5.0.8/src”
make[1]: 进入目录“/opt/redis-5.0.8/src”
Hint: It's a good idea to run 'make test' ;)
make[1]: 离开目录“/opt/redis-5.0.8/src”
[root@VM-0-9-centos redis-5.0.8]#
[root@VM-0-9-centos redis-5.0.8]# make install
cd src && make install
make[1]: 进入目录“/opt/redis-5.0.8/src”
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: 离开目录“/opt/redis-5.0.8/src”
[root@VM-0-9-centos redis-5.0.8]#
7)、Redis的默认安装路径:
/usr
8)、查看redis的版本信息:
进入目录/bin
执行命令:
[root@VM-0-9-centos bin]# redis-cli --version
redis-cli 5.0.8
[root@VM-0-9-centos bin]# pwd
/bin
[root@VM-0-9-centos bin]#
[root@VM-0-9-centos bin]# cd /usr/
[root@VM-0-9-centos usr]# ls
bin etc games include lib lib64 libexec local sbin share src tmp
[root@VM-0-9-centos usr]# cd local/
[root@VM-0-9-centos local]# ls
bin etc games include lib lib64 libexec qcloud sbin share src yd.socket.server
[root@VM-0-9-centos local]# cd bin/
[root@VM-0-9-centos bin]# ls
redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server
[root@VM-0-9-centos bin]#
9)、将Redis配置文件(redis.conf),复制到我们当前目录下:
[root@VM-0-9-centos bin]# ls
redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server
[root@VM-0-9-centos bin]# mkdir wylconfig
[root@VM-0-9-centos bin]# ls
redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server wylconfig
[root@VM-0-9-centos bin]# cp /opt/redis-5.0.8/redis.conf wylconfig/
[root@VM-0-9-centos bin]# ls
redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server wylconfig
[root@VM-0-9-centos bin]# cd wylconfig/
[root@VM-0-9-centos wylconfig]# ls
redis.conf
[root@VM-0-9-centos wylconfig]#
以后我们使用刚刚拷贝出来的配置文件,原生的配置文件不变!达到备份的目的!
10、redis默认不是后台启动的
这时候我们要修改配置文件,/usr/local/bin/wylconfig
redis.conf
# -------------------------------------------------------
# WARNING: DISKLESS REPLICATION IS EXPERIMENTAL CURRENTLY
# -------------------------------------------------------
#
# New replicas and reconnecting replicas that are not able to continue the replication
# process just receiving differences, need to do what is called a "full
# synchronization". An RDB file is transmitted from the master to the replicas.
# The transmission can happen in two different ways:
#
# 1) Disk-backed: The Redis master creates a new process that writes the RDB
# file on disk. Later the file is transferred by the parent
# process to the replicas incrementally.
# 2) Diskless: The Redis master creates a new process that directly writes the
# RDB file to replica sockets, without touching the disk at all.
#
# With disk-backed replication, while the RDB file is generated, more replicas
# can be queued and served with the RDB file as soon as the current child producing
# the RDB file finishes its work. With diskless replication instead once
# the transfer starts, new replicas arriving will be queued and a new transfer
# will start when the current one terminates.
#
# When diskless replication is used, the master waits a configurable amount of
# time (in seconds) before starting the transfer in the hope that multiple replicas
# will arrive and the transfer can be parallelized.
#
# With slow disks and fast (large bandwidth) networks, diskless replication
# works better.
repl-diskless-sync no
# When diskless replication is enabled, it is possible to configure the delay
# the server waits in order to spawn the child that transfers the RDB via socket
# to the replicas.
#
# This is important since once the transfer starts, it is not possible to serve
# new replica