1.Redis overview:
Redis: REmote DIctionary Server, a remote dictionary server, is completely open source and free, written in C language and complies with the BSD protocol. It is a high-performance (key/value) distributed in-memory database that runs based on memory and supports persistence. NoSQL database, is one of the most popular NoSql database, also known as data structure server.
2. Features of Redis:
3. The role of Redis:
4. Getting started with Redis and downloading from the official website:
Official website: https://redis.io/
Chinese Community: http://www.redis.cn/
5. Redis+Linux CentOS 7 service installation:
[1]. Download the Redis installation package from the official website: redis-4.0.6.tar.gz, and upload it to the server using XShell+Xftp tools: [2]. Go to: /usr/local/redis directory, and decompress redis-4.0 .6.tar.gz:
[3] . Enter the decompression directory: /usr/local/redis/redis-4.0.6, execute the make command to install:
[4]. If make is complete and continue to execute make install:
[5]. Understand and view the installation directory of Redis:
[6]. After the installation is complete, check the redis related files, create the redis directory in the etc directory, and back it up to the directory created by redis.conf:
Copy the file using the cp command:
[7]. Go to the /usr/local/etc/redis directory, and edit and modify redis.conf:
This file is very long, but mostly comments, and we focus on a few of the settings daemonize and pidfile:
The default value of daemonize is false, and the default value of pidfile is pidfile /var/run/redis_6379.pid
第一个表示是否daemon化,显然我们要把它改成daemonize yes;
第二个表示当服务以守护进程方式运行时,redis默认会把pid写入/var/run/redis_6379.pid文件,服务运行中该文件就存在,服务一旦停止该文件就自动删除,因而可以用来判断redis是否正在运行,保存后退出。
[8].配置Redis服务自启动:安装配置完成已经拥有基本配置,redis还需要有一个管理启动、关闭、重启的一个脚本。redis源码里其实已经提供了一个初始化脚本,位置在:
/usr/local/redis/redis-4.0.6/utils/utils/redis_init_script
接着将redis_init_script脚本拷贝到/etc/init.d/redisd:
在/etc/init.d下的脚本都是可以在系统启动是自动启动的服务,而现在还缺一个系统启动时的配置,但是服务 redisd 不支持 chkconfig,需求在redisd中配置:
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
输入:service redisd start 检查redis服务是否配置成功:
综上所述,基本安装与配置服务启动完成!
ps:
service redis does not support chkconfig 的解决办法
问题解决办法如下:
必须把下面两行注释放在/etc/init.d/redis文件靠前的注释中(加入以下注释):
1
2
|
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
|
上面的注释的意思是,redis服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,关闭的
优先级是10。
linux 运行级别
运行级别就是操作系统当前正在运行的功能级别。这个级别从0到6 ,具有不同的功能。这些级别
在/etc/inittab文件里指定。这个文件是init程序寻找的主要文件,最先运行的服务是那些放
在/etc/rc.d 目录下的文件。
不同的运行级定义如下:(可以参考Linux里面的/etc/inittab)
# 缺省的运行级,RHS用到的级别如下:
0:关机
1:单用户模式
2:无网络支持的多用户模式
3:有网络支持的多用户模式
4:保留,未使用
5:有网络支持有X-Window支持的多用户模式
6:重新引导系统,即重启
对各个运行级的详细解释:
0 为停机,机器关闭。
1 为单用户模式,就像Win9x下的安全模式类似。
2 为多用户模式,但是没有NFS支持。
3 为完整的多用户模式,是标准的运行级。
4 一般不用,在一些特殊情况下可以用它来做一些事情。例如在笔记本 电脑的电池用尽时,可以切换到
这个模式来做一些设置。
5 就是X11,进到X Window系统了。
6 为重启,运行init 6机器就会重启。
chkconfig用法
chkconfig命令可以用来检查、设置系统的各种服务
使用语法:
chkconfig [--add][--del][--list][系统服务] 或 chkconfig [--level <等级代号>][系统服务]
[on/off/reset]
参数用法:
--add 增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相
关数据。
--del 删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的叙述文件内删除相关
数据。
--level<等级代号> 指定读系统服务要在哪一个执行等级中开启或关毕。
使用范例:
chkconfig --list 列出所有的系统服务
chkconfig --add redis add redis service
chkconfig --del redis delete redis service
chkconfig --level redis 2345 on puts redis on (open) when the run level is 2, 3, 4, and 5.