x86麒麟系统源码安装Redis集群
一、介绍
1.1 Redis 与 MySQL 的对比及 Redis 在企业级应用中的角色
1.1.2 关系型数据库与非关系型数据库
关系型数据库(MySQL)
- 形式:类似于Excel表格,有行有列,由行和列组成的数据结构。
- 特点:包含表的概念,使用结构化查询语言(SQL)进行操作。
非关系型数据库(Redis)
- 形式:无表的概念,所有数据以键值对(Key:Value)的形式存储。
- 特点:非结构化查询语言(NoSQL),数据以key:value格式存储,用冒号分割。
1.2 Redis 的数据结构及特点
1.2.1 数据结构
- 键值对(K/V):简单且直接,通过确定键的名字来查找对应的值。
1.2.2 特点
- 内存数据库:一旦启动,所有数据一次性加载到内存,提高读写性能。
- 内存限制:由于数据存储在内存中,因此内存量有限,如物理机只有16G内存,Redis存储数据不能超过此限制。
- 数据丢失风险:内存数据在断电时会丢失,因此存在数据丢失的风险。
1.3 Redis 在企业级应用中的角色
1. 缓存服务器
- 常常作为MySQL的缓存服务器,将MySQL的数据以key:value的方式缓存到Redis中,提高MySQL的读写性能。
2. 存储
- Redis本身也可以作为存储使用,存储一些需要快速访问的数据。
3. 消息队列(MQ)
- Redis还可以作为消息队列使用,处理消息传递和队列管理。
1.4 Redis 的持久化
- 由于Redis是内存数据库,数据在断电时会丢失,因此需要进行持久化。
- 持久化是将内存中的数据保存到磁盘上,以确保数据在断电后不丢失。
1.5 Redis 与 MySQL 对比
- 关系型数据库(MySQL)
- 表格形式,有行有列。
- 包含表的概念,使用SQL操作。
- 非关系型数据库(Redis)
- 无表概念,数据以键值对形式存储。
- 使用非结构化查询语言(NoSQL)。
1.6 Redis 特点
- 数据结构简单,以键值对形式存储。
- 内存数据库,所有数据加载到内存,提高性能。
- 内存有限制,需考虑物理机内存大小。
- 数据在断电时丢失,存在数据丢失风险。
1.7 Redis 在企业级应用中的角色
- 缓存服务器:提高MySQL读写性能。
- 存储:存储需要快速访问的数据。
- 消息队列(MQ):处理消息传递和队列管理。
1.7 Redis 持久化
- 由于数据存储在内存中,需要进行持久化以确保数据不丢失。
二、部署单节点
2.1 安装redis
下载地址:https://download.redis.io/releases/
2.1.1 下载
[root@redis111 data]# wget https://download.redis.io/releases/redis-3.0.5.tar.gz
[root@redis111 data]# tar xf redis-3.0.5.tar.gz
2.1.2 编译安装
[root@redis111 data]# cd redis-3.0.5/
[root@redis111 redis-3.0.5]# make PREFIX=/data/redis install
2.2 命令介绍
[root@redis111 redis-3.0.5]# ll /data/redis/bin/
total 9112
-rwxr-xr-x 1 root root 2258912 Dec 19 10:35 redis-benchmark
-rwxr-xr-x 1 root root 28864 Dec 19 10:35 redis-check-aof
-rwxr-xr-x 1 root root 60416 Dec 19 10:35 redis-check-dump
-rwxr-xr-x 1 root root 2377184 Dec 19 10:35 redis-cli
lrwxrwxrwx 1 root root 12 Dec 19 10:35 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 4594968 Dec 19 10:35 redis-server
# redis-cli* 是 客户端启动的命令
# redis-sentinel -> redis-server* 是哨兵的启动命令
# redis-server* 是单机和集群的启动命令
2.3 创建目录
只有启动命令 是不可以的 我们未来所需要 存储 redis 所生成的数据 ,所以需要一个数据目录
[root@redis111 data]# mkdir /data/redis/{data,etc,logs,run}
#需要的目录 自己创建
#需要存储redis 的数据 建一个data
#需要配置文件 etc 也可以叫conf 这个无所谓
#生成日志目录log
#未来运行所需要的pid文件目录 run
2.4 编辑配置文件
默认没有配置文件 我们需要给他提供一个配置文件,配置文件 在刚才下载的源码包里 有个配置文件
#源码包里面的redis.conf
#给他 复制到 /data/redis/etc/
[root@redis111 redis]# cp /data/redis-3.0.5/redis.conf /data/redis/etc/
[root@redis111 redis]# vim /data/redis/etc/redis.conf
#修改下面参数
bind 127.0.0.1 192.168.1.111
#这里是添加本机ip
daemonize yes
#改为后台启动
pidfile /data/redis/run/redis_6379.pid
#修改pid文件目录
logfile "/data/redis/logs/redis-6379.log"
#日志文件目录
dbfilename dump-6379.rdb
#自动化的存储 给他改个名
dir /data/redis/data
#指定一个目录
requirepass 123456
#redis 密码
最终效果
[root@redis111 redis]# egrep -v "^$|^#" /data/redis/etc/redis.conf
daemonize yes
pidfile /data/redis/run/redis_6379.pid
port 6379
tcp-backlog 511
bind 127.0.0.1 192.168.1.111
timeout 0
tcp-keepalive 0
loglevel notice
logfile "/data/redis/logs/redis-6379.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump-6379.rdb
dir /data/redis/data
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
requirepass 123456
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
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-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
2.5 启动redis
2.5.1 启动前配置
[root@redis111 redis]# vim /etc/sysctl.conf
#添加下面两条内容
net.core.somaxconn = 512
vm.overcommit_memory = 1
[root@redis111 redis]# sysctl -p
#立即生效
echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@redis111 redis]# vim /etc/rc.local
#加入下面这条
echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@redis111 redis]# chmod +x /etc/rc.local
#赋权
[root@redis111 redis]# systemctl start rc-local.service
#启动
#把 /data/redis/bin 加到 $PATH 变量里面
[root@redis111 ~]# vim /etc/profile
export PATH=/apps/redis/bin:$PATH
[root@redis111 ~]# source /etc/profile
2.5.2 单机启动测试
[root@redis111 redis]# /data/redis/bin/redis-server /data/redis/etc/redis.conf
[root@redis111 redis]# ss -tnl | grep 6379
LISTEN 0 511 192.168.1.111:6379 0.0.0.0:*
LISTEN 0 511 127.0.0.1:6379 0.0.0.0:*
#登录
#直接输入密码方式
[root@redis111 redis]# /data/redis/bin/redis-cli -h 192.168.1.111 -p 6379 -a 123456
192.168.1.111:6379> set k1 v1
OK
192.168.1.111:6379> get k1
"v1"
#进入命令行输入密码方式
[root@redis111 redis]# /data/redis/bin/redis-cli -h 192.168.1.111 -p 6379
192.168.1.111:6379> auth 123456
OK
192.168.1.111:6379> get k1
"v1"
至此单节点的redis就已经安装完成,可以直接使用