首页
About Me
推荐
weibo
github
Search
1
linuxea:gitlab-ci之docker镜像质量品质报告
49,197 阅读
2
linuxea:如何复现查看docker run参数命令
21,468 阅读
3
Graylog收集文件日志实例
18,257 阅读
4
git+jenkins发布和回滚示例
17,882 阅读
5
linuxea:jenkins+pipeline+gitlab+ansible快速安装配置(1)
17,778 阅读
ops
Openvpn
Sys Basics
rsync
Mail
NFS
Other
Network
HeartBeat
server 08
Code
Awk
Shell
Python
Golang
virtualization
KVM
Docker
openstack
Xen
kubernetes
kubernetes-cni
Service Mesh
Data
Mariadb
PostgreSQL
MongoDB
Redis
MQ
Ceph
TimescaleDB
kafka
surveillance system
zabbix
ELK Stack
Open-Falcon
Prometheus
victoriaMetrics
Web
apache
Tomcat
Nginx
自动化
Puppet
Ansible
saltstack
Proxy
HAproxy
Lvs
varnish
更多
互联咨询
最后的净土
软件交付
持续集成
gitops
devops
登录
Search
标签搜索
kubernetes
docker
zabbix
Golang
mariadb
持续集成工具
白话容器
linux基础
nginx
elk
dockerfile
Gitlab-ci/cd
最后的净土
基础命令
jenkins
docker-compose
gitops
haproxy
saltstack
Istio
marksugar
累计撰写
676
篇文章
累计收到
140
条评论
首页
栏目
ops
Openvpn
Sys Basics
rsync
Mail
NFS
Other
Network
HeartBeat
server 08
Code
Awk
Shell
Python
Golang
virtualization
KVM
Docker
openstack
Xen
kubernetes
kubernetes-cni
Service Mesh
Data
Mariadb
PostgreSQL
MongoDB
Redis
MQ
Ceph
TimescaleDB
kafka
surveillance system
zabbix
ELK Stack
Open-Falcon
Prometheus
victoriaMetrics
Web
apache
Tomcat
Nginx
自动化
Puppet
Ansible
saltstack
Proxy
HAproxy
Lvs
varnish
更多
互联咨询
最后的净土
软件交付
持续集成
gitops
devops
页面
About Me
推荐
weibo
github
搜索到
8
篇与
的结果
2016-02-27
Redis持久化rdb和aof简单介绍
redis消息队列:发布和订阅,以及频道打开一个subscribe127.0.0.1:6379> SUBSCRIBE test Reading messages... (press Ctrl-C to quit) 1) "subscribe" 2) "test" 3) (integer) 1 1) "message" 2) "test" 3) "hello" 1) "message" 2) "test" 3) "word 在另外一个终端输入 PUBLISH test word127.0.0.1:6379> PUBLISH test word (integer) 1 127.0.0.1:6379> 那么这些数据会将在subcribe中打印出,这种方式发送后将不会再发送,如果丢失则会丢失redis支持两种持久化,分别是rdb和aofrdb:指定的时间内快照存放在本地aof: 将所有执行过的命令保存在本地,这种方式更像mysql的binlog在服务器宕机时,如果是快照的方式,数据将会丢失一部分,而aof则损失的较小,并且在后台会进行重写rdb:[root@yum-down ~]# vim /etc/redis/6379.conf save 900 1 save 300 10 save 60 10000 900秒内如果有一个key发送变化则做一次快照,或者在300秒内有10个key发生变化则做一次快照,或者在60秒内,有10000个key做一次快照,禁用删除save即可,另外这里的快照是经过压缩的dbfilename dump_6379.rdb 快照的保存的名词dir /opt/redis 快照保存的位置如下:127.0.0.1:6379> set key 1 OK 127.0.0.1:6379> save OK 127.0.0.1:6379> set key 2 OK 127.0.0.1:6379> save OK 127.0.0.1:6379> [root@yum-down ~]# ll /opt/redis/ total 4 -rw-r--r-- 1 root root 27 Feb 26 04:49 dump_6379.rdb [root@yum-down ~]# ll /opt/redis/ total 4 -rw-r--r-- 1 root root 27 Feb 26 04:50 dump_6379.rdb [root@yum-down ~]# ll /opt/redis/ BGSAVE127.0.0.1:6379> BGSAVE Background saving started 127.0.0.1:6379> [root@yum-down ~]# ll /opt/redis/ total 4 -rw-r--r-- 1 root root 27 Feb 26 04:51 dump_6379.rdb 通常我们备份时AVE不会影响到正常业务,通常我们关机时使用save后再进行。SAVE和BGSAVE它们调用的方式各有不同: SAVE 直接调用 rdbSave ,阻塞 Redis主进程,直到保存完成为止。在主进程阻塞期间,服务器不能处理客户端的任何请求,BGSAVE 则 fork 出一个子进程,子进程负责调用 rdbSave ,并在保存完成之后向主进程发送信号,通知保存已完成。因为 rdbSave 在子进程被调用,所以 Redis 服务器在BGSAVE 执行期间仍然可以继续处理客户端的请求。AOF:[root@yum-down ~]# vim /etc/redis/6379.conf appendonly yes appendfilename "appendonly.aof" AOF在set是通过算法进行数据重写AOF在配置文件中修改后,他的数据也是存放在dir目录中,和rdb一个目录中[root@yum-down redis]# ll /opt/redis/ total 4 -rw-r--r-- 1 root root 0 Feb 26 05:49 appendonly.aof -rw-r--r-- 1 root root 27 Feb 26 05:49 dump_6379.rdb [root@yum-down redis]# [root@yum-down redis]# cat appendonly.aof *2 $6 SELECT $1 0 *3 $3 set $1 1 $1 1 [root@yum-down redis]#
2016年02月27日
3,132 阅读
0 评论
0 点赞
2016-02-26
Redis简单的数据类型
简单的使用:set插入字符串,get查看[root@yum-down ~]# redis-cli -h 10.10.0.250 -p 6379 10.10.0.250:6379> set keyname hello OK 10.10.0.250:6379> get keyname "hello" 10.10.0.250:6379> 过滤:显示所有10.10.0.250:6379> keys * 1) "keya" 2) "keyna" 3) "keyname1" 4) "keyname" 匹配keyname开头10.10.0.250:6379> keys keyname? 1) "keyname2" 2) "keyname1" 10.10.0.250:6379> 判断key是否存在,0不存在,非0则存在,表示数量10.10.0.250:6379> EXISTS keya (integer) 1 10.10.0.250:6379> EXISTS keya1 (integer) 0 10.10.0.250:6379> 删除:0不存在,非0则存在,表示数量10.10.0.250:6379> DEL keya (integer) 1 10.10.0.250:6379> DEL keya (integer) 0 10.10.0.250:6379> info:Keyspacedb0:keys=2,expires=0,avg_ttl=0db0:实例如下:SELECT 1和2两个实例,分别插入数据10.10.0.250:6379[2]> SELECT 1 OK 10.10.0.250:6379[1]> SELECT 2 OK 10.10.0.250:6379[2]> SET 1 1 OK 10.10.0.250:6379[2]> SELECT 1 OK 10.10.0.250:6379[1]> SET 1 1 OK 在使用info查看就有了1和2的实例Keyspacedb0:keys=2,expires=0,avg_ttl=0db1:keys=1,expires=0,avg_ttl=0db2:keys=1,expires=0,avg_ttl=0flushall可清空所有实例10.10.0.250:6379[1]> flushallkeys:key数量expires:过期数量avg_ttl:ttl数量追加:append通常使用set也可以追加127.0.0.1:6379> set 1 hello OK 127.0.0.1:6379> get 1 "hello" set追加 127.0.0.1:6379> set 1 hello,word OK 127.0.0.1:6379> get 1 "hello,word" append追加 127.0.0.1:6379> append 1 w (integer) 11 127.0.0.1:6379> append 1 word (integer) 15 127.0.0.1:6379> get 1 "hello,wordwword" 127.0.0.1:6379> 单个数据追加:INCR127.0.0.1:6379> incr new (integer) 1 127.0.0.1:6379> incr new (integer) 2 127.0.0.1:6379> incr new (integer) 3 127.0.0.1:6379> incr new (integer) 4 127.0.0.1:6379> incr new (integer) 5 127.0.0.1:6379> get new "5" 127.0.0.1:6379> 追加多个:INCRBY127.0.0.1:6379> get new "5" 127.0.0.1:6379> incrby new 100 (integer) 105 127.0.0.1:6379> get new "105" 127.0.0.1:6379> 减少:DECR127.0.0.1:6379> get new "105" 127.0.0.1:6379> DECR new (integer) 104 127.0.0.1:6379> DECR new (integer) 103 127.0.0.1:6379> DECR new (integer) 102 127.0.0.1:6379> DECR new (integer) 101 127.0.0.1:6379> DECR new (integer) 100 127.0.0.1:6379> get new "100" 127.0.0.1:6379> 浮点:INCRBYELOAT127.0.0.1:6379> INCRBYFLOAT key 0.1 "0.2" 127.0.0.1:6379> INCRBYFLOAT key 0.1 "0.3" 127.0.0.1:6379> INCRBYFLOAT key 0.1 "0.4" 127.0.0.1:6379> INCRBYFLOAT key 0.1 "0.5" 127.0.0.1:6379> INCRBYFLOAT key 0.1 "0.6" 127.0.0.1:6379> INCRBYFLOAT key 0.1 "0.7" 127.0.0.1:6379> MSET使用:127.0.0.1:6379> mset key 1 key2 2 key3 3 OK 127.0.0.1:6379> get key "1" 127.0.0.1:6379> get key2 "2" 127.0.0.1:6379> get key3 "3" 127.0.0.1:6379> mget key key2 key3 1) "1" 2) "2" 3) "3" 127.0.0.1:6379> 根据UTF-8编码计算key值:127.0.0.1:6379> set key "linuxEA博客" OK 127.0.0.1:6379> get key "linuxEA\xe5\x8d\x9a\xe5\xae\xa2" 127.0.0.1:6379> strlen key (integer) 13 127.0.0.1:6379> ===================散列类型=====================散列类型:HSET 127.0.0.1:6379> HSET xuhao name 1 (integer) 1 127.0.0.1:6379> HSET xuhao co red (integer) 1 127.0.0.1:6379> HSET xuhao price 3 (integer) 1 HGETALL查看所有127.0.0.1:6379> HGETALL xuhao 1) "name" 2) "1" 3) "co" 4) "red" 5) "price" 6) "3" HGET单个查看127.0.0.1:6379> HGET xuhao name "1" 127.0.0.1:6379> HGET xuhao co "red" 127.0.0.1:6379> HGET xuhao price "3" 127.0.0.1:6379> HMSET: 127.0.0.1:6379> HMSET pc name thinkpad co black price 3000 OK 127.0.0.1:6379> HGETALL pc 1) "name" 2) "thinkpad" 3) "co" 4) "black" 5) "price" 6) "3000" 127.0.0.1:6379> HSET pc mode1 "bu huan jia" (integer) 1 127.0.0.1:6379> HGET pc mode1 "bu huan jia" 127.0.0.1:6379> 删除:127.0.0.1:6379> HGET pc mode1 "bu huan jia" 127.0.0.1:6379> HDEL pc mode1 (integer) 1 127.0.0.1:6379> HGETALL mode1 (empty list or set) 判断是否还存在:127.0.0.1:6379> HEXISTS mode1 "bu huan jia" (integer) 0 127.0.0.1:6379> 判断key是否存在:127.0.0.1:6379> EXISTS mode1 (integer) 0 127.0.0.1:6379> ===================列表类型=====================列表类型:[root@yum-down ~]# redis-cli 127.0.0.1:6379> del new (integer) 1 127.0.0.1:6379> LPUSH new 1 (integer) 1 127.0.0.1:6379> LPUSH new 2 (integer) 2 127.0.0.1:6379> LPUSH new 3 (integer) 3 从右边插入127.0.0.1:6379> RPUSH new 4 (integer) 4 127.0.0.1:6379> LLEN new (integer) 4 127.0.0.1:6379> 从左边弹出一个:127.0.0.1:6379> LPOP new "1" 从右边弹出一个:127.0.0.1:6379> RPOP new "4" 127.0.0.1:6379> 弹出两个后查看只剩下2个字符127.0.0.1:6379> LLEN new (integer) 2 127.0.0.1:6379> 某一个范围:LRANGE-1表示从右边的第一个元素127.0.0.1:6379> LRANGE new 1 2 1) "2" 2) "3" 127.0.0.1:6379> LRANGE new 0 -1 -0则是从左边开始查看127.0.0.1:6379> LINDEX new 0 "1" 127.0.0.1:6379> 只保留指定的条目:如:只保留0-4的条目:127.0.0.1:6379> LTRIM new 1 4 OK 查看127.0.0.1:6379> LRANGE new 0 -1 1) "4" 2) "LLEN" 3) "new" 4) "LLEN" 只保留0-3的条目127.0.0.1:6379> LTRIM new 1 3 OK 查看127.0.0.1:6379> LRANGE new 0 -1 1) "LLEN" 2) "new" 3) "LLEN" 127.0.0.1:6379> 例:只看logs的100条数据:127.0.0.1:6379> LPUSH logs newlog (integer) 1 127.0.0.1:6379> LTRIM logs 0 99 OK 127.0.0.1:6379> ===================集合类型====================集合类型:SADD127.0.0.1:6379> SADD jihe a b c (integer) 3 127.0.0.1:6379> SADD jihe2 e f g (integer) 3 127.0.0.1:6379> SMEMBERS jihe 1) "c" 2) "b" 3) "a" 127.0.0.1:6379> SMEMBERS jihe2 1) "e" 2) "g" 3) "f" 127.0.0.1:6379> 判断是否存在:SISMEMBER127.0.0.1:6379> SISMEMBER jihe2 a (integer) 0 127.0.0.1:6379> SISMEMBER jihe2 e (integer) 1 127.0.0.1:6379> 判断差集:SDIFF127.0.0.1:6379> SDIFF jihe jihe2 1) "c" 2) "a" 3) "b" 127.0.0.1:6379> 交集运算: SINTER127.0.0.1:6379> SMEMBERS jihe2 1) "a" 2) "e" 3) "g" 4) "f" 127.0.0.1:6379> SMEMBERS jihe 1) "c" 2) "b" 3) "a" 127.0.0.1:6379> SINTER jihe jihe2 1) "a" 127.0.0.1:6379> 集合:SUNION127.0.0.1:6379> SUNION jihe jihe2 1) "e" 2) "a" 3) "b" 4) "f" 5) "g" 6) "c" 127.0.0.1:6379> 有序集合:127.0.0.1:6379> ZADD jihea 80 a (integer) 1 127.0.0.1:6379> ZADD jihea 81 b (integer) 1 127.0.0.1:6379> ZADD jihea 82 c (integer) 1 127.0.0.1:6379> ZADD jihea 83 d (integer) 1 127.0.0.1:6379> ZADD jihea 84 e (integer) 1 查看127.0.0.1:6379> ZSCORE jihea a "80" 127.0.0.1:6379> ZSCORE jihea b "81" 127.0.0.1:6379> ZSCORE jihea c "82" 127.0.0.1:6379> ZSCORE jihea d "83" 127.0.0.1:6379> 查看所有:127.0.0.1:6379> ZRANGE jihea 0 -1 1) "a" 2) "b" 3) "c" 4) "d" 5) "e" 127.0.0.1:6379>
2016年02月26日
3,173 阅读
0 评论
0 点赞
2016-02-25
Redis编译安装和saltstack简单配置(1)
分布式存储之-Redisredis常用于数据库读缓存和写缓存,通常写缓存需要考虑到数据一致性的问题,读缓存应用较多redis是一个开源的,使用c语言编写的,支持网络交互的,可基于内存也可持久化的key-value数据库目前国内最大的redis集群--新浪微博redis和memcached对比[root@yum-down local]# wget http://download.redis.io/releases/redis-3.0.7.tar.gz [root@yum-down local]# tar xf redis-3.0.7.tar.gz [root@yum-down local]# cd redis-3.0.7 [root@yum-down redis-3.0.7]# make PREFIX=/usr/local/redis install [root@yum-down utils]# cp redis_init_script /etc/init.d/redis [root@yum-down utils]# chmod +x /etc/init.d/redis 修改脚本中的安装路径[root@yum-down utils]# vim /etc/init.d/redis EXEC=/usr/local/redis/bin/redis-server CLIEXEC=/usr/local/redis/bin/redis-cli 创建配置文件路径,并复制配置文件以端口号命名[root@yum-down redis-3.0.7]# mkdir /etc/redis [root@yum-down redis-3.0.7]# cp /usr/local/redis-3.0.7/redis.conf /etc/redis/6379.conf 第一次启动,如果没有修改是启动在前台页面[root@yum-down ~]# /etc/init.d/redis start Starting Redis server... 5228:M 24 Feb 07:16:27.342 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 3.0.7 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 5228 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 5228:M 24 Feb 07:16:27.344 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 5228:M 24 Feb 07:16:27.344 # Server started, Redis version 3.0.7 5228:M 24 Feb 07:16:27.344 # 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. 5228:M 24 Feb 07:16:27.344 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. 5228:M 24 Feb 07:16:27.344 * The server is now ready to accept connections on port 6379 ^C5228:signal-handler (1456327043) Received SIGINT scheduling shutdown... 5228:M 24 Feb 07:17:23.607 # User requested shutdown... 5228:M 24 Feb 07:17:23.607 * Saving the final RDB snapshot before exiting. 5228:M 24 Feb 07:17:23.611 * DB saved on disk 5228:M 24 Feb 07:17:23.611 # Redis is now ready to exit, bye bye...修改配置文件‘daemonize 改为yes’[root@yum-down ~]# vim /etc/redis/6379.conf daemonize yes 修改pid和/etc/init.d/redis中的pid一致pidfile /var/run/redis_6379.pid [root@yum-down ~]# /etc/init.d/redis start Starting Redis server... [root@yum-down ~]# netstat -ntlp |grep redis tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 5235/redis-server tcp 0 0 :::6379 :::* LISTEN 5235/redis-server 关闭测试[root@yum-down ~]# service redis stop Stopping ... Redis stopped [root@yum-down ~]# 做一个软连接启动:[root@yum-down ~]# ln -s /usr/local/redis/bin/redis-cli /usr/local/bin/redis-cli [root@yum-down ~]# redis-cli 127.0.0.1:6379> 由于redis是单线程,只能使用一个cpu,可以启动多个,则可以指定ip和端口[root@yum-down ~]# redis-cli -h 10.10.0.250 -p 6379 10.10.0.250:6379> 简单的使用:set插入字符串,get查看[root@yum-down ~]# redis-cli -h 10.10.0.250 -p 6379 10.10.0.250:6379> set keyname hello OK 10.10.0.250:6379> get keyname "hello" 10.10.0.250:6379> 过滤:显示所有10.10.0.250:6379> keys * 1) "keya" 2) "keyna" 3) "keyname1" 4) "keyname" 匹配keyname开头10.10.0.250:6379> keys keyname? 1) "keyname2" 2) "keyname1" 10.10.0.250:6379> 判断key是否存在,0不存在,非0则存在,表示数量10.10.0.250:6379> EXISTS keya (integer) 1 10.10.0.250:6379> EXISTS keya1 (integer) 0 10.10.0.250:6379> 删除:0不存在,非0则存在,表示数量10.10.0.250:6379> DEL keya (integer) 1 10.10.0.250:6379> DEL keya (integer) 0 10.10.0.250:6379> info:# Keyspace db0:keys=2,expires=0,avg_ttl=0 db0:实例如下:SELECT 1和2两个实例,分别插入数据10.10.0.250:6379[2]> SELECT 1 OK 10.10.0.250:6379[1]> SELECT 2 OK 10.10.0.250:6379[2]> SET 1 1 OK 10.10.0.250:6379[2]> SELECT 1 OK 10.10.0.250:6379[1]> SET 1 1 OK 在使用info查看就有了1和2的实例# Keyspace db0:keys=2,expires=0,avg_ttl=0 db1:keys=1,expires=0,avg_ttl=0 db2:keys=1,expires=0,avg_ttl=0 flushall可清空所有实例10.10.0.250:6379[1]> flushall keys:key数量expires:过期数量avg_ttl:ttl数量简单的配置文件说明:[root@yum-down ~]# egrep -v "^#|^$" /etc/redis/6379.conf daemonize yes 前后台启动 pidfile /var/run/redis.pid pid位置 port 6379 端口 logfile "" 日志 dir ./ 启动的目录 [root@yum-down ~]# redis-saltstack配置1,复制安装包到salt/redis/files/2,复制配置文件到salt/redis/files/3, 复制启动脚本到salt/redis/files/目录下,没有则创建;top中指定即可install.sls如下: file.managed: - name: /usr/local/src/redis-3.0.7.tar.gz - source: salt://redis/files/redis-3.0.7.tar.gz - user: root - group: root - mode: 755 cmd.run: - name: cd /usr/local/src && tar xf redis-3.0.7.tar.gz && cd redis-3.0.7 && PREFIX=/usr/local/redis install - unless: test -d /usr/local/redis redis-config: file.managed: - name: /etc/redis/6379.conf - spurce: salt://redis/files/6379.conf - user: root - group: root - mode: 644 redis-service: file.managed: - name: /etc/init.d/redis - source: salt://redis/files/redis.init - user: root - group: root - mode: 755 cmd.run - name: chkconfig --add redis && chkconfig redis on - unless: chkconfig --list |grep redis service.runnig: - name: redis - emable: True - watch: - file: redis-config - require: - cmd: redis-install - cmd: redis-service
2016年02月25日
3,210 阅读
0 评论
0 点赞
1
2