markDown 的使用

标题

1
2
3
# 一级标题
## 二级标题
依次类推

列表

1
2
在 Markdown 下,列表的显示只需要在文字前加上 - 或 * 即可变为无序列表,
有序列表则直接在文字前加 1. 2. 3. 符号要和文字之间加上一个字符的空格。

引用

1
只需要在文本前加入 > 这种尖括号(大于号)即可

图片与链接

1
插入链接与插入图片的语法很像,区别在一个 !号

粗体与斜体

1
2
Markdown 的粗体和斜体也非常简单,用两个 * 包含一段文本就是粗体的语法,
用一个 * 包含一段文本就是斜体的语法。

我只粗体我是斜体

表格

表格是我觉得 Markdown 比较累人的地方,例子如下:

1
2
3
4
5
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |

Tables Are Cool
col 3 is right-aligned $1600
col 2 is centered $12
zebra stripes are neat $1

分割线

1
分割线的语法只需要另起一行,连续输入三个星号 *** 即可。

代码框

1
2
3
4
如果你是个程序猿,需要在文章里优雅的引用代码框,在 Markdown 下实现也非常简单,
只需要用两个 ` 把中间的代码包裹起来.
如 `System.out.println()`

System.out.println()

redis集群搭建

1
2
3
4
5
6
7
8
9
搭建的是一个13从的redis+3个哨兵集群的环境,由于是在一台物理机上,所有我们用端口区分。
物理机IP:192.168.0.12
主节点master端口:6301
从节点slave1端口:6315
从节点slave2端口:6316
从节点slave3端口:6317
哨兵sentinel1端口:26301
哨兵sentinel2端口:26302
哨兵sentinel3端口:26303

下载redis && 复制

1
2
3
下载redis后然后解压,
复制
cp redis-benchmark redis-cli redis-server redis-sentinel /usr/bin/ #这个倒是很有用,这样就不用再执行时加上./了,而且可以在任何地方执行

设置内存分配策略(可选,根据服务器的实际情况进行设置)

1
2
3
4
5
6
/proc/sys/vm/overcommit_memory
可选值:012
0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;
否则,内存申请失败,并把错误返回给应用进程。
1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
2, 表示内核允许分配超过所有物理内存和交换空间总和的内存

开启redis端口,修改防火墙配置文件

1
2
3
4
5
vi /etc/sysconfig/iptables
加入端口配置
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT
重新加载规则
service iptables restart

配置redis.config文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
1、主节点master的配置文件redis_master_6301.config:
# Redis configuration file example
################################## INCLUDES ###################################
# include /path/to/local.conf
# include /path/to/other.conf
################################ GENERAL #####################################
daemonize yes
pidfile ./run/redis_slaver1_6315.pid
port 6301
tcp-backlog 511
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1
# unixsocket /tmp/redis.sock
# unixsocketperm 700
timeout 0
tcp-keepalive 0
loglevel notice
logfile "./run/logs/log_master_6301.log"
databases 16
################################ SNAPSHOTTING ################################
save ""
# save 900 1
# save 300 10
# save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum no
dbfilename dump_6301.rdb
dir ./run/data
################################# REPLICATION #################################
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
# repl-ping-slave-period 10
# repl-timeout 60
repl-disable-tcp-nodelay no
# repl-backlog-size 1mb
# repl-backlog-ttl 3600
slave-priority 100
# min-slaves-to-write 3
# min-slaves-max-lag 10
################################## SECURITY ###################################
# rename-command CONFIG ""
################################### LIMITS ####################################
# maxclients 10000
# maxmemory <bytes>
# maxmemory-policy noeviction
# maxmemory-samples 5
############################## APPEND ONLY MODE ###############################
appendonly no
appendfilename "appendonly_6301.aof"
appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
################################ LUA SCRIPTING ###############################
lua-time-limit 5000
################################ REDIS CLUSTER ###############################
# cluster-enabled yes
# cluster-config-file nodes-6379.conf
# cluster-node-timeout 15000
# cluster-slave-validity-factor 10
# cluster-migration-barrier 1
# cluster-require-full-coverage yes
################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 128
################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0
############################# EVENT NOTIFICATION ##############################
notify-keyspace-events ""
############################### ADVANCED CONFIG ###############################
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
2、从节点slave1的配置文件redis_slave_6315.config:
# Redis configuration file example
################################## INCLUDES ###################################
# include /path/to/local.conf
# include /path/to/other.conf
################################ GENERAL #####################################
daemonize yes
pidfile ./run/redis_slaver1_6315.pid
port 6315
tcp-backlog 511
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1
# unixsocket /tmp/redis.sock
# unixsocketperm 700
timeout 0
tcp-keepalive 0
loglevel notice
logfile "./run/logs/log_slaver1_6315.log"
databases 16
################################ SNAPSHOTTING ################################
save ""
# save 900 1
# save 300 10
# save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum no
dbfilename dump_6315.rdb
dir ./run/data
################################# REPLICATION #################################
slaveof 192.168.0.12 6301
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
# repl-ping-slave-period 10
# repl-timeout 60
repl-disable-tcp-nodelay no
# repl-backlog-size 1mb
# repl-backlog-ttl 3600
slave-priority 80
# min-slaves-to-write 3
# min-slaves-max-lag 10
################################## SECURITY ###################################
# rename-command CONFIG ""
################################### LIMITS ####################################
# maxclients 10000
# maxmemory <bytes>
# maxmemory-policy noeviction
# maxmemory-samples 5
############################## APPEND ONLY MODE ###############################
appendonly no
appendfilename "appendonly_6315.aof"
appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
################################ LUA SCRIPTING ###############################
lua-time-limit 5000
################################ REDIS CLUSTER ###############################
# cluster-enabled yes
# cluster-config-file nodes-6379.conf
# cluster-node-timeout 15000
# cluster-slave-validity-factor 10
# cluster-migration-barrier 1
# cluster-require-full-coverage yes
################################## SLOW LOG ###################################
slowlog-log-slower-than 10000
slowlog-max-len 128
################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0
############################# EVENT NOTIFICATION ##############################
notify-keyspace-events ""
############################### ADVANCED CONFIG ###############################
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
3、从节点slave2的配置文件redis_slave_6316.config:
与上面slave1配置文件需要修改的地方
pidfile ./run/redis_slaver1_6316.pid
port 6316
logfile "./run/logs/log_slaver1_6316.log"
dbfilename dump_6316.rdb
appendfilename "appendonly_6316.aof"
4、从节点slave3的配置文件redis_slave_6317.config:
与上面slave1配置文件需要修改的地方
pidfile ./run/redis_slaver1_6317.pid
port 6317
logfile "./run/logs/log_slaver1_6317.log"
dbfilename dump_6317.rdb
appendfilename "appendonly_6317.aof"
5、哨兵sentinel1的配置文件sentinel_26301.config:
# Example sentinel.conf
port 26301
# sentinel announce-ip 1.2.3.4
dir ./run/tmp
sentinel monitor master1 192.168.0.12 6301 2
# sentinel auth-pass mymaster MySUPER--secret-0123passw0rd
# sentinel down-after-milliseconds <master-name> <milliseconds>
sentinel down-after-milliseconds master1 30000
sentinel parallel-syncs master1 1
sentinel failover-timeout master1 180000
# sentinel notification-script mymaster /var/redis/notify.sh
# sentinel client-reconfig-script mymaster /var/redis/reconfig.sh
# sentinel can-failover master1 yes
logfile "/redis-3.0.0/run/logs/sentinellog_m1_26301.log"
6、哨兵sentinel2的配置文件sentinel_26302.config:
# Example sentinel.conf
port 26302
# sentinel announce-ip 1.2.3.4
dir ./run/tmp
sentinel monitor master1 192.168.0.12 6301 2
# sentinel auth-pass mymaster MySUPER--secret-0123passw0rd
# sentinel down-after-milliseconds <master-name> <milliseconds>
sentinel down-after-milliseconds master1 30000
sentinel parallel-syncs master1 1
sentinel failover-timeout master1 180000
# sentinel notification-script mymaster /var/redis/notify.sh
# sentinel client-reconfig-script mymaster /var/redis/reconfig.sh
# sentinel can-failover master1 yes
logfile "/redis-3.0.0/run/logs/sentinellog_m1_26302.log"
7、哨兵sentinel3的配置文件sentinel_26303.config:
# Example sentinel.conf
port 26303
# sentinel announce-ip 1.2.3.4
dir ./run/tmp
sentinel monitor master1 192.168.0.12 6301 2
# sentinel auth-pass mymaster MySUPER--secret-0123passw0rd
# sentinel down-after-milliseconds <master-name> <milliseconds>
sentinel down-after-milliseconds master1 30000
sentinel parallel-syncs master1 1
sentinel failover-timeout master1 180000
# sentinel notification-script mymaster /var/redis/notify.sh
# sentinel client-reconfig-script mymaster /var/redis/reconfig.sh
# sentinel can-failover master1 yes
logfile "/redis-3.0.0/run/logs/sentinellog_m1_26303.log"
````
# 启动redis和哨兵服务
```yaml
注意:第一次要先启动redis主服务、从服务,然后才能启动哨兵服务
1、进入redis安装目录的根目录
2、启动redis主节点
[root@localhost redis-3.0.0]# redis-server redis_master_6301.config &
3、启动redis从节点
[root@localhost redis-3.0.0]# redis-server redis_slave_6315.config &
[root@localhost redis-3.0.0]# redis-server redis_slave_6316.config &
[root@localhost redis-3.0.0]# redis-server redis_slave_6317.config &
4、启动哨兵
[root@localhost redis-3.0.0]# redis-sentinel sentinel_26301.config &
[root@localhost redis-3.0.0]# redis-sentinel sentinel_26302.config &
[root@localhost redis-3.0.0]# redis-sentinel sentinel_26303.config &
到目前为止整个redis+sentinel的安装搭建环境就算完成
`

常用命名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
进入redis的安装目录
启动redis-server:
./redis-server redis_6305.conf &
启动redis-sentinel
./redis-sentinel sentinel_6301.config
./redis-server sentinel_6316.conf --sentinel &
查看某个端口信息:
./redis-cli -p 6301 info
./redis-cli -p 6301 info Replication
./redis-cli -p 6301 info Sentinel
查看某个主机上的信息redis信息
./redis-cli -h 10.16.41.52 -p 6316 info
./redis-cli -h 10.16.41.52 -p 6316 info Replication
./redis-cli -h 10.16.41.52 -p 6316 info Sentinel
关闭本机redis服务
./redis-cli -p 6379 shutdown
关闭远程主机redis服务
./redis-cli -h 192.168.9.18 -p 6379 shutdown
客户端连接本机
./redis-cli -p 6301
客户端连接远程机
./redis-cli -h 10.16.41.53 -p 6301
切换连接
ssh app@10.16.41.52
使用命令关闭RDB持久化
`

logback 日志配置

写入文件配置

1
2
3
4
5
6
7
8
9
10
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>90</maxHistory>
</rollingPolicy>
<encoder>
<charset>utf-8</charset>
<Pattern>%d %-5level [%thread] %logger{0}: %msg%n</Pattern>
</encoder>
</appender>

写入mysql数据库配置

1
2
3
4
5
6
7
8
9
10
11
12
<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
<!--日志异步到数据库 -->
<connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
<!--连接池 -->
<dataSource class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<driverClassName>com.mysql.jdbc.Driver</driverClassName>
<url>jdbc:mysql://localhost:3306/DB</url>
<username >root</username>
<password>root</password>
</dataSource>
</connectionSource>
</appender>

写入控制台配置

1
2
3
4
5
6
7
8
9
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- 日志输出编码 -->
<Encoding>UTF-8</Encoding>
<layout class="ch.qos.logback.classic.PatternLayout">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
</pattern>
</layout>
</appender>

异步写入

<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
      <queueSize>512</queueSize>
      <appender-ref ref="FILE"/>
</appender>