欢迎来到我的博客园

Redis 介绍,安装,启动和停止

Redis数据库软件的介绍及安装

什么是Redis

Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。

Redis 是一个高性能的key-value数据库。 redis的出现,很大程度补偿了memcached这类key/value存储的不足,在部 分场合可以对关系数据库起到很好的补充作用。

和Memcached类似,它支持存储的value类型相对更多,包括string(字符串)、list(链表)、set(集合)、zset(sorted set --有序集合)和hash(哈希类型)。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的。

Redis 软件官网

redis软件我们可以在redis 软件官网上下载: https://redis.io 

中文官网: CRUG网站 (redis.cn)

Redis 在Centos上安装:

我们可以使用两种方式来安装redis:yum和 源码包安装

yum安装Redis

yum install redis -y

Redis 源码包安装

1) 下载源码包

wget https://download.redis.io/redis-stable.tar.gz

  

2)编译redis

tar -xzvf redis-stable.tar.gz
cd redis-stable
make             ###make 成功后此时我们可以在src目录下看到redis-cli和redis-server文件了
make install     ###默认会将redis运行文件安装到/usr/local/bin目录下

  

3)如果想将redis安装到其他目录怎么办??

###第一种办法 修改src/Makefile文件,然后修改PREFIX变量为我们向指定的目录,然后执行make make install
[root@node1 src]# vi Makefile
PREFIX?=/usr/pkgs/redis
###第二种make install的时候指定PREFIS变量
make PREFIX=/usr/local/redis install

redis数据库的启动和停止

redis作为数据库是是由专门的程序来运行并提供服务的,当我们安装好了redis之后,有两个文件 redis-serve和redis-cli文件,redis-server就是我们数据库的服务端程序,提供redis数据库服务。 redis-cli就是客户端程序,用来进行数据库的连接。

Redis数据库的启动

Redis数据库启动有两种方式,前台启动方式和后台启动方式

redis 前台启动方式为:直接允许redis-server程序,但是一单窗框断开,redis不会在继续服务,不建议

[root@node1 bin]# ./redis-server 
16872:C 07 Jul 2022 09:52:55.474 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
16872:C 07 Jul 2022 09:52:55.474 # Redis version=6.2.1, bits=64, commit=00000000, modified=0, pid=16872, just started
16872:C 07 Jul 2022 09:52:55.474 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
16872:M 07 Jul 2022 09:52:55.475 * Increased maximum number of open files to 10032 (it was originally set to 1024).
16872:M 07 Jul 2022 09:52:55.475 * monotonic clock: POSIX clock_gettime
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 6.2.1 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 16872
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

16872:M 07 Jul 2022 09:52:55.476 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
16872:M 07 Jul 2022 09:52:55.476 # Server initialized
16872:M 07 Jul 2022 09:52:55.476 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
16872:M 07 Jul 2022 09:52:55.476 * Ready to accept connections

第二种方式为后台启动方式

 

#拷贝一份 原厂自带的配置文件
[root@node1 bin]# cp /usr/pkgs/install/redis-6.2.1/redis.conf  ./
#对配置文件进行修改,后台运行将daemonize改成yes
[root@node1 bin]# vi redis.conf 
daemonize yes
#然后启动数据库 redis-server /path/to/redis.conf
[root@node1 bin]# ./redis-server redis.conf 

  

数据库停止

第一种方式:redis-cli shutdown

[root@node1 bin]# ps -ef|grep redis
root     16922 10641  0 10:01 pts/2    00:00:00 grep --color=auto redis
[root@node1 bin]# ./redis-server redis.conf 
[root@node1 bin]# ps -ef|grep redis
root     16924     1  0 10:01 ?        00:00:00 ./redis-server 127.0.0.1:6379
root     16930 10641  0 10:01 pts/2    00:00:00 grep --color=auto redis
[root@node1 bin]# ./redis-cli shutdown
[root@node1 bin]# ps -ef|grep redis
root     16933 10641  0 10:01 pts/2    00:00:00 grep --color=auto redis
[root@node1 bin]#

  

第二种方式 redis-cli 然后连接数据库后执行shutdown

[root@node1 bin]# ./redis-server redis.conf 
[root@node1 bin]# ./redis-cli 
127.0.0.1:6379> shutdown
not connected> 

  

第三种方式 kill -9 redis-server  不建议

[root@node1 bin]# ./redis-server redis.conf
[root@node1 bin]# ps -ef|grep 'redis-server'
root     16943     1  0 10:03 ?        00:00:00 ./redis-server 127.0.0.1:6379
root     16949 10641  0 10:03 pts/2    00:00:00 grep --color=auto redis-server
[root@node1 bin]# kill -9 16943
[root@node1 bin]# ps -ef|grep 'redis-server'
root     16951 10641  0 10:04 pts/2    00:00:00 grep --color=auto redis-server
[root@node1 bin]#

  

 

posted @ 2022-07-07 21:26  panzq  阅读(368)  评论(0编辑  收藏  举报