迷,什么都是道理;悟,什么都不是道理。

CentOS   MySQL

导航

Redis

目录

 

使用场景

1 缓存-键过期时间
  --缓存 session
  --优惠券过期时间
  --缓存数据,找不到,再到MySQL查,然后回写redis
2 排行榜
  --热度
  --发布时间
3 计数器
  --浏览次数
4 社交(集合)
  --点赞/推送/标签
5 消息队列-发布订阅
  --配合ELK实现日志收集

 

安装部署(多实例的方式与MySQL基本一致)

[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:04:42 /Server/program-files ] 
# ls
mysql  mysql-8.0.20  mysql-8.0.22  redis-5.0.10  redis-5.0.10.tar.gz

[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:04:44 /Server/program-files ] 
# cd redis-5.0.10/

[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:04:48 /Server/program-files/redis-5.0.10 ] 
# ls
00-RELEASENOTES  CONTRIBUTING  deps     Makefile   README.md   runtest          runtest-moduleapi  sentinel.conf  tests
BUGS             COPYING       INSTALL  MANIFESTO  redis.conf  runtest-cluster  runtest-sentinel   src            utils

# 由于已经有了 Makefile,所以直接 make。 [ root@stock.data.news.
100 pts/0 2021-01-11/31@1 17:04:50 /Server/program-files/redis-5.0.10 ] # make distclean [ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:07:12 /Server/program-files/redis-5.0.10 ] # make && make install

# 编译后,redis的命令会存放在 /usr/local/bin 中
[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:13:05 /Server/program-files/redis-5.0.10 ]
# which redis-{server,cli}            
/usr/local/bin/redis-server
/usr/local/bin/redis-cli

[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:14:04 /Server/program-files/redis-5.0.10 ]
# ls /usr/local/bin/
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server

# 个人的习惯,将命令放入指定的目录,然后重新配置环境变量
[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:16:55 /Server/program-files/redis-5.0.10 ]
# ls
00-RELEASENOTES  CONTRIBUTING  deps     Makefile   README.md   runtest          runtest-moduleapi  sentinel.conf  tests
BUGS             COPYING       INSTALL  MANIFESTO  redis.conf  runtest-cluster  runtest-sentinel   src            utils

[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:17:53 /Server/program-files/redis-5.0.10 ]
# mkdir bin

[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:17:57 /Server/program-files/redis-5.0.10 ]
# mv /usr/local/bin/* ./bin

[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:18:09 /Server/program-files/redis-5.0.10 ]
# ls ./bin
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server

[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:18:15 /Server/program-files/redis-5.0.10 ]
# ls /usr/local/bin/

# 创建环境变量
[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:21:04 /Server/program-files/redis-5.0.10 ]
# cd ..

[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:21:08 /Server/program-files ]
# ll
total 1948
lrwxrwxrwx  1 root root      14 Jan  2 15:09 mysql -> ./mysql-8.0.22
drwxr-xr-x  9 root root     129 Jan  2 14:50 mysql-8.0.20
drwxr-xr-x. 9 root root     149 Jan  2 14:44 mysql-8.0.22
drwxrwxr-x  7 root root    4096 Jan 11 17:17 redis-5.0.10
-rw-r--r--  1 root root 1990507 Jan 11 16:32 redis-5.0.10.tar.gz

[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:21:10 /Server/program-files ]
# ln -s ./redis-5.0.10 redis

[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:21:24 /Server/program-files ]
# ll
total 1948
lrwxrwxrwx  1 root root      14 Jan  2 15:09 mysql -> ./mysql-8.0.22
drwxr-xr-x  9 root root     129 Jan  2 14:50 mysql-8.0.20
drwxr-xr-x. 9 root root     149 Jan  2 14:44 mysql-8.0.22
lrwxrwxrwx  1 root root      18 Jan 11 17:21 redis -> ./redis-5.0.10
drwxrwxr-x  7 root root    4096 Jan 11 17:17 redis-5.0.10
-rw-r--r--  1 root root 1990507 Jan 11 16:32 redis-5.0.10.tar.gz

[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:24:32 /Server/program-files ]
# tail -n 16 /etc/profile

# common var
export ROOT_PATH='/Server/program-files'
export BIN_DIR='bin'

# MySQL var
export MYSQL_HOME=${ROOT_PATH}/mysql/${BIN_DIR}
export MYSQL_SHELL=${ROOT_PATH}/mysql_shell/${BIN_DIR}
export MYSQL_ROUTER=${ROOT_PATH}/mysql_router/${BIN_DIR}
export PATH=${MYSQL_HOME}:${MYSQL_SHELL}:${MYSQL_ROUTER}:$PATH
export MYSQL_PS1='\u@\h@\p[\d] \r:\m:\s >'

# Redis var
export Redis_HOME=${ROOT_PATH}/redis/${BIN_DIR}
export PATH=${Redis_HOME}:$PATH

# 检查环境变量,退出会话,再重新登录
[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:25:09 ~ ]
# which redis-cli
/Server/program-files/redis/bin/redis-cli

# 初始配置
[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:33:46 /Server/program-files ]
# ls
mysql  mysql-8.0.20  mysql-8.0.22  redis  redis-5.0.10  redis-5.0.10.tar.gz

[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:33:47 /Server/program-files ]
# cd redis

[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:33:50 /Server/program-files/redis ]
# ls
00-RELEASENOTES  BUGS          COPYING  INSTALL   MANIFESTO  redis.conf  runtest-cluster    runtest-sentinel  src    utils
bin              CONTRIBUTING  deps     Makefile  README.md  runtest     runtest-moduleapi  sentinel.conf     tests

[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:33:53 /Server/program-files/redis ]
# tree /Server -d -L 1
/Server
├── datas
├── logs # Redis 的 log 存放目录
├── program-files
└── runnings # Redis 的 pid 存放目录

# Redis 的配置文件及数据存放目录
[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:34:01 /Server/program-files/redis ]
# ls /Server/datas/  
downloads  mysql-8.0.20-3306  mysql-8.0.22-3306  redis-5.0.10-6379

# Redis 的初始化脚本(install_server.sh ),目的就是生成最全面的配置文件。
[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:38:03 /Server/program-files/redis ]
# cd ./utils/

[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:39:32 /Server/program-files/redis/utils ]
# ls
build-static-symbols.tcl  create-cluster            hashtable          lru                redis_init_script.tpl  speed-regression.tcl
cluster_fail_time.tcl     generate-command-help.rb  hyperloglog        redis-copy.rb      redis-sha1.rb          whatisdoing.sh
corrupt_rdb.c             graphs                    install_server.sh  redis_init_script  releasetools

[ root@stock.data.news.100 pts/0 2021-01-11/31@1 17:39:33 /Server/program-files/redis/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]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] /Server/datas/redis-5.0.10-6379/6379.conf   
Please select the redis log file name [/var/log/redis_6379.log] /Server/logs/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] /Server/datas/redis-5.0.10-6379
Please select the redis executable path [/Server/program-files/redis/bin/redis-server]
Selected config:
Port           : 6379
Config file    : /Server/datas/redis-5.0.10-6379/6379.conf
Log file       : /Server/logs/redis_6379.log
Data dir       : /Server/datas/redis-5.0.10-6379
Executable     : /Server/program-files/redis/bin/redis-server
Cli Executable : /Server/program-files/redis/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

 

posted on 2021-01-13 18:51  3L·BoNuo·Lotus  阅读(90)  评论(0编辑  收藏  举报