NoSQL database case combat--Redis environment deployment


This environment is based on the Centos 7.8 system to build a Redis learning environment.
Install Redis-6.0.9


1. Environmental preparation

Hardware environment

Operating system: centos-7.8 cpu: 1*1 hard disk: 20G memory: 2G

Software preparation

# 操作系统--mini安装
[root@wan ~]# cat /etc/redhat-release 
CentOS Linux release 7.8.2003 (Core)
# 禁用防火墙
[root@wan ~]# systemctl stop firewalld
[root@wan ~]# systemctl disable firewalld
# 禁用selinux
[root@wan ~]# vim /etc/selinux/config
SELINUX=disable
# 设置 DNS 服务器
[root@wan ~]# vim /etc/resolv.conf 
# Generated by NetworkManager
nameserver 223.5.5.5
nameserver 114.114.114.114
nameserver 8.8.8.8
# 安装 所需软件
[root@wan ~]# yum install wget bash-completion lrzsz tree zip unzip psmisc net-tools -y
# 配置扩展源
[root@wan ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

Two, rpm installation

# 安装 redis
[root@wan ~]# yum install http://rpmfind.net/linux/remi/enterprise/7/remi/x86_64/redis-6.0.9-2.el7.remi.x86_64.rpm -
# 查看redis安装情况
[root@wan ~]# rpm -qa | grep redis
redis-6.0.9-2.el7.remi.x86_64
# 启动redis服务
[root@wan ~]# systemctl enable --now redis
[root@wan ~]# systemctl is-active redis
active
[root@wan ~]# systemctl is-enabled redis
enable
# 查看redis服务进程信息
[root@wan ~]# netstat -lnutp | grep redis
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      9924/redis-server 1

# 登录数据库
[root@wan ~]# redis-cli 
127.0.0.1:6379> help
redis-cli 6.0.9
To get help about Redis commands type:
      "help @<group>" to get a list of commands in <group>
      "help <command>" for help on <command>
      "help <tab>" to get a list of possible help topics
      "quit" to exit

To set redis-cli preferences:
      ":set hints" enable online hints
      ":set nohints" disable online hints
Set your preferences in ~/.redisclirc
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> exit

Three, source installation

# 下载redis源码包
[root@node01 redis-6.0.9]# wget -c http://download.redis.io/releases/redis-6.0.9.tar.gz
# 解压到指定目录
[root@node01 redis-6.0.9]# tar xf  redis-6.0.9.tar.gz -C /usr/local/src/ 
[root@node01 redis-6.0.9]# cd /usr/local/src/redis-6.0.9/
[root@node01 redis-6.0.9]# ll
total 288
-rw-rw-r--.  1 root root 108806 Oct 27 15:12 00-RELEASENOTES
-rw-rw-r--.  1 root root     51 Oct 27 15:12 BUGS
-rw-rw-r--.  1 root root   2499 Oct 27 15:12 CONTRIBUTING
-rw-rw-r--.  1 root root   1487 Oct 27 15:12 COPYING
drwxrwxr-x.  6 root root    124 Oct 27 15:12 deps
-rw-rw-r--.  1 root root     11 Oct 27 15:12 INSTALL
-rw-rw-r--.  1 root root    151 Oct 27 15:12 Makefile
-rw-rw-r--.  1 root root   6888 Oct 27 15:12 MANIFESTO
-rw-rw-r--.  1 root root  21099 Oct 27 15:12 README.md
-rw-rw-r--.  1 root root  84841 Oct 27 15:12 redis.conf
-rwxrwxr-x.  1 root root    275 Oct 27 15:12 runtest
-rwxrwxr-x.  1 root root    280 Oct 27 15:12 runtest-cluster
-rwxrwxr-x.  1 root root    795 Oct 27 15:12 runtest-moduleapi
-rwxrwxr-x.  1 root root    281 Oct 27 15:12 runtest-sentinel
-rw-rw-r--.  1 root root  10744 Oct 27 15:12 sentinel.conf
drwxrwxr-x.  3 root root   4096 Oct 27 15:12 src
drwxrwxr-x. 11 root root    182 Oct 27 15:12 tests
-rw-rw-r--.  1 root root   3055 Oct 27 15:12 TLS.md
drwxrwxr-x.  9 root root   4096 Oct 27 15:12 utils

# 安装源码安装、编译所需工具
[root@wan ~]# [root@node01 redis-6.0.9]# yum install gcc gcc-c++ make -y
# 下载源码包
下载链接:http://download.redis.io/releases/
[root@wan ~]# wget -c http://download.redis.io/releases/redis-5.0.9.tar.gz
# 解压
[root@wan ~]# tar xf redis-5.0.9.tar.gz -C /usr/local/src/
# 编译
[root@wan redis-5.0.9]# cd /usr/local/src/redis-5.0.9/
[root@wan ~]# make MALLOC=libc
# 安装
[root@wan ~]# make install PREFIX=/usr/local/redis
# 提供配置文件
[root@wan ~]# mkdir /etc/redis
[root@wan ~]# cp /usr/local/src/redis-5.0.9/redis.conf /etc/redis/
# 修改配置文件
[root@wan redis-5.0.9]# vim /etc/redis/redis.conf 
[root@wan redis-5.0.9]# dir /var/lib/redis
# 创建数据目录
[root@wan redis-5.0.9]# mkdir /var/lib/redis
# 创建用户和组
[root@wan redis-5.0.9]# groupadd -r -g 957 redis
[root@wan redis-5.0.9]# useradd -r -u 957 -g 957 -d /var/lib/redis -c 'Redis server' -s /sbin/nologin redis
# 修改权限
[root@wan redis-5.0.9]# chown -R redis /var/lib/redis/
# 配置环境变量
[root@wan redis-5.0.9]# vim /etc/profile.d/redis.sh
export PATH=/usr/local/redis/bin:$PATH
[root@wan redis-5.0.9]# source /etc/profile.d/redis.sh
# 命令行启动
[root@wan redis-5.0.9]# redis-server /etc/redis/redis.conf 
# 配置服务启动脚本
[root@wan redis-5.0.9]# vim /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis persistent key-value database
After=network.target

[Service]
ExecStart=/usr/local/redis/bin/redis-server /etc/redis/redis.conf --supervised systemd
ExecStop=/usr/bin/kill `pidof redis-server`
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target

# 启动redis服务
[root@wan redis-5.0.9]# systemctl enable --now redis
[root@wan redis-5.0.9]# systemctl is-active redis
active
[root@wan redis-5.0.9]# systemctl is-enabled redis
enabled

# 登录数据库
[root@wan redis-5.0.9]# redis-cli 
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> exit

Guess you like

Origin blog.csdn.net/XY0918ZWQ/article/details/112344555