Squid compilation and installation and basic operations

Squid compilation and installation and basic operations

Departmental database and non-relational database

Relational Database

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

Non-relational database

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

Redis

Introduction

Redis runs on memory and supports persistence

Use key-value (key-value pair) storage format

Advantages
Very high data read and write speed
Supports rich data types
Supports data persistence
Atomicity
Supports data backup

redis (remote dictionary server, remote dictionary service) is an open source written in ANSI C language, complies with the BSD protocol, supports the network, and can be based on a log-based and key-value database with memory persistence, and provides APIs in multiple languages . It is usually called a structure server because the value can be of string, hash, list, sets, and sorted sets.

Redis is completely open source and free, and is a high-performance key-value database

Features of redis

Redis supports data persistence. The database in memory can be saved on disk, and it can be loaded again for use when restarting.

Redis not only supports simple key-value data, but also provides storage for list, set, zset, hash and other data structures.
Redis supports data backup, that is, data backup in master-slave mode (detailed in the next article redis cluster)

The difference between redis and other key-values

Redis has a more complex data structure and provides atomic operations on them, which is an evolutionary path different from other databases. The data types of redis are based on basic data structures and are transparent to programmers without additional abstraction.

Redis runs in memory but can be persisted to disk, so memory needs to be weighed when reading and writing different data sets at high speed, because data cannot be larger than hardware memory. Another advantage of the in-memory database is that compared to the same complex data structure on the disk, it is very simple to operate in memory, so that redis can do a lot of internally complex things. At the same time, in terms of disk format, they are produced in a compact and appended manner because they do not require random access

Redis installation and deployment

操作步骤
    解压软件包
    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 database commonly used commands
Redis-cli command line tool

Get command help
help @:Get a list of commands
help: Get help for a command help: Get a
list of topics that may help

set: store data

get: Get data

Key related
keys: get the key value list of the symbol rule
exists: determine whether the key value exists
del: delete the specified key
type of the current database : get the value type of the key corresponding to
rename (overwrite)/renamenx (not overwrite): for the existing Key rename
dbsize: View the number of keys in the current database
Redis-benchmark test tool

    -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

Guess you like

Origin blog.csdn.net/weixin_46355881/article/details/108559083