简介
NoSQL
为了解决当前互联网的三大问题:
- 1.High performance(高性能);
- 2.Huge Storage(大数据量);
- 3.High Scalability & High Availavbility(高扩展性和高可用性);
Redis
Redis是常用的一种NOSQL数据库,支持的键值数据类型:
- 1.字符串(直接通过key取)
- 2.散列类型(相当于value又是一组键值对)
- 3.列表类型(List)
- 4.集合类型(Set)
- 5.有序集合类型(SortedSet,有权值,好找)
Redis安装
- 1.下载稳定版本Redis(当前4.0.1)
[root@zk download]# wget http://download.redis.io/releases/redis-4.0.1.tar.gz
--2017-08-27 23:49:17-- http://download.redis.io/releases/redis-4.0.1.tar.gz
Resolving download.redis.io... 109.74.203.151
Connecting to download.redis.io|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1711660 (1.6M) [application/x-gzip]
Saving to: “redis-4.0.1.tar.gz”
100%[======================================>] 1,711,660 549K/s in 3.0s
2017-08-27 23:49:21 (549 KB/s) - “redis-4.0.1.tar.gz” saved [1711660/1711660]
- 2.解压缩到/usr/local
[root@zk download]# tar -xvf redis-4.0.1.tar.gz -C /usr/local/
[root@zk local]# cd redis-4.0.1/
- 3.安装gcc环境
[root@zk redis-4.0.1]# yum install gcc-c++
Loaded plugins: fastestmirror, security
...
...
Total download size: 22 M
Is this ok [y/N]: y
Downloading Packages:
...
...
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>
Package: centos-release-6-6.el6.centos.12.2.x86_64 (@anaconda-CentOS-201410241409.x86_64/6.6)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Is this ok [y/N]: y
...
...
Complete!
- 4.编译Redis
这里直接make会出问题如下:("Newer version of jemalloc required")
[root@zk redis-4.0.1]# make
cd src && make all
make[1]: Entering directory `/usr/local/redis-4.0.1/src'
CC adlist.o
In file included from adlist.c:34:
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/usr/local/redis-4.0.1/src'
make: *** [all] Error 2
StackOverFlow上面有解决的方法:
https://stackoverflow.com/questions/37103054/redis-installation-fails-when-running-make-command
其实README里面也有写,貌似make MALLOC=libc 也能解决问题。
[root@zk redis-4.0.1]# make distclean
...
...
[root@zk redis-4.0.1]# make
- 5.安装Redis,复制配置文件
[root@zk redis-4.0.1]# make PREFIX=/usr/local/redis install
cd src && make install
make[1]: Entering directory `/usr/local/redis-4.0.1/src'
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: Leaving directory `/usr/local/redis-4.0.1/src'
[root@zk bin]# cd ../../redis-4.0.1/
[root@zk redi-4.0.1]# cp redis.conf ../redis/bin/
[root@zk redis-4.0.1]# cd -
/usr/local/redis/bin
6.修改配置文件
将"daemonize"从no改为yes7.带参数启动redis(后端启动)
[root@zk bin]# ./redis-server redis.conf
12545:C 28 Aug 02:57:00.871 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
12545:C 28 Aug 02:57:00.871 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=12545, just started
12545:C 28 Aug 02:57:00.871 # Configuration loaded
8.关闭redis服务
方法1:
注意:直接通过kill -9 pid进行关闭
1.ps -ef | grep redis查询pid
2.kill -9 pid
方法2:
直接通过./redis-cli shutdown 进行关闭9.开放端口
[root@zk bin]# /sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT
[root@zk bin]# /etc/rc.d/init.d/iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]