redis 安装使用与配置

it2023-12-03  91

 Redis是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。从2010年3月15日起,Redis的开发工作由VMware主持。

  如何安装Redis?

  Redis的官方下载站是http://redis.io/download,可以去上面下载最新的安装程序下来,我写此文章时的的稳定版本是2.2.12。

  怎么安装 Redis数据库呢?下面将介绍Linux版本的安装方法:

  步骤一: 下载Redis

  下载安装包:wget http://redis.googlecode.com/files/redis-2.2.12.tar.gz

  [root@localhost 4setup]# wget http: // redis.googlecode.com/files/redis-2.2.12.tar.gz    -- 19 : 06 : 56 -- http: // redis.googlecode.com/files/redis-2.2.12.tar.gz   正在解析主机 redis.googlecode.com... 74.125 . 71.82   Connecting to redis.googlecode.com | 74.125 . 71.82 | : 80 ... 已连接。  已发出 HTTP 请求,正在等待回应... 200 OK  长度: 455240 (445K) [application / x - gzip]  Saving to: `redis - 2.2 . 12 .tar.gz '    100 % [ ==========================================> ] 455 , 240 34 .8K / s in 13s   19 : 07 : 16 ( 34.8 KB / s) - `redis - 2.2 . 12 .tar.gz ' saved [455240/455240]   [root@localhost 4setup]#

  步骤二: 编译源程序

  [root@localhost 4setup]# ll  总计 29168    - rw - r -- r -- 1 root root 455240 2011 - 07 - 22 redis - 2.2 . 12 .tar.gz  [root@localhost 4setup]# tar xzf redis - 2.2 . 12 .tar.gz  [root@localhost 4setup]# cd redis - 2.2 . 12   [root@localhost redis - 2.2 . 12 ]# make  cd src && make all  make[ 1 ]: Entering directory ` / root / 4setup / redis - 2.2 . 12 / src '

  步骤三: 启动Redis服务

  src / redis - server  [root@localhost redis - 2.2 . 12 ]# src / redis - server  [ 6246 ] 05 Aug 19 : 17 : 22 # Warning: no config file specified, using the default config. In order to specify a config file use ' redis-server /path/to/redis.conf'   [ 6246 ] 05 Aug 19 : 17 : 22 * Server started, Redis version 2.2 . 12   [ 6246 ] 05 Aug 19 : 17 : 22 # 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.   [ 6246 ] 05 Aug 19 : 17 : 22 * The server is now ready to accept connections on port 6379   [ 6246 ] 05 Aug 19 : 17 : 22 - 0 clients connected ( 0 slaves), 539544 bytes in use

  Redis 服务端的默认连接端口是 6379。

  步骤四: 将Redis作为 Linux 服务随机启动

  vi /etc/rc.local, 使用vi编辑器打开随机启动配置文件,并在其中加入下面一行代码。

   / root / 4setup / redis - 2.2 . 12 / src / redis - server  

  步骤五: 客户端连接验证

  新打开一个Session输入:src/redis-cli,如果出现下面提示,那么您就可以开始Redis之旅了。

  [root@localhost redis - 2.2 . 12 ]# src / redis - cli  redis 127.0 . 0.1 : 6379 >

  步骤六: 查看Redis日志

  查看服务器端session,即可对Redis的运行状况进行查看或分析了。

  [ 6246 ] 05 Aug 19 : 24 : 33 - 0 clients connected ( 0 slaves), 539544 bytes in use  [ 6246 ] 05 Aug 19 : 24 : 37 - Accepted 127.0 . 0.1 : 51381   [ 6246 ] 05 Aug 19 : 24 : 38 - 1 clients connected ( 0 slaves), 547372 bytes in use

  以上的几个步骤就OK了!!这样一个简单的Redis数据库就可以畅通无阻地运行起来了。

  步骤七: 停止Redis实例

  最简单的方法是在启动实例的session中,直接使用Control-C来将实例停止。

  我们还可以用客户端来停止服务,如可以用shutdown来停止Redis实例, 具体如下:

  [root@localhost redis - 2.2 . 12 ]# src / redis - cli shutdown

转载于:https://www.cnblogs.com/zhibo/archive/2013/03/14/2959033.html

最新回复(0)