Linux安装单台Redis 6.2


前言

Redis 6.2包括许多新命令和改进功能,但没有重大功能。它主要是使Redis更加完整,并解决许多用户经常或长时间要求的问题。


提示:以下是本篇文章正文内容,下面案例可供参考

一、Redis是什么?

Redis是现在最受欢迎的NoSQL数据库之一,Redis是一个使用ANSI C编写的开源、包含多种数据结构、支持网络、基于内存、可选持久性的键值对存储数据库,其具备如下特性:

基于内存运行,性能高效
支持分布式,理论上可以无限扩展
key-value存储系统
开源的使用ANSI C语言编写、遵守BSD协议、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API
相比于其他数据库类型,Redis具备的特点是:

C/S通讯模型
单进程单线程模型
丰富的数据类型
操作具有原子性
持久化
高并发读写
支持lua脚本

二、安装步骤 第一种

1.安装

安装步骤如下:

cd /usr/local/
wget https://download.redis.io/releases/redis-6.2.1.tar.gz
tar xzf redis-6.2.1.tar.gz
cd redis-6.2.1
make

注意:如果上面执行不成功!则执行下面这句话
注意这里make失败 因为是c语言编写的

yum install gcc
make dist clean
make

查看可执行文件 有了可执行文件

cd src

c
安装全局:使用命令启动redis 随时随地

cd /opt/
mkdir myredis
cd myredis/
mkdir redis6
# /opt/myredis/redis6  这个是我安装的目录
# 回到原来的redis目录
cd /usr/local/redis-6.2.1
make install PREFIX=/opt/myredis/redis6
vi /etc/profile
export REDIS_HOME=/opt/myredis/redis6
export PATH=$PATH:$REDIS_HOME/bin
source /etc/profile

这样就可以用启动命令了!

service redis start
service redis stop

2.使用Install_server.sh(可以执行多次) 第二种安装方式

一个物理机中有多个redis实例进程,通过port区分 可以执行程序就一份在目录,但是内存中未来的多个实例需要各自的配置文件,持久化目录等资源
cd utils

运行脚本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,注释掉下面的内容:

vi 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

接下来准备

mkdir -p /etc/redis/6379
mkdir -p /etc/redis/6378
mkdir -p /etc/redis/6377

[root@localhost utils]# ./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 6379
Please select the redis config file name [/etc/redis/6379.conf] /etc/redis/6379/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] /etc/redis/6379/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] /etc/redis/6379/
Please select the redis executable path [/opt/myredis/redis6/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /etc�/redis/6379/6379.conf
Log file       : /etc/redis/6379/redis_6379.log
Data dir       : /etc/redis/6379/
Executable     : /opt/myredis/redis6/bin/redis-server
Cli Executable : /opt/myredis/redis6/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.

运行脚本后默认会启动redis。

命令

service redis_6379 start
service redis_6379 stop
service redis_6379 status

redis.conf配置
下面来看一下/etc/redis/6379/6379.conf中配置:

开启守护进程模式
daemonize yes

daemonize设置yes或者no区别:

yes:代表开启守护进程模式,redis会在后台运行,并将进程pid号写入至redis.conf选项pidfile设置的文件中。
no:启动将进入redis的命令行界面,exit或者关闭连接工具(putty,xshell等)都会导致redis进程退出。去除bind的ip,注释掉下面这一行,否则无法使用远程连接,只能本地连接redis。

bind 127.0.0.1

关闭保护模式,将protected-mode的yes改为no,也是开启远程连接。
protected-mode no

运行客户端

[root@localhost run]# redis-cli -p 6379
127.0.0.1:6379> set name qjc
OK
127.0.0.1:6379> get name
"qjc"
127.0.0.1:6379> 

猜你喜欢

转载自blog.csdn.net/qq_42731358/article/details/115316933