Redis 介绍:
分布式内存存储服务器并支持数据的持久化和多样数据的类型。
把网站经常被访问的数据,提前放到内存服务器里。(要可再生的数据,和不宜太大的数可以放内存)
Memcached 是不支持数据的持久化和多样数据的类型
实验环境准备:
[root@host51 ~]# systemctl stop mysqld
[root@host51 ~]# systemctl disable mysqld
[root@host51 ~]# /usr/local/mycat/bin/mycat stop
Stopping Mycat-server...
搭建Redis 数据库服务器
1.装包(可以到官网下载中文网站 www.redis.cn)
[root@host51 ~]# tar -zxf redis-4.0.8.tar.gz
[root@host51 ~]# ls
。。。
redis-4.0.8
。。。
[root@host51 ~]# rpm -q gcc gcc-c++ //因为Redis 是用C语言编写的
未安装软件包 gcc
未安装软件包 gcc-c++
[root@host51 ~]# yum -y install gcc gcc-c++
[root@host51 ~]# cd redis-4.0.8/
[root@host51 redis-4.0.8]# ls
00-RELEASENOTES COPYING Makefile redis.conf runtest-sentinel tests
BUGS deps MANIFESTO runtest sentinel.conf utils
CONTRIBUTING INSTALL README.md runtest-cluster src
[root@host51 redis-4.0.8]# make && make install //初始化安装
[root@host51 redis-4.0.8]# cd utils/
[root@host51 utils]# ls
build-static-symbols.tcl hashtable redis_init_script.tpl
cluster_fail_time.tcl hyperloglog redis-sha1.rb
corrupt_rdb.c install_server.sh releasetools
create-cluster lru speed-regression.tcl
generate-command-help.rb redis-copy.rb whatisdoing.sh
graphs redis_init_script
2.修改配置文件(不编辑,启动的时候就自动改动)
3.启动服务
[root@host51 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
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/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!
//确定配置就回车,要修改就ctrl +c进行修改
4.查看服务信息(默认是安装自己启动)
[root@host51 utils]# netstat -ntlup | grep :6379 //默认的端口号是6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 6575/redis-server 1
[root@host51 utils]# ps -C redis-server
PID TTY TIME CMD
6575 ? 00:00:00 redis-server
5.服务的开启和关闭
[root@host51 utils]# /etc/init.d/redis_6379 status //查看状态
Redis is running (6575)
[root@host51 utils]# /etc/init.d/redis_6379 stop
Stopping ...
Waiting for Redis to shutdown ...
Redis stopped
[root@host51 utils]# ps -C redis-server
PID TTY TIME CMD
[root@host51 utils]# ss -ntulp | grep :6379
[root@host51 utils]# /etc/init.d/redis_6379 start
Starting Redis server...
6.访问服务
[root@host51 utils]# echo $PATH (这个是环境变量)
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@host51 utils]# redis-cli //默认只能本机连接
127.0.0.1:6379>
[root@host51 utils]# redis-cli //退出连接
127.0.0.1:6379> exit
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@host51 utils]# which redis-cli (redis 服务的环境变量)
/usr/local/bin/redis-cli
[root@host51 utils]# scp /usr/local/bin/redis-cli [email protected]:/usr/local/bin/ (将环境变量拷贝到另外一台机上就可以连接服务器)
[root@host50 ~]# which redis-cli
/usr/local/bin/redis-cli
[root@host50 ~]# redis-cli -h192.168.4.51 -p6379 (有了环境变量,需要指明IP和端口)
Unrecognized option or bad number of args for: '-h192.168.4.51'