zhangll00 2020-07-29
1.redis是单线程,高性能的key/value内存数据,基于内存运行并支持持久化的NoSQL数据库
2.redis主要用来做缓存,但不仅仅是做缓存,例如:redis的计数器生成分布式唯一主键,redis实现分布式锁,队列,会话缓存
安装单节点redis
1、安装gcc套装: yum install cpp yum install binutils yum install glibc yum install glibc-kernheaders yum install glibc-common yum install glibc-devel yum install gcc yum install make 2、升级gcc yum -y install centos-release-scl yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils scl enable devtoolset-9 bash 3、设置永久升级: echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile 4、安装redis: wget http://download.redis.io/releases/redis-6.0.3.tar.gz tar xzf redis-6.0.3.tar.gz cd redis-6.0.3 make make PREFIX=/usr/local/redis install 5、修改redis.conf以daemon运行 [ bin]# grep daemon redis.conf daemonize yes 6、启动redis ./redis-server redis.conf ./redis-cli [ bin]# redis-cli 127.0.0.1:6379> ping PONG
安装redis集群
#创建配置文件 [ kconfig]# cat redis6380.conf include /usr/local/bin/kconfig/redis.conf pidfile "/var/run/redis6380.pid" port 6380 dbfilename "dump6380.rdb" cluster-enabled yes cluster-config-file node-6380.conf cluster-node-timeout 15000 #启动6个实例 [ kconfig]# ps -ef|grep redis root 31911 1 0 11:10 ? 00:00:02 redis-server 127.0.0.1:6380 [cluster] root 31938 1 0 11:10 ? 00:00:02 redis-server 127.0.0.1:6381 [cluster] root 31974 1 0 11:10 ? 00:00:02 redis-server 127.0.0.1:6382 [cluster] root 32012 1 0 11:10 ? 00:00:02 redis-server 127.0.0.1:6390 [cluster] root 32050 1 0 11:10 ? 00:00:02 redis-server 127.0.0.1:6391 [cluster] root 32062 1 0 11:11 ? 00:00:02 redis-server 127.0.0.1:6392 [cluster] #创建集群 redis-cli --cluster create 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6390 127.0.0.1:6391 127.0.0.1:6392 --cluster-replicas 1 #查看集群状态 [ kconfig]# redis-cli -c -p 6380 127.0.0.1:6380> cluster nodes 9467d8a87b935deb57875689fccd4a22f5b44209 127.0.0.1: slave e59e4511ef9e2816c1a1fe8c89c17f4f8de5ae53 0 1595778201000 3 connected 43bebe3e0646119264ae865e508dfa5bfcedef36 127.0.0.1: slave 9e90af4a5f76f6d007a3e002285307286d17f5a6 0 1595778203817 1 connected 3926c5da0c5f32a114242ba1a4649d564af960ef 127.0.0.1: slave 353af028076bff70ebb69f9e9fb6cc057a1302e4 0 1595778202000 2 connected e59e4511ef9e2816c1a1fe8c89c17f4f8de5ae53 127.0.0.1: master - 0 1595778202814 3 connected 10923-16383 9e90af4a5f76f6d007a3e002285307286d17f5a6 127.0.0.1: myself,master - 0 1595778203000 1 connected 0-5460 353af028076bff70ebb69f9e9fb6cc057a1302e4 127.0.0.1: master - 0 1595778201000 2 connected 5461-10922