1. redis主从复制原理?

 1 从节点1、2
2 127.0.0.1:6379> replicaof 10.0.0.157 6379
3 OK
4 127.0.0.1:6379> config set masterauth 123456
5 OK
6 127.0.0.1:6379> info
7 # Replication
8 role:slave
9 master_host:10.0.0.157
10 master_port:6379
11 master_link_status:up
12
13 127.0.0.1:6379> keys *
14 ...
15 99995) "k77506"
16 99996) "k43577"
17 99997) "k64419"
18 99998) "k96650"
19 99999) "k96858"
20 100000) "k13323"
 1 主节点
2 127.0.0.1:6379> info replication
3 # Replication
4 role:master
5 connected_slaves:2
6 slave0:ip=10.0.0.156,port=6379,state=online,offset=630,lag=1
7 slave1:ip=10.0.0.158,port=6379,state=online,offset=630,lag=1
8 master_failover_state:no-failover
9 master_replid:e4dc78895bbf1d8119bf49a8ed5161febe53338a
10 master_replid2:0000000000000000000000000000000000000000
11 master_repl_offset:644
12 second_repl_offset:-1
13 repl_backlog_active:1
14 repl_backlog_size:1048576
15 repl_backlog_first_byte_offset:1
16 repl_backlog_histlen:644

2. redis哨兵实现

[root@centos7 ~]# cd /usr/local/src/
[root@centos7 src]# ls
redis-6.2.2 redis-6.2.2.tar.gz
[root@centos7 src]# cd redis-6.2.2
[root@centos7 redis-6.2.2]# ls
00-RELEASENOTES COPYING MANIFESTO runtest-cluster src
BUGS deps README.md runtest-moduleapi tests
CONDUCT INSTALL redis.conf runtest-sentinel TLS.md
CONTRIBUTING Makefile runtest sentinel.conf utils
[root@centos7 redis-6.2.2]# cp sentinel.conf /apps/redis/etc/
[root@centos7 redis-6.2.2]# vim /apps/redis/etc/sentinel.conf
bind 0.0.0.0
port 26379
daemonize yes
pidfile /apps/redis/run/redis-sentinel.pid
logfile "/apps/redis/log/sentinel_26379.log"
sentinel monitor mymaster 10.0.0.157 6379 2
sentinel auth-psaa mymaster 123456
sentinel down-after-milliseconds mymaster 3000
#修改完后将配置文件传到其余的节点 修改sentinel.service文件
[root@centos7 ~]# cat /lib/systemd/system/redis-sentinel.service
[Unit]
Description=Redis Sentinel
After=network.target [Service]
ExecStart=/apps/redis/bin/redis-sentinel /apps/redis/etc/redis-sentinel.conf --supervised systemd
ExecStop=/bin/kill -s QUIT $MAINPID
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755 [Install]
WantedBy=multi-user.target 三个节点启动redis-sentinel.service
# systemctl start redis-sentinel.service 关闭主节点
[root@centos7 etc]# redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> shutdown
not connected> 新主节点
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=10.0.0.158,port=6379,state=online,offset=748637,lag=1
master_failover_state:no-failover
master_replid:fbfa0d5aa02f2e97867345d0d4dd3ec13a263780
master_replid2:65b064fc605e9a1c9747603853a3cc509e57d51f
master_repl_offset:748637
second_repl_offset:737461
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:159
repl_backlog_histlen:748479

127.0.0.1:6379> set age 18
  OK

从节点

127.0.0.1:6379> get age

  "18"

 
重启关闭的节点
[root@centos7 etc]# redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:10.0.0.156
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:1101451
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:fbfa0d5aa02f2e97867345d0d4dd3ec13a263780
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:1101451
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1100214
repl_backlog_histlen:1238
127.0.0.1:6379> get age
"18"

3. redis集群搭建,迁移,扩容

redis集群搭建(原生命令)

每个节点安装redis
修改以下配置
masterauth 123456
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-require-full-coverage no 重启服务
systemctl restart redis
[root@centos7 ~]# ps aux | grep redis
redis 5473 0.0 0.1 195548 3948 ? Ssl 22:45 0:00 /apps/redis/bin/redis-server 0.0.0.0:6379 [cluster]
root 5480 0.0 0.0 112812 980 pts/0 S+ 22:45 0:00 grep --color=auto redis 在其中一个节点与其他节点进行通信
[root@node1 ~]# redis-cli -a 123456 --no-auth-warning cluster meet 10.0.0.157 6379
OK
[root@node1 ~]# redis-cli -a 123456 --no-auth-warning cluster meet 10.0.0.158 6379
OK
[root@node1 ~]# redis-cli -a 123456 --no-auth-warning cluster meet 10.0.0.159 6379
OK
[root@node1 ~]# redis-cli -a 123456 --no-auth-warning cluster meet 10.0.0.171 6379
OK
[root@node1 ~]# redis-cli -a 123456 --no-auth-warning cluster meet 10.0.0.172 6379
OK [root@node1 ~]# redis-cli -a 123456 cluster nodes
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
540516862020d0488f3a7b1ed5b188b624527f4a 10.0.0.157:6379@16379 master - 0 1675868398000 1 connected
258bf4841b23c2a6a0ce87ce6cd5a688e1848b20 10.0.0.158:6379@16379 master - 0 1675868398000 2 connected
e37097952378288720c436aebf4f01e4096005c0 10.0.0.156:6379@16379 myself,master - 0 1675868399000 0 connected
cc22270e6c3ca563c669f3d8f8ba3bcc06f13e28 10.0.0.172:6379@16379 master - 0 1675868399888 5 connected
83bf279100fd098932f737f40f1b6f1a3e69474d 10.0.0.171:6379@16379 master - 0 1675868398879 4 connected
b328f1aef7d514f8760c10d2e13c5466ed9f4dfc 10.0.0.159:6379@16379 master - 0 1675868400897 3 connected
分配槽点
root@node1 ~]# cat addslot.sh
#!/bin/bash
host=$1
port=$2
start=$3
end=$4
pass=123456 for slot in `seq ${start} ${end}`;do
echo slot:$slot
redis-cli -h ${host} -p $port -a ${pass} --no-auth-warning cluster addslots ${slot}
done
[root@node1 ~]# ./addslot.sh 10.0.0.156 6379 0 5461
[root@node1 ~]# ./addslot.sh 10.0.0.157 6379 5462 10922
[root@node1 ~]# ./addslot.sh 10.0.0.158 6379 10923 16383
[root@node1 ~]# redis-cli -a 123456 --no-auth-warning cluster nodes
540516862020d0488f3a7b1ed5b188b624527f4a 10.0.0.157:6379@16379 master - 0 1675951324000 1 connected 5462-10922
258bf4841b23c2a6a0ce87ce6cd5a688e1848b20 10.0.0.158:6379@16379 master - 0 1675951324000 2 connected 10923-16383
e37097952378288720c436aebf4f01e4096005c0 10.0.0.156:6379@16379 myself,master - 0 1675951322000 0 connected 0-5461
cc22270e6c3ca563c669f3d8f8ba3bcc06f13e28 10.0.0.172:6379@16379 master - 0 1675951324715 5 connected
83bf279100fd098932f737f40f1b6f1a3e69474d 10.0.0.171:6379@16379 master - 0 1675951323708 4 connected
b328f1aef7d514f8760c10d2e13c5466ed9f4dfc 10.0.0.159:6379@16379 master - 0 1675951320000 3 connected
[root@node1 ~]# redis-cli -h 10.0.0.159 -a 123456 --no-auth-warning cluster replicate e37097952378288720c436aebf4f01e4096005c0
OK
[root@node1 ~]# redis-cli -h 10.0.0.171 -a 123456 --no-auth-warning cluster replicate 540516862020d0488f3a7b1ed5b188b624527f4a
OK
[root@node1 ~]# redis-cli -h 10.0.0.172 -a 123456 --no-auth-warning cluster replicate 258bf4841b23c2a6a0ce87ce6cd5a688e1848b20
OK
[root@node1 ~]# redis-cli -a 123456 --no-auth-warning cluster nodes
540516862020d0488f3a7b1ed5b188b624527f4a 10.0.0.157:6379@16379 master - 0 1675952591000 1 connected 5462-10922
258bf4841b23c2a6a0ce87ce6cd5a688e1848b20 10.0.0.158:6379@16379 master - 0 1675952592487 2 connected 10923-16383
e37097952378288720c436aebf4f01e4096005c0 10.0.0.156:6379@16379 myself,master - 0 1675952589000 0 connected 0-5461
cc22270e6c3ca563c669f3d8f8ba3bcc06f13e28 10.0.0.172:6379@16379 slave 258bf4841b23c2a6a0ce87ce6cd5a688e1848b20 0 1675952588455 2 connected
83bf279100fd098932f737f40f1b6f1a3e69474d 10.0.0.171:6379@16379 slave 540516862020d0488f3a7b1ed5b188b624527f4a 0 1675952591478 1 connected
b328f1aef7d514f8760c10d2e13c5466ed9f4dfc 10.0.0.159:6379@16379 slave e37097952378288720c436aebf4f01e4096005c0 0 1675952591000 0 connected
[root@node1 ~]# redis-cli -a 123456 --no-auth-warning cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:5
cluster_my_epoch:0
cluster_stats_messages_ping_sent:10882
cluster_stats_messages_pong_sent:11148
cluster_stats_messages_meet_sent:5
cluster_stats_messages_sent:22035
cluster_stats_messages_ping_received:11148
cluster_stats_messages_pong_received:10887
cluster_stats_messages_received:22035

新版本创建集群

搭建后集群后分配槽点
[root@centos7 ~]# redis-cli -a 123456 --cluster create 10.0.0.156:6379 10.0.0.157:6379 10.0.0.158:6379 10.0.0.159:6379 10.0.0.171:6379 10.0.0.172:6379 --cluster-replicas 1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 10.0.0.171:6379 to 10.0.0.156:6379
Adding replica 10.0.0.172:6379 to 10.0.0.157:6379
Adding replica 10.0.0.159:6379 to 10.0.0.158:6379
M: 284e9791656dbac33cb1d6e83568a60e8d84d230 10.0.0.156:6379
slots:[0-5460] (5461 slots) master
M: c3f495b7803eb75db4f2c50e6042c5688a09d194 10.0.0.157:6379
slots:[5461-10922] (5462 slots) master
M: 5ce656697e443c63dcc731129373ba0bac6a5747 10.0.0.158:6379
slots:[10923-16383] (5461 slots) master
S: 1690099cd947202933875611ca2901c2ddb8597b 10.0.0.159:6379
replicates 5ce656697e443c63dcc731129373ba0bac6a5747
S: 36bcd366bf14b8122777accb55d7bd0d014e8230 10.0.0.171:6379
replicates 284e9791656dbac33cb1d6e83568a60e8d84d230
S: 0c4ffe8052798d05a2e6c14be40d73b3445bacba 10.0.0.172:6379
replicates c3f495b7803eb75db4f2c50e6042c5688a09d194
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
..
>>> Performing Cluster Check (using node 10.0.0.156:6379)
M: 284e9791656dbac33cb1d6e83568a60e8d84d230 10.0.0.156:6379
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 0c4ffe8052798d05a2e6c14be40d73b3445bacba 10.0.0.172:6379
slots: (0 slots) slave
replicates c3f495b7803eb75db4f2c50e6042c5688a09d194
M: c3f495b7803eb75db4f2c50e6042c5688a09d194 10.0.0.157:6379
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 36bcd366bf14b8122777accb55d7bd0d014e8230 10.0.0.171:6379
slots: (0 slots) slave
replicates 284e9791656dbac33cb1d6e83568a60e8d84d230
M: 5ce656697e443c63dcc731129373ba0bac6a5747 10.0.0.158:6379
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 1690099cd947202933875611ca2901c2ddb8597b 10.0.0.159:6379
slots: (0 slots) slave
replicates 5ce656697e443c63dcc731129373ba0bac6a5747
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[root@centos7 ~]# redis-cli -a 123456 cluster nodes
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
0c4ffe8052798d05a2e6c14be40d73b3445bacba 10.0.0.172:6379@16379 slave c3f495b7803eb75db4f2c50e6042c5688a09d194 0 1675956965000 2 connected
284e9791656dbac33cb1d6e83568a60e8d84d230 10.0.0.156:6379@16379 myself,master - 0 1675956964000 1 connected 0-5460
c3f495b7803eb75db4f2c50e6042c5688a09d194 10.0.0.157:6379@16379 master - 0 1675956966000 2 connected 5461-10922
36bcd366bf14b8122777accb55d7bd0d014e8230 10.0.0.171:6379@16379 slave 284e9791656dbac33cb1d6e83568a60e8d84d230 0 1675956966212 1 connected
5ce656697e443c63dcc731129373ba0bac6a5747 10.0.0.158:6379@16379 master - 0 1675956965206 3 connected 10923-16383
1690099cd947202933875611ca2901c2ddb8597b 10.0.0.159:6379@16379 slave 5ce656697e443c63dcc731129373ba0bac6a5747 0 1675956964000 3 connected
[root@centos7 ~]# redis-cli -a 123456 cluster info
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:91
cluster_stats_messages_pong_sent:99
cluster_stats_messages_sent:190
cluster_stats_messages_ping_received:94
cluster_stats_messages_pong_received:91
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:190

redis集群扩容

把新的节点加入集群中
[root@centos7 ~]# redis-cli -a 123456 --cluster add-node 10.0.0.173:6379 10.0.0.156:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 10.0.0.173:6379 to cluster 10.0.0.156:6379
>>> Performing Cluster Check (using node 10.0.0.156:6379)
M: e37097952378288720c436aebf4f01e4096005c0 10.0.0.156:6379
slots:[0-5461] (5462 slots) master
1 additional replica(s)
M: 540516862020d0488f3a7b1ed5b188b624527f4a 10.0.0.157:6379
slots:[5462-10922] (5461 slots) master
1 additional replica(s)
M: 258bf4841b23c2a6a0ce87ce6cd5a688e1848b20 10.0.0.158:6379
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: cc22270e6c3ca563c669f3d8f8ba3bcc06f13e28 10.0.0.172:6379
slots: (0 slots) slave
replicates 258bf4841b23c2a6a0ce87ce6cd5a688e1848b20
S: 83bf279100fd098932f737f40f1b6f1a3e69474d 10.0.0.171:6379
slots: (0 slots) slave
replicates 540516862020d0488f3a7b1ed5b188b624527f4a
S: b328f1aef7d514f8760c10d2e13c5466ed9f4dfc 10.0.0.159:6379
slots: (0 slots) slave
replicates e37097952378288720c436aebf4f01e4096005c0
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 10.0.0.173:6379 to make it join the cluster.
[OK] New node added correctly. 重新分配槽位
[root@node1 ~]# redis-cli -a 123456 --cluster reshard 10.0.0.156:6379
Warning: Using a password with '-a' or '-u' option on the command line interface
may not be safe.
>>> Performing Cluster Check (using node 10.0.0.156:6379)
M: d6e2eca6b338b717923f64866bd31d42e52edc98 10.0.0.156:6379
slots: (0 slots) master
M: d34da8666a6f587283a1c2fca5d13691407f9462 10.0.0.157:6379
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
M: d04e524daec4d8e22bdada7f21a9487c2d3e1057 10.0.0.158:6379
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 99720241248ff0e4c6fa65c2385e92468b3b5993 10.0.0.159:6379
slots: (0 slots) slave
replicates d04e524daec4d8e22bdada7f21a9487c2d3e1057
M: f67f1c02c742cd48d3f48d8c362f9f1b9aa31549 10.0.0.173:6379
slots: (0 slots) master
S: f9adcfb8f5a037b257af35fa548a26ffbadc852d 10.0.0.172:6379
slots: (0 slots) slave
replicates cb028b83f9dc463d732f6e76ca6bbcd469d948a7
S: 9875b50925b4e4f29598e6072e5937f90df9fc71 10.0.0.171:6379
slots: (0 slots) slave
replicates d34da8666a6f587283a1c2fca5d13691407f9462
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)?4096 #新分配多少个槽位
=16384/master个数
What is the receiving node ID? d6e2eca6b338b717923f64866bd31d42e52edc98 #新的
master的ID
Please enter all the source node IDs.
Type 'all' to use all the nodes as source nodes for the hash slots.
Type 'done' once you entered all the source nodes IDs.
Source node #1: all #将哪些源主机的槽位分配给新的节点,all是自动在所有的redis node选择划
分,如果是从redis cluster删除某个主机可以使用此方式将指定主机上的槽位全部移动到别的redis主机
......
Do you want to proceed with the proposed reshard plan (yes/no)? yes #确认分配
......
Moving slot 12274 from 10.0.0.158:6379 to 10.0.0.173:6379:
Moving slot 12275 from 10.0.0.158:6379 to 10.0.0.173:6379:
Moving slot 12276 from 10.0.0.158:6379 to 10.0.0.173:6379:
Moving slot 12277 from 10.0.0.158:6379 to 10.0.0.173:6379:
Moving slot 12278 from 10.0.0.158:6379 to 10.0.0.173:6379:
Moving slot 12279 from 10.0.0.158:6379 to 10.0.0.173:6379:
Moving slot 12280 from 10.0.0.158:6379 to 10.0.0.173:6379:
Moving slot 12281 from 10.0.0.158:6379 to 10.0.0.173:6379:
Moving slot 12282 from 10.0.0.158:6379 to 10.0.0.173:6379:
Moving slot 12283 from 10.0.0.158:6379 to 10.0.0.173:6379:
Moving slot 12284 from 10.0.0.158:6379 to 10.0.0.173:6379:
Moving slot 12285 from 10.0.0.158:6379 to 10.0.0.173:6379:
Moving slot 12286 from 10.0.0.158:6379 to 10.0.0.173:6379:
Moving slot 12287 from 10.0.0.158:6379 to 10.0.0.173:6379: [root@node1 ~]# redis-cli -a 123456 cluster nodes
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
540516862020d0488f3a7b1ed5b188b624527f4a 10.0.0.157:6379@16379 master - 0 1676560040914 1 connected 6827-10922
258bf4841b23c2a6a0ce87ce6cd5a688e1848b20 10.0.0.158:6379@16379 master - 0 1676560040000 2 connected 12288-16383
e37097952378288720c436aebf4f01e4096005c0 10.0.0.156:6379@16379 myself,master - 0 1676560037000 0 connected 1366-5461
cc22270e6c3ca563c669f3d8f8ba3bcc06f13e28 10.0.0.172:6379@16379 slave 258bf4841b23c2a6a0ce87ce6cd5a688e1848b20 0 1676560037844 2 connected
83bf279100fd098932f737f40f1b6f1a3e69474d 10.0.0.171:6379@16379 slave 540516862020d0488f3a7b1ed5b188b624527f4a 0 1676560039895 1 connected
b328f1aef7d514f8760c10d2e13c5466ed9f4dfc 10.0.0.159:6379@16379 slave e37097952378288720c436aebf4f01e4096005c0 0 1676560040000 0 connected
adf674e50130ccef555dbcee10a94fd44b4cd10a 10.0.0.173:6379@16379 master - 0 1676560041935 6 connected 0-1365 5462-6826 10923-12287 新加一个从节点进集群
[root@node1 ~]# redis-cli -a 123456 --cluster add-node 10.0.0.174:6379 10.0.0.156:6379 --cluster-slave --cluster-master-id adf674e50130ccef555dbcee10a94fd44b4cd10a
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 10.0.0.174:6379 to cluster 10.0.0.156:6379
>>> Performing Cluster Check (using node 10.0.0.156:6379)
M: e37097952378288720c436aebf4f01e4096005c0 10.0.0.156:6379
slots:[1366-5461] (4096 slots) master
1 additional replica(s)
M: 540516862020d0488f3a7b1ed5b188b624527f4a 10.0.0.157:6379
slots:[6827-10922] (4096 slots) master
1 additional replica(s)
M: 258bf4841b23c2a6a0ce87ce6cd5a688e1848b20 10.0.0.158:6379
slots:[12288-16383] (4096 slots) master
1 additional replica(s)
S: cc22270e6c3ca563c669f3d8f8ba3bcc06f13e28 10.0.0.172:6379
slots: (0 slots) slave
replicates 258bf4841b23c2a6a0ce87ce6cd5a688e1848b20
S: 83bf279100fd098932f737f40f1b6f1a3e69474d 10.0.0.171:6379
slots: (0 slots) slave
replicates 540516862020d0488f3a7b1ed5b188b624527f4a
S: b328f1aef7d514f8760c10d2e13c5466ed9f4dfc 10.0.0.159:6379
slots: (0 slots) slave
replicates e37097952378288720c436aebf4f01e4096005c0
M: adf674e50130ccef555dbcee10a94fd44b4cd10a 10.0.0.173:6379
slots:[0-1365],[5462-6826],[10923-12287] (4096 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 10.0.0.174:6379 to make it join the cluster.
Waiting for the cluster to join >>> Configure node as replica of 10.0.0.173:6379.
[OK] New node added correctly.
[root@node1 ~]# redis-cli -a 123456 cluster nodes
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
540516862020d0488f3a7b1ed5b188b624527f4a 10.0.0.157:6379@16379 master - 0 1676560596000 1 connected 6827-10922
b04b6bae61504ed41c0f8ee4d213c020eb44f07c 10.0.0.174:6379@16379 slave adf674e50130ccef555dbcee10a94fd44b4cd10a 0 1676560598000 6 connected
258bf4841b23c2a6a0ce87ce6cd5a688e1848b20 10.0.0.158:6379@16379 master - 0 1676560597000 2 connected 12288-16383
e37097952378288720c436aebf4f01e4096005c0 10.0.0.156:6379@16379 myself,master - 0 1676560594000 0 connected 1366-5461
cc22270e6c3ca563c669f3d8f8ba3bcc06f13e28 10.0.0.172:6379@16379 slave 258bf4841b23c2a6a0ce87ce6cd5a688e1848b20 0 1676560597299 2 connected
83bf279100fd098932f737f40f1b6f1a3e69474d 10.0.0.171:6379@16379 slave 540516862020d0488f3a7b1ed5b188b624527f4a 0 1676560597000 1 connected
b328f1aef7d514f8760c10d2e13c5466ed9f4dfc 10.0.0.159:6379@16379 slave e37097952378288720c436aebf4f01e4096005c0 0 1676560598307 0 connected
adf674e50130ccef555dbcee10a94fd44b4cd10a 10.0.0.173:6379@16379 master - 0 1676560594246 6 connected 0-1365 5462-6826 10923-12287
[root@node1 ~]# redis-cli -a 123456 cluster info
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:8
cluster_size:4
cluster_current_epoch:7
cluster_my_epoch:0
cluster_stats_messages_ping_sent:21544
cluster_stats_messages_pong_sent:21880
cluster_stats_messages_meet_sent:5
cluster_stats_messages_fail_sent:5
cluster_stats_messages_update_sent:6
cluster_stats_messages_sent:43440
cluster_stats_messages_ping_received:21878
cluster_stats_messages_pong_received:25640
cluster_stats_messages_meet_received:2
cluster_stats_messages_received:47520

迁移

#所以节点清空密码
[root@node1 ~]# redis-cli -p 6379 -a 123456 --no-auth-warning CONFIG SET requirepass ""
OK [root@node1 ~]# redis-cli --cluster import 10.0.0.156:6379 --cluster-from 10.0.0.173:6379 --cluster-copy --cluster-replace
>>> Importing data from 10.0.0.173:6379 to cluster 10.0.0.156:6379
>>> Performing Cluster Check (using node 10.0.0.156:6379)
M: e37097952378288720c436aebf4f01e4096005c0 10.0.0.156:6379
slots:[0-1364],[1366-5461] (5461 slots) master
1 additional replica(s)
M: 540516862020d0488f3a7b1ed5b188b624527f4a 10.0.0.157:6379
slots:[1365],[5462-6825],[6827-10922] (5461 slots) master
1 additional replica(s)
M: 258bf4841b23c2a6a0ce87ce6cd5a688e1848b20 10.0.0.158:6379
slots:[6826],[10923-16383] (5462 slots) master
1 additional replica(s)
S: cc22270e6c3ca563c669f3d8f8ba3bcc06f13e28 10.0.0.172:6379
slots: (0 slots) slave
replicates 258bf4841b23c2a6a0ce87ce6cd5a688e1848b20
S: 83bf279100fd098932f737f40f1b6f1a3e69474d 10.0.0.171:6379
slots: (0 slots) slave
replicates 540516862020d0488f3a7b1ed5b188b624527f4a
S: b328f1aef7d514f8760c10d2e13c5466ed9f4dfc 10.0.0.159:6379
slots: (0 slots) slave
replicates e37097952378288720c436aebf4f01e4096005c0
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
*** Importing 100 keys from DB 0
Migrating c48 to 10.0.0.158:6379: OK
Migrating c10 to 10.0.0.156:6379: OK
Migrating c94 to 10.0.0.156:6379: OK
Migrating c58 to 10.0.0.156:6379: OK
Migrating c79 to 10.0.0.158:6379: OK
.
.
.
Migrating c61 to 10.0.0.156:6379: OK
Migrating c1 to 10.0.0.158:6379: OK
Migrating c46 to 10.0.0.157:6379: OK
Migrating c67 to 10.0.0.158:6379: OK
Segmentation fault

4. zabbix原理?

zabbix由几个主要的软件组件构成

server: zabbix server是一个核心组件,agent可以向它报告可用性和完整性信息和统计数据。该server所有的配置,数据和业务数据都存在数据库中。

数据库存储:所有的配置信息包括采集的数据都被zabbix存储在数据库中。

Web界面: 通过一个基于web的平台,我们可以从任何一个地方访问zabbix。这个web是zabbix server的一部分,通常跟server运行在同一台物理机上。(SQLite必须得配置在同一台物理机上)

Proxy: proxy可以代替server收集性能和可用性的数据。proxy是一个可选的部分,但它对于减弱zabbix server的负载非常有用。

agent: zabbix agent被部署在监控的目标上,主机监控本地的资源和应用并汇报数据给zabbix server。

5. zabbix server/proxy和agent配置文件详解。

#server配置文件
root@zabbix-server:~# grep "^[a-Z]" /apps/zabbix_server/etc/zabbix_server.conf
LogType=file
LogFile=/apps/zabbix_server/logs/zabbix_server.log
LogFileSize=500
DebugLevel=3
PidFile=/apps/zabbix_server/run/zabbix_server.pid
SocketDir=/apps/zabbix_server/run/
DBHost=10.0.0.164
DBName=zabbix_server
DBUser=zabbix
DBPassword=123456
SNMPTrapperFile=/apps/zabbix_server/run/zabbix_traps.tmp
StartSNMPTrapper=1
HousekeepingFrequency=4
MaxHousekeeperDelete=1000000
CacheSize=126M
CacheUpdateFrequency=60
StartDBSyncers=6
HistoryCacheSize=128M
HistoryIndexCacheSize=32M
TrendCacheSize=16M
ValueCacheSize=16M
Timeout=30
UnavailableDelay=60
FpingLocation=/usr/bin/fping
LogSlowQueries=3000
TmpDir=/apps/zabbix_server/run/
ProxyConfigFrequency=60
AllowRoot=1
User=rootroot@zabbix-server:~# grep "^[a-Z]" /apps/zabbix_server/etc/zabbix_server.conf
LogType=file
LogFile=/apps/zabbix_server/logs/zabbix_server.log
LogFileSize=500
DebugLevel=3
PidFile=/apps/zabbix_server/run/zabbix_server.pid
SocketDir=/apps/zabbix_server/run/
DBHost=10.0.0.164
DBName=zabbix_server
DBUser=zabbix
DBPassword=123456
SNMPTrapperFile=/apps/zabbix_server/run/zabbix_traps.tmp
StartSNMPTrapper=1
HousekeepingFrequency=4
MaxHousekeeperDelete=1000000
CacheSize=126M
CacheUpdateFrequency=60
StartDBSyncers=6
HistoryCacheSize=128M
HistoryIndexCacheSize=32M
TrendCacheSize=16M
ValueCacheSize=16M
Timeout=30
UnavailableDelay=60
FpingLocation=/usr/bin/fping
LogSlowQueries=3000
TmpDir=/apps/zabbix_server/run/
ProxyConfigFrequency=60
AllowRoot=1
User=root
#proxy-active配置文件
root@zabbix-proxy-active:~# grep '^[a-Z]' /etc/zabbix/zabbix_proxy.conf
ProxyMode=0
Server=10.0.0.161
ServerPort=10051
Hostname=zabbix-proxy-active
LogFile=/var/log/zabbix/zabbix_proxy.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_proxy.pid
SocketDir=/var/run/zabbix
DBHost=10.0.0.164
DBName=zabbix_proxy_active
DBUser=proxy
DBPassword=123456
ProxyLocalBuffer=720
ProxyOfflineBuffer=720
HeartbeatFrequency=60
ConfigFrequency=60
DataSenderFrequency=30
StartPollers=5
StartPollersUnreachable=3
StartTrappers=5
StartPingers=3
JavaGateway=10.0.0.162
JavaGatewayPort=10052
StartJavaPollers=5
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
ListenIP=0.0.0.0
Timeout=30
ExternalScripts=/usr/lib/zabbix/externalscripts
FpingLocation=/usr/bin/fping
Fping6Location=/usr/bin/fping6
LogSlowQueries=3000
#proxy-passive配置文件
root@zabbix-proxy-passive:~# grep '^[a-Z]' /etc/zabbix/zabbix_proxy.conf
ProxyMode=1
Server=10.0.0.161
Hostname=zabbix-proxy-passive
ListenPort=10051
LogFile=/var/log/zabbix/zabbix_proxy.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_proxy.pid
SocketDir=/var/run/zabbix
DBHost=10.0.0.164
DBName=zabbix_proxy_passive
DBUser=proxy
DBPassword=123456
ProxyLocalBuffer=720
ProxyOfflineBuffer=720
HeartbeatFrequency=60
ConfigFrequency=60
StartPollers=5
StartPollersUnreachable=5
StartTrappers=5
StartPingers=3
JavaGateway=10.0.0.162
JavaGatewayPort=10052
StartJavaPollers=5
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
ListenIP=0.0.0.0
HousekeepingFrequency=1
CacheSize=16M
StartDBSyncers=4
HistoryCacheSize=16M
Timeout=30
ExternalScripts=/usr/lib/zabbix/externalscripts
FpingLocation=/usr/bin/fping
Fping6Location=/usr/bin/fping6
LogSlowQueries=3000
#agent配置文件
root@zabbix-web1:~# grep "^[a-Z]" /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=10.0.0.161
ListenPort=10050
ListenIP=0.0.0.0
StartAgents=3
ServerActive=127.0.0.1
Hostname=10.0.0.166
Include=/etc/zabbix/zabbix_agentd.d/*.conf

6. zabbix监控常用服务 nginx,redis, tomcat, haproxy,mysql。

#监控Tomcat
root@zabbix-web1:~# apt install openjdk-8-jdk
root@zabbix-web1:/apps/apache-tomcat-8.5.73# tar xvf apache-tomcat-8.5.73.tar.gz
root@zabbix-web1:/apps/apache-tomcat-8.5.73# vim bin/catalina.sh
CATALINA_OPTS="$CATALINA_OPTS -Docm.sun.management.jmxremote -Docm.sun.management.jmxremote.port=12345 -Docm.sun.management.jmxremote.authenticate=false -Docm.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=10.0.0.166"
root@zabbix-web1:/apps/apache-tomcat-8.5.73# /apps/apache-tomcat-8.5.73/bin/catalina.sh start
Using CATALINA_BASE: /apps/apache-tomcat-8.5.73
Using CATALINA_HOME: /apps/apache-tomcat-8.5.73
Using CATALINA_TMPDIR: /apps/apache-tomcat-8.5.73/temp
Using JRE_HOME: /usr
Using CLASSPATH: /apps/apache-tomcat-8.5.73/bin/bootstrap.jar:/apps/apache-tomcat-8.5.73/bin/tomcat-juli.jar
Using CATALINA_OPTS: -Docm.sun.management.jmxremote -Docm.sun.management.jmxremote.port=12345 -Docm.sun.management.jmxremote.authenticate=false -Docm.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=10.0.0.166
Tomcat started.
root@zabbix-web1:/apps/apache-tomcat-8.5.73/bin# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 127.0.0.53%lo:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 50 *:41119 *:*
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 100 *:8080 *:*
LISTEN 0 50 *:46483 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 50 *:12345 *:*
root@zabbix-server:~# vim /apps/zabbix_server/sbin/zabbix_java/settings.sh
root@zabbix-server:~# grep "^[a-Z]" /apps/zabbix_server/sbin/zabbix_java/settings.sh
LISTEN_IP="0.0.0.0"
LISTEN_PORT=10052
PID_FILE="/tmp/zabbix_java.pid"
START_POLLERS=5
TIMEOUT=30
root@zabbix-server:~# /apps/zabbix_server/sbin/zabbix_java/startup.sh
root@zabbix-server:~# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 64 0.0.0.0:32981 0.0.0.0:*
LISTEN 0 128 127.0.0.53%lo:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:54489 0.0.0.0:*
LISTEN 0 128 0.0.0.0:57757 0.0.0.0:*
LISTEN 0 64 0.0.0.0:2049 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 0.0.0.0:40465 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 64 [::]:41849 [::]:*
LISTEN 0 128 [::]:52603 [::]:*
LISTEN 0 64 [::]:2049 [::]:*
LISTEN 0 50 *:10052 *:*
LISTEN 0 128 [::]:38255 [::]:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:50257 [::]:* root@zabbix-server:~# vim /apps/zabbix_server/etc/zabbix_server.conf
JavaGateway=10.0.0.161
JavaGatewayPort=10052
StartJavaPollers=5
root@zabbix-server:~# systemctl restart zabbix-server.service

#nginx
location /nginx_status {
stub_status;
allow 10.0.0.161/16;
allow 127.0.0.1;
deny all;
}
###:
root@zabbix-web2:~# vim /etc/zabbix/zabbix_agentd.d/test.conf
UserParameter=nginx_status[*],/bin/bash /etc/zabbix/zabbix_agentd.d/nginx_status.sh $1
root@zabbix-web2:/etc/zabbix/zabbix_agentd.d# vim nginx_status.sh
#!/bin/bash
Check_Writing (){
/usr/bin/curl "http://127.0.0.1:80/nginx_status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'
}
Check_Reading(){
/usr/bin/curl "http://127.0.0.1:80/nginx_status/" 2>/dev/null| grep 'Writing' | awk '{print $2}'
}
Check_Waiting(){
/usr/bin/curl "http://127.0.0.1:80/nginx_status/" 2>/dev/null| grep 'Writing' | awk '{print $6}'
}
Check_Active(){
/usr/bin/curl "http://127.0.0.1:80/nginx_status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'
}
Check_accepts(){
/usr/bin/curl "http://127.0.0.1:80/nginx_status/" 2>/dev/null| awk NR==3 |awk '{print $1}'
}
Check_handled(){
/usr/bin/curl "http://127.0.0.1:80/nginx_status/" 2>/dev/null| awk NR==3 |awk '{print $2}'
}
Check_requests(){
/usr/bin/curl "http://127.0.0.1:80/nginx_status/" 2>/dev/null| awk NR==3 |awk '{print $3}'
} case $1 in
write)
Check_Writing;
;;
reading)
Check_Reading;
;;
active)
Check_active;
;;
waiting)
Check_Waiting;
;;
accept)
Check_accepts;
;;
handled)
Check_handled;
;;
requests)
Check_requests;
esac 测试
root@zabbix-server:/etc/apt# /usr/bin/zabbix_get -s 192.168.150.17 -p 10050 -k"nginx_status[handled]"
27
root@zabbix-server:/etc/apt# /usr/bin/zabbix_get -s 192.168.150.17 -p 10050 -k"nginx_status[accept]"
25
root@zabbix-server:/etc/apt# /usr/bin/zabbix_get -s 192.168.150.17 -p 10050 -k"nginx_status[write]"
1
redis
root@zabbix-web2:/etc/zabbix/zabbix_agentd.d# cat redis_monitor.sh
#!bin/bash
redis_status(){
R_PORT=$1
R_COMMAND=$2
(echo -en "INFO\r\n";) | ncat 127.0.0.1 "$R_PORT" > /tmp/redis_"$R_PORT".tmp
REDIS_STAT_VALUE=$(grep ""$R_COMMAND":" /tmp/redis_"$R_PORT".tmp | cut -d ':' -f2)
echo $REDIS_STAT_VALUE
} help(){
echo "${0} + redis_status + PORT +COMMAND"
} main(){
case $1 in
redis_status)
redis_status $2 $3
;;
*)
help
;;
esac
}
main $1 $2 $3
root@zabbix-web2:/etc/zabbix/zabbix_agentd.d# cat all.conf
UserParameter=redis_monitor[*],/bin/bash /etc/zabbix/zabbix_agentd.d/redis_monitor.sh $1 $2 $3
root@zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 10.0.0.167 -p 10050 -k "redis_monitor["redis_status","6379","connected_clients"]"
1

7. zabbix 使用api批量添加主机,脚本支持读csv文件,csv文件可以传递主机名,主机地址,模板名,主机PORT。读取csv遍历每1行添加主机到zabbix web。

root@zabbix-web2:/opt# curl -s -X POST -H 'Content-Type:application/json' -d '
> {
> "jsonrpc": "2.0",
> "method": "user.login", "params": {
> "user": "Admin",
> "password": "zabbix"
> },
> "id": 1
> }' http://10.0.0.167/zabbix/api_jsonrpc.php | python3 -m json.tool
{
"jsonrpc": "2.0",
"result": "35449513e525509881628285990735ef",
"id": 1
} ###获取gid、templete-id、将要加入的主机zabbix-agent配置好
root@zabbix-web2:/opt#curl -s -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": "API Add Host Test",
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "10.0.0.168",
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": "18"
}
],
"templates": [
{
"templateid": "10001"
}
]
},
"auth": "f1b7a0cb25ed9d7f60595d63fb660a4f",
"id": 1
}' http://10.0.0.167/zabbix/api_jsonrpc.php | python -m json.tool
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"hostids": [
"10439"
]
}
}

8。实现任意一种告警通知,短信,邮箱,企业微信

1)先在QQ邮箱打开该功能,然后生成授权码并保存

2)在zabbix web 配置报警媒介

3)给用户添加报警媒介

4)创建动作并添加

第十一周作业-N67044-张铭扬的更多相关文章

  1. 2017-2018-2 20179205《网络攻防技术与实践》第十一周作业 SQL注入攻击与实践

    <网络攻防技术与实践>第十一周作业 SQL注入攻击与实践 1.研究缓冲区溢出的原理,至少针对两种数据库进行差异化研究 缓冲区溢出原理   在计算机内部,输入数据通常被存放在一个临时空间内, ...

  2. 《Linux内核原理与设计》第十一周作业 ShellShock攻击实验

    <Linux内核原理与设计>第十一周作业 ShellShock攻击实验 分组: 和20179215袁琳完成实验及博客攥写 实验内容:   Bash中发现了一个严重漏洞shellshock, ...

  3. 2019-2020-1 20199329《Linux内核原理与分析》第十一周作业

    <Linux内核原理与分析>第十一周作业 一.本周内容概述: 学习linux安全防护方面的知识 完成实验楼上的<ShellShock 攻击实验> 二.本周学习内容: 1.学习& ...

  4. 2020-2021-1 20209307 《Linux内核原理与分析》第十一周作业

    这个作业属于哪个课程 <2020-2021-1Linux内核原理与分析)> 这个作业要求在哪里 <2020-2021-1Linux内核原理与分析第十一周作业> 这个作业的目标 ...

  5. 1903021121-刘明伟-java十一周作业-java面向对象编程

    项目 内容 课程班级博客链接 19级信计班(本) 作业要求链接 第十一周作业 博客名称 1903021121-刘明伟-java十一周作业-java面向对象 要求 每道题要有题目,代码(使用插入代码,不 ...

  6. 2017-2018-2 1723《程序设计与数据结构》第十一周作业 & 实验三 & (总体)第三周结对编程 总结

    作业地址 第十一次作业:https://edu.cnblogs.com/campus/besti/CS-IMIS-1723/homework/1933 (作业界面已评分,可随时查看,如果对自己的评分有 ...

  7. C语言第十一周作业

        这个作业属于哪个课程 C语言程序设计II 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/computer-scienceclass3-2018/ ...

  8. 2019春第十一周作业Compile Summarize

    这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 这里 我在这个课程的目标是 能按自己的想法解出题目 这个作业在那个具体方面帮助我实现目标 能朝着软件工程师方向发展 参考文献与网址 C语言 ...

  9. 201521123035《Java程序设计》第十一周作业

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 本周对多线程的冲突是从多线程的冲突开始讲起,从而提出互斥共享与互斥访问.其中,互斥访问提到了synchronize ...

  10. JAVA2015086第十一周作业

    本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 书面作业 本次PTA作业题集多线程 1.互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) 1.1 除了 ...

随机推荐

  1. js获取当前年月日时分

    function GetDate(){ var now = new Date(); var year = now.getFullYear(); //年 var month = now.getMonth ...

  2. 【深入浅出 Yarn 架构与实现】4-2 RM 管理 Application Master

    上一篇文章对 ResourceManager 整体架构和功能进行了讲述.本篇将对 RM 中管理 Application Master 的部分进行深入的讲解. 下面将会介绍 RM 与 AM 整体通信执行 ...

  3. 第一百一十七篇: JavaScript 工厂模式和原型模式

    好家伙,本篇为<JS高级程序设计>第八章"对象.类与面向对象编程"学习笔记   1.工厂模式 工厂模式是另外一种关注对象创建概念的创建模式. 它的领域中同其它模式的不同 ...

  4. APICloud 入门教程窗口篇

    什么是窗口,窗口可以理解为一屏幕内容的一个基本载体,里面可以放导航,图片,视频,文字等组成一屏幕内容. 不同的窗口组成一个APP, 例如购物APP有[首页],[购物车],[我的]等不同的窗口.不同的窗 ...

  5. [python] 向量检索库Faiss使用指北

    Faiss是一个由facebook开发以用于高效相似性搜索和密集向量聚类的库.它能够在任意大小的向量集中进行搜索.它还包含用于评估和参数调整的支持代码.Faiss是用C++编写的,带有Python的完 ...

  6. [C#]简单的理解委托和事件

    委托 在C++中可以利用"函数指针"将对方法的引用作为实参传递给另一个方法,而C#中可以利用委托提供相同的功能. 委托-内部机制 但是委托实际上是一个特殊的类.委托必须直接或间接的 ...

  7. [cocos2d-x]关于坐标系

    本文从cocos2dx官网看到,搬运过来学习一下. cocos2d-x3.X的坐标系 Cocos2d-x坐标系和OpenGL坐标系相同,都是起源于笛卡尔坐标系. 笛卡尔坐标系中定义右手系原点在左下角, ...

  8. 解决node.js报错Invalid character in header content ["Content-Disposition"]

    遇到这种报错一般在于下载文件时候,如果Content-Disposition设置文件名有中文会出现此种问题,解决方案如下: 把第二段代码改为第一段,即可~~ 'Content-Disposition' ...

  9. webpack动态配置多静态资源路径,动态配置多上线路径,配置less,多种图片引用方式----"webpack": "^4.41.6",

    1.项目场景是有两个静态资源目录,一个用于开发,一个用于发布,上线多个版本,打包多个版本后,也要部署到同一个服务器的同一个端口下. 根据我自己的摸索,我搞出来了下面的配置,自感觉还蛮好用的 先看我的c ...

  10. A+B Problem C++

    前言继上次发表的A+B Problem C语言后,今天我们来学习一下A+B Problem C++ 正文什么是C++? C++既可以进行C语言的过程化程序设计,又可以进行以抽象数据类型为特点的基于对象 ...