squid编译安装与基础操作

squid编译安装与基础操作

系数据库与非关系型数据库

关系型数据库

一个结构化的数据库,创建在关系模型基础上
一般面向于记录
包括
    Oracle、Mysql、SQL Server、Microsoft Access、DB2等

非关系型数据库

除了主流的关系型数据库外的数据库,都认为是非关系型
包括
    Redis、MongoDB、Hbase、CouhDB等

Redis

简介

Redis基于内存运行并支持持久化

采用key-value(键值对)的存储形式

优点
具有极高的数据读写速度
支持丰富的数据类型
支持数据的持久化
原子性
支持数据备份

redis(remote dictionary server,远程字典服务)是一个开源的使用ANSI C语言编写、遵守BSD协议,支持网络,可基于内存可持久化的日志型、key-Value的数据库,并提供多种语言的API。它通常被称为结构服务器,因为值(value)可以是字符串(string),哈希(hash),列表(list),集合(sets)和有序集合(sorted sets)等类型

redis是完全开源免费的,是一个高性能的key-value数据库

redis的特点

redis支持数据的持久化,可以将内存中的数据库保存在磁盘中,重启的时候可以再次加载进行使用

redis不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存储
redis支持数据的备份,即master-slave模式的数据备份(下一篇将会详述redis群集)

redis与其他key-value的不同

redis有着更为复杂的数据结构并且提供对他们的原子操作,这是一个不同于其他数据库的进化路径。redis的数据类型都是基于基本数据结构的同时对程序员透明,无需进行额外的抽象

redis运行在内存中但是可以持久化到磁盘,所以在对不同数据集进行高速读写时需要权衡内存,因为数据不能大于硬件内存。在内存数据库方面的另外一个优点是,相比在磁盘上相同的复杂的数据结构,在内存中操作起来非常简单,这样redis可以做很多内部复杂性很强的事情。同时,在磁盘格式方面他们是紧凑的以追加的方式生产的,因为他们不需要进行随机访问

Redis安装部署

操作步骤
    解压软件包
    make && make install
    设置Redis相关配置文件
    查看运行状态
编译安装Redis
[root@localhost ~]# yum -y install gcc gcc-c++ make
[root@localhost ~]# tar zxvf redis-5.0.7.tar.gz -C /opt/
[root@localhost ~]# cd /opt/redis-5.0.7/
[root@localhost redis-5.0.7]# make
[root@localhost redis-5.0.7]# make PREFIX=/usr/local/redis install
[root@localhost redis-5.0.7]# ln -s /usr/local/redis/bin/* /usr/local/bin/
[root@localhost redis-5.0.7]# cd /opt/redis-5.0.7/utils/
[root@localhost utils]# ./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
[root@localhost utils]# netstat -lnupt | grep redis
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      15435/redis-server 
[root@localhost utils]# /etc/init.d/redis_6379 start
[root@localhost utils]# /etc/init.d/redis_6379 stop
[root@localhost utils]# /etc/init.d/redis_6379 restart
[root@localhost utils]# /etc/init.d/redis_6379 status
[root@localhost utils]# vim /etc/redis/6379.conf 
  70 bind 127.0.0.1
  93 port 6379
 137 daemonize yes
 159 pidfile /var/run/redis_6379.pid
 167 loglevel notice
 172 logfile /var/log/redis_6379.log

  70 bind 127.0.0.1 192.168.20.10
配置参数
    bind:监听的主机地址
    port:端口
    daemonize yes:启用守护进程
    pidfile:指定PID文件
    loglevel notice:日志级别
    logfile:指定日志文件

Redis数据库常用命令
Redis-cli命令行工具

获取命令帮助
help @:获取中的命令列表
help :获取某个命令的帮助
help :获取可能帮助的主题列表

set:存放数据

get:获取数据

key相关
keys:获取符号规则的键值列表
exists:判断键值是否存在
del:删除当前数据库的指定key
type:获取key对应的value值类型
rename(覆盖)/renamenx(不覆盖):对已有的key进行重命名
dbsize:查看当前数据库中key的数目
Redis-benchmark测试工具

    -h:指定服务器主机名

    -p:指定服务器端口

    -c:指定请求数

    -d:以字节的形式指定set/get值的数据大小

    -q:强制退出Redis,仅显示query/sec值
 [root@localhost utils]# /etc/init.d/redis_6379 restart
[root@localhost utils]# redis-cli -h 192.168.20.10 -p 6379
192.168.20.10:6379> 
[root@localhost utils]# redis-cli 
127.0.0.1:6379> 

192.168.20.10:6379> keys *
(empty list or set)
192.168.20.10:6379> quit

192.168.20.10:6379> help @list

  BLPOP key [key ...] timeout
  summary: Remove and get the first element in a list, or block until one is available
  since: 2.0.0
......

192.168.20.10:6379> help keys

  KEYS pattern
  summary: Find all keys matching the given pattern
  since: 1.0.0
  group: generic

192.168.20.10:6379> set color yellow
OK
192.168.20.10:6379> keys *
1) "color"
192.168.20.10:6379> get color
"yellow"
192.168.20.10:6379> del color
(integer) 1
192.168.20.10:6379> keys per???
1) "person"
192.168.20.10:6379> keys per*
1) "person"
筛选键名模糊查询的时候 可以用* ?通配符
192.168.20.10:6379> type person
string
192.168.20.10:6379> exists person 
(integer) 1
192.168.20.10:6379> exists color
(integer) 0
192.168.20.10:6379> rename person name
OK
192.168.20.10:6379> keys *
1) "name"
192.168.20.10:6379> dbsize
(integer) 1  
[root@localhost utils]# /usr/local/redis/bin/redis-benchmark -h 192.168.20.10 -p 6379 -q -d 100
192.168.20.10:6379> select 3
OK
192.168.20.10:6379[3]> set num 10
OK
192.168.20.10:6379[3]> move num 4
(integer) 1
192.168.20.10:6379[3]> keys *
(empty list or set)
192.168.20.10:6379[3]> select 4
OK
192.168.20.10:6379[4]> keys *
1) "num"
192.168.20.10:6379[4]> get num
"10"

设置hash结构
192.168.20.10:6379> hset person name zhangsan
(integer) 1
192.168.20.10:6379> hset person age 25
(integer) 1
192.168.20.10:6379> hset person score 60
(integer) 1
192.168.20.10:6379> keys *
1) "person"
2) "mylist"
3) "name"
4) "myset:__rand_int__"
5) "key:__rand_int__"
6) "counter:__rand_int__"
192.168.20.10:6379> hget person name
"zhangsan"
192.168.20.10:6379> hget person age
"25"
192.168.20.10:6379> hget person score
"60"


[root@localhost utils]# cd /var/lib/redis/6379/
[root@localhost 6379]# ll
总用量 232
-rw-r--r--. 1 root root 233891 98 17:31 dump.rdb

[root@localhost 6379]# vim /etc/redis/6379.conf      
save 900 1
save 300 10
save 60 10000
dbfilename dump.rdb
dir /var/lib/redis/6379                         
rdbcompression yes

[root@localhost 6379]# vim /etc/redis/6379.conf      
appendonly yes
appendfilename "appendonly.aof"
# appendfsync always
appendfsync everysec
# appendfsync no
aof-load-truncated yes

[root@localhost 6379]# /etc/init.d/redis_6379 restart
[root@localhost 6379]# ll
总用量 232
-rw-r--r--. 1 root root      0 98 18:50 appendonly.aof
-rw-r--r--. 1 root root 233945 98 18:50 dump.rdb

[root@localhost 6379]# redis-cli -h 192.168.20.10 -p 6379
192.168.20.10:6379> info memory
# Memory
used_memory:853320
used_memory_human:833.32K
used_memory_rss:10493952
used_memory_rss_human:10.01M
used_memory_peak:853320
used_memory_peak_human:833.32K
used_memory_peak_perc:100.01%
used_memory_overhead:841094
used_memory_startup:791400
used_memory_dataset:12226
used_memory_dataset_perc:19.74%
allocator_allocated:1661928
allocator_active:2068480
allocator_resident:9187328
total_system_memory:3954188288
total_system_memory_human:3.68G
used_memory_lua:37888
used_memory_lua_human:37.00K
used_memory_scripts:0
used_memory_scripts_human:0B
number_of_cached_scripts:0
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
allocator_frag_ratio:1.24
allocator_frag_bytes:406552
allocator_rss_ratio:4.44
allocator_rss_bytes:7118848
rss_overhead_ratio:1.14
rss_overhead_bytes:1306624
mem_fragmentation_ratio:12.92
mem_fragmentation_bytes:9681656
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:49694
mem_aof_buffer:0
mem_allocator:jemalloc-5.1.0
active_defrag_running:0
lazyfree_pending_objects:0

猜你喜欢

转载自blog.csdn.net/weixin_46355881/article/details/108559083
今日推荐