吃透Redis系列(一):Linux下Redis安装

Redis系列文章:

吃透Redis系列(一):Linux下Redis安装

吃透Redis系列(二):Redis六大数据类型详细用法

吃透Redis系列(三):Redis管道,发布/订阅,事物,过期时间 详细介绍

吃透Redis系列(四):布隆(bloom)过滤器详细介绍

吃透Redis系列(五):RDB和AOF持久化详细介绍

吃透Redis系列(六):主从复制详细介绍

吃透Redis系列(七):哨兵机制详细介绍

吃透Redis系列(八):集群详细介绍

吃透Redis系列(九):Redis代理twemproxy和predixy详细介绍

吃透Redis系列(十):Redis内存模型详细介绍

吃透Redis系列(十一):Jedis和Lettuce客户端详细介绍

Linux下包管理工具认识

一般来说著名的linux系统基本上分两大类:

  1. RedHat系列:Redhat、Centos、Fedora等
  2. Debian系列:Debian、Ubuntu等

RedHat 系列 -包管理工具 yum

Debian系列-包管理工具 apt-get

安装wget

wget是一个下载文件的工具,我们用来从网络上下载东西:

sudo apt-get install wget

下载redis安装包

// 新建存放下载文件的目录
mkdir soft
// 切换到此目录下面
cd soft
// 用wget来下载安装包
wget http://download.redis.io/releases/redis-6.0.6.tar.gz

解压安装包

tar xf redis-6.0.6.tar.gz

执行make文件

// 切换到redis包下
cd redis-6.0.6
// 执行make文件
make

如果报错的话,证明没有gcc环境,需要先安装gcc,然后再执行make distclean把刚才安装的错误文件清除一下然后再执行make

sudo apt-get install gcc
make distclean
make

然后执行make成功之后,我们切换到src下面,可以看到生成了可执行文件

安装

安装到opt/redis目录

sudo make install PREFIX=/opt/redis

配置环境变量

sudo gedit /etc/profile

打开profile文件,然后添加如下内容:

export REDIS_HOME=/opt/redis
export PATH=$PATH:$REDIS_HOME/bin

然后刷新环境变量

source /etc/profile

执行install_server.sh脚本

cd /soft/redis-6.0.6/utils
sudo ./install_server.sh

运行脚本可能会出现如下错误:

This systems seems to use systemd.
Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!

打开install_server.sh注释掉如下内容:

#_pid_1_exe="$(readlink -f /proc/1/exe)"
#if [ "${_pid_1_exe##*/}" = systemd ]
#then
#	echo "This systems seems to use systemd."
#	echo "Please take a look at the provided example service unit files in this #directory, and adapt and install them. Sorry!"
#	exit 1
#fi
#unset _pid_1_exe

然后再次执行

sudo ./install_server.sh

输出

Please select the redis port for this instance: [6379] 

一个物理机中可以有多个redis实例(进程),通过port区分,然后下面会显示出让你配置端口,默认端口为:6379,如果用默认端口的话,直接按Enter执行下一步

Please select the redis config file name [/etc/redis/6379.conf] 

生成此Redis实例的配置文件存放于/etc/redis/6379.conf

然后我们继续按Enter就行

Please select the redis log file name [/var/log/redis_6379.log]

生成此Reids运行的log日志文件存放于/var/log/redis_6379.log

继续按Enter

Please select the data directory for this instance [/var/lib/redis/6379] 

存放数据的文件/var/lib/redis/6379

继续Enter

Please select the redis executable path []

需要输入redis-server的路径,我们把上面配置的路径输入:

Please select the redis executable path [] /opt/redis/bin/redis-server

继续按Enter

Selected config:
Port           : 6381
Config file    : /etc/redis/6381.conf
Log file       : /var/log/redis_6381.log
Data dir       : /var/lib/redis/6381
Executable     : /opt/redis/bin/redis-server
Cli Executable : /opt/redis/bin/redis-cli

提示出来我们上面选择的配置,继续按Enter

Copied /tmp/6381.conf => /etc/init.d/redis_6381
Installing service...
Success!
Starting Redis server...
Installation successful!

提示我们安装成功,并帮我启动了redis server

查看redis server运行状态

上面我们已经安装成功,并自动启动了redis server,接下来我们输入

service redis_6379 status

命令来查看运行状态:

在这里插入图片描述

启动或停止redis实例

service redis_6379 start
service redis_6379 stop

多实例安装

一个物理机中可以有多个redis实例,通过port区分。

我们只需要重复执行上面的install_server.sh脚本来安装多个redis实例即可。

我这边又安装了redis 6380 6381实例,并且都启动,我们可以通过以下命令查看当前正在运行的redis实例:

ps -fe | grep redis

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/u013277209/article/details/111669419