redis-basic introduction and linux installation

what is redis

redis is an open source in-memory database, belonging to the NoSQL camp

Supported data types

  • String
  • Hash
  • List
  • Set
  • Sorted set
  • Bitmaps (BitMaps)
  • HyperLogLog
  • GEO geolocation storage

BitMaps Bitmap: Can be used as Bloom filter, which is essentially a string

HyperLogLog: ultra-small memory unique value count, 12kb HyperLogLog, essentially a string

GEO: Geolocation information (latitude and longitude), essentially an ordered collection

Redis features

  • Fast speed : 10w ops (10w read and write per second), data stored in memory , c language implementation, single thread model

  • Feature-rich : publish and subscribe (message) Lua script, transaction (pipeline)

  • Simple : tens of thousands of lines of source code, does not depend on external libraries

  • Master-slave replication : master server and slave server, the master server can be synchronized to the slave server

  • Highly available and distributed :

    Redis-sentinel support high availability after version 2.8

    Support distributed after version 3.0

Because of this, many large companies are using it, such as: github, twitter, stackoverflow, Ali, Baidu, Weibo, Meituan, Sohu

Typical usage scenarios of redis *****

  • Cache system

  • Counters: website visits, reposts, comments

  • Message queue: Publish and subscribe, blocking queue implementation

  • Leaderboard: ordered collection

  • Social networks: Many features match social networks, followers, followers, people nearby

  • Real-time system: spam processing system, bloom filter

Redis stand-alone installation

Download and install

The following is around the Linux system environment

Later, try to develop on linux or mac, there will be a lot of trouble, such as the process of installing mysql on windows, you will know after experiencing it

After configuring the network mapping on the virtual machine, you can use the graphical management tool on Windows to connect to the redis database.

# 下载(注意 当前目录 不要再桌面上)
# pwd  # 看看当前目录在哪儿
wget http://download.redis.io/releases/redis-5.0.7.tar.gz

# 解压
tar -xzf redis-5.0.7.tar.gz

# 建立软连接(相当于 windows 的环境变量)
ln -s redis-5.0.7 redis

cd redis
# 编译安装(要等一会儿的)
make&&make install

# src 文件夹下的几个与我们相关的文件
ll src
#redis-server--->redis 服务器
#redis-cli---》redis 命令行客户端
#redis-benchmark---》redis 性能测试工具
#redis-check-aof---》aof 文件修复工具
#redis-check-dump---》rdb 文件检查工具
#redis-sentinel---》sentinel服务器,哨兵

# redis 作者对 windows 维护并不太友好,但 window 自己有安装包

Three ways to start

How to turn off redis service?

Source code installation can use this method, find the process id, and then close the process (restart can be stopped and restarted)

[root@localhost 桌面]# ps -ef | grep redis-server | grep 6379
root       8495   3895  0 00:26 pts/0    00:00:00 redis-server *:6379
[root@localhost 桌面]# kill -9 8495
[root@localhost 桌面]# ps -ef | grep redis-server | grep 6379

1. The simplest start

# 最简启动
redis-server

# 另开终端
ps -ef|grep redis  # 查看 redis 进程

2. Dynamic parameter start

cd src

#动态参数启动
redis-server --port 6380 # 启动redis 并指定端口为 6380

3. Configuration file start

# 配置文件启动
# (这个文件位置在哪、叫什么不重要)在 redis 目录下创建 config 目录,copy 一个 redis.conf 文件
cd redis
mkdir config
mkdir /root/data
cd config

vi redis.conf
'''写入如下内容(可自定义配置)

# 以守护进程模式启动(后台运行)
daemonize yes
# 这里开的端口要开通(可能云服务器默认开启的端口不包含这个)
port 6379
# 开放外部访问
bind 0.0.0.0
# 关闭保护模式,允许外界访问
protected-mode no
# 工作目录(这个目录也差不多是随意的,要提前创建好)
dir "/root/data"
logfile "6379.log"

'''

cd ..
#启动redis
redis-server config/redis.conf
#查看进程
ps -ef |grep redis-server |grep 6379
#查看日志
cd /root/data
cat 6379.log

Client connection

6379 port episode: These 4 numbers correspond to the phone button MERZ, which is the name of the Italian female singer Alessia Merz (whispering)

### 客户端连接测试 ###
redis-cli -h 127.0.0.1 -p 6379

# redis 命令行中输入 ping 会返回PONG
ping

# 退出 redis 命令行
exit

# 尝试用 windows 中的 redis 桌面管理工具来连接
ifconfig
# 找到 ip,然后用桌面工具建立连接即可

Troubleshoot connection failure

Refer to the blog [ Windows local can not connect to the virtual machine redis service perfect solution ], successfully solved ~

# 连接失败解决
# 先查看 虚拟机的 6379 端口是否打开,下面命令如果返回 no 则说明虚拟机的端口未打开
firewall-cmd --query-port=6379/tcp
# 打开 6379 端口(--permanent 参数让这条命令永久生效)
firewall-cmd --add-port=6379 --permanent
# 再次连接测试

# 若还是连接不上,请测试虚拟机与 windows 主机是否相通(在windows 命令行中)
ping ....虚拟机下 ifconfig 查到的 ip....
# 未通再检查虚拟机的网络连接

# 若端口开放了,也能 ping 通,那么检查一下虚拟机的防火墙
systemctl status iptables
# 发现我的虚拟机上 firewalld 防火墙开着,那么把它关掉(正式服务器上不建议这么做)
systemctl status firewalld
chkconfig firewalld off
# 再次尝试桌面工具连接,成功!

Guess you like

Origin www.cnblogs.com/suwanbin/p/12698472.html