1、redis的编译安装
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
yum install -y gcc gcc-c++ make wget
cd /opt
wget https://download.redis.io/releases/redis-5.0.7.tar.gz
tar zxvf redis-5.0.7.tar.gz -C /opt/
cd /opt/redis-5.0.7/
# 编译
make && make -j2 install PREFIX=/usr/local/redis
# PREFIX大写
2、redis的yum安装
(1)安装redis的yum源
yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
(2)安装redis
yum --enablerepo=remi install redis
(3)开机自启redis
systemctl enable redis
3、通过脚本在一台虚拟机开启10个redis实例,端口号为7001-7010
#!/bin/bash
cp -f /opt/redis-5.0.7/redis.conf /usr/local/redis/bin/
cd /usr/local/redis/bin/
sed -i '136s/daemonize no/daemonize yes/' /usr/local/redis/bin/redis.conffor ((k = 7001; k <= 7010; k++)); docp /usr/local/redis/bin/redis.conf /usr/local/redis/bin/redis$k.confsed -i "92s/port 6379/port $k/" /usr/local/redis/bin/redis$k.confsed -i '69s/bind 127.0.0.1/bind 0.0.0.0/' /usr/local/redis/bin/redis$k.conf./redis-server redis$k.conf
done
ps -ef | grep redis
4、安装redis-7.0.x版本
cd /opt
wget https://download.redis.io/releases/redis-7.0.5.tar.gz
tar zxvf redis-7.0.5.tar.gz -C /opt/
cd /opt/redis-7.0.5/
make && make -j2 install PREFIX=/usr/local/redis7
5、练习redis数据库操作指令
redis-cli
#a、切换数据库为10
127.0.0.1:6379> select 10
OK
127.0.0.1:6379[10]>#b、在该数据库中新增key为name value为自己姓名汉语拼音127.0.0.1:6379[10]> set name xcz
OK#c、将name的值改为zhangsan
127.0.0.1:6379[10]> set name zhangsan
OK127.0.0.1:6379[10]> get name
"zhangsan"