CentOS系统安装配置svn服务器

今天看大神的博客部署了一下svn,期间遇到各种问题,特写此博客重新将svn在centos下的部署和各种问题的解决方案重新旅顺一下。

一、下载svn

yum install -y subversion

二、验证是否安装成功

svnserve --version

出现版本号说明安装成功了~

三、创建svn版本库

mkdir /var/svn #我这里把版本库放在了var目录下的svn文件夹,方便管理  
svnadmin create /var/svn/repo0 #我这里将svn作为所有版本库的目录,并创建了一个名为repo0的版本库

四、配置当前版本库

创建版本库后,在当前版本库目录中会生成下面的文件,其中我们关心的是配置文件。

[root@localhost svn]# ls  
repo0  
[root@localhost svn]# cd repo0  
[root@localhost repo0]# ls  
conf  db  format  hooks  locks  README.txt  
[root@localhost repo0]# pwd  
/var/svn/repo0  
[root@localhost repo0]# cd conf  
[root@localhost conf]# ls -a  
.  ..  authz  passwd  svnserve.conf

修改passwd文件

passwd文件管理svn用户密码

### This file is an example password file for svnserve.
### Its format is similar to that of svnserve.conf. As shown in the
### example below it contains one section labelled [users].
### The name and password for each user follow, one account per line.

[users]
# harry = harryssecret
# sally = sallyssecret
user0 = user0passwd

修改authz文件

authz文件管理用户组及权限认证,读写控制认证等

### This file is an example authorization file for svnserve.
### Its format is identical to that of mod_authz_svn authorization
### files.
### As shown below each section defines authorizations for the path and
### (optional) repository specified by the section name.
### The authorizations follow. An authorization line can refer to:
###  - a single user,
###  - a group of users defined in a special [groups] section,
###  - an alias defined in a special [aliases] section,
###  - all authenticated users, using the '$authenticated' token,
###  - only anonymous users, using the '$anonymous' token,
###  - anyone, using the '*' wildcard.
###
### A match can be inverted by prefixing the rule with '~'. Rules can
### grant read ('r') access, read-write ('rw') access, or no access
### ('').

[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average
[groups]
team0=user0 #这里代表将user0分在了team0这个小组中
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
[/]
@team0=rw  #服务team0用户组读写权限
# [/foo/bar]
# harry = rw
# &joe = r
# * =

# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r

修改svnserve.conf文件

[general]  
### These options control access to the repository for unauthenticated  
### and authenticated users.  Valid values are "write", "read",  
### and "none".  The sample settings below are the defaults.  
anon-access = none #没有登录的用户不能访问  
auth-access = write #登录的用户可以写入  
### The password-db option controls the location of the password  
### database file.  Unless you specify a path starting with a /,  
### the file's location is relative to the directory containing  
### this configuration file.  
### If SASL is enabled (see below), this file will NOT be used.  
### Uncomment the line below to use the default password file.  
password-db = passwd #密码文件为当前目录下的passwd  
### The authz-db option controls the location of the authorization  
### rules for path-based access control.  Unless you specify a path  
### starting with a /, the file's location is relative to the the  
### directory containing this file.  If you don't specify an  
### authz-db, no path-based access control is done.  
### Uncomment the line below to use the default authorization file.  
authz-db = authz #验证文件为当前目录下的authz

五、停止和启动svn

启动svn

svnserve -d -r /var/svn/

关闭svn

ps -aux |grep svn  
kill -9 进程id

六、导入导出工程

导入工程

$ mkdir MyProject    
$ mkdir MyProject/trunk    
$ mkdir MyProject/branches    
$ mkdir MyProject/tags    
svn import MyProject svn://**svn服务器外网ip**/repo0/MyProject -m "first import project"

导出工程

svn co svn://**svn服务器外网ip**/repo0/MyProject

七、常见错误异常

注:可以使用systemctl status svnserve.service来查看svn当前状态

Authorization failed

svn://192.168.20.242/MyProject1,然后要求输入用户名和密码。如果用户名和密码输入出错了,强行确定后。问题来了!会出现,以下错误信息:

org.tigris.subversion.javahl.ClientException
Authorization failed

这时要清理一下svn用户登录缓存

rm ~/.subversion/auth

svn导入文件时的编码问题

遇到

svn: Valid UTF-8 data 
(hex: 47 64 20 53 63) 
followed by invalid UTF-8 sequence 
(hex: e9 6e 69 63)

或者

svn Error normalizing log message to internal format

这样的错误的原因是所提交的文件中包含非utf8的编码,进入configrm

vim ~/.subversion/config

修改log-encoding值为你文件的编码

[miscellany]
### Set global-ignores to a set of whitespace-delimited globs
### which Subversion will ignore in its 'status' output, and
### while importing or adding files and directories.
### '*' matches leading dots, e.g. '*.rej' matches '.foo.rej'.
# global-ignores = *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo
#   *.rej *~ #*# .#* .*.swp .DS_Store
### Set log-encoding to the default encoding for log messages
log-encoding = binary
### Set use-commit-times to make checkout/update/switch/revert
### put last-committed timestamps on every file touched.
# use-commit-times = yes
### Set no-unlock to prevent 'svn commit' from automatically
### releasing locks on files.
# no-unlock = yes
### Set mime-types-file to a MIME type registry file, used to
### provide hints to Subversion's MIME type auto-detection
### algorithm.
# mime-types-file = /path/to/mime.types
### Set preserved-conflict-file-exts to a whitespace-delimited

当然你也可以给文件转编码

总结:svn配置过程中由于系统环境和版本问题会遇到各种突发问题,多百度谷歌stackoverflow就好了。

修改TortoiseSVN svn保存的帐号密码

如果装了TortoiseSVN:

Settings -> Saved Data -> Authentication Data -> clear。即可清除保存的上个用户登录信息;当再次用到svn时,会提示输入用户名密码,输入新的用户名密码即可。

或者,手动删除下面目录下的svn登录用户信息保存文件:

C:Documents and SettingsjavaLeeApplication DataSubversionauthsvn.simple

通过TortoiseSVN的clear Authentication Data和手动删除效果是一模一样的!都是对userNameApplication DataSubversionauthsvn.simple目录下的已保存登录用户信息文件进行删除。

未分类

未分类

git fatal: 拒绝合并无关的历史的错误解决

问题描述

本地初始化的项目 与 github 版本不一致, 导致无法提交

$ git pull origin master
来自 https://github.com/itaken/python-login-demo
 * branch            master     -> FETCH_HEAD
fatal: 拒绝合并无关的历史

解决方法

在pull 时候, 添加–allow-unrelated-histories参数 即可.

$ git pull origin master --allow-unrelated-histories                    129 ↵
来自 https://github.com/itaken/python-login-demo
 * branch            master     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 LICENSE | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 LICENSE

Git add commit误操作撤销的方法

概述

在平时工作中使用git难免会提交一些错误的文件到git库里,这时候,撤销吧,怕把正确的文件删除了,不撤销重新改又很麻烦,下面,我就从提交的三个阶段,来讲解如何撤销错误的操作。

Git Add了一个错误文件

解决方法

这种情况一般发生在新创建的项目,执行命令:

git add .

命令执行完后发现增加了错误的文件,比如Pycham自动生成的.idea文件夹。比如下图:

未分类

这时候,我想撤销add .idea这个操作,可以这么做:

git reset <file> #撤销指定的文件
git reset #撤销所有的文件

执行完这个命令后,效果如下:

未分类

可以看到.idea这个目录变成了Untracked了。完美解决。 如果你在执行的时候遇到如下的错误:

fatal: Failed to resolve 'HEAD' as a valid ref.

如果遇到这个错误,就说明你的本地git仓库从来没有执行过git commit操作,导致HEAD指针不存在。这时候你可以通过如下的命令撤销操作:

git rm --cached .   #删除文件
git rm -r --cached . #删除文件和目录

如何避免

.gitignore: 把不需要提交的文件增加到这个文件
git add : 增加指定的文件,少用点号

Git Commit了一个错误文件

举例

我现在有个文件的状态如下:

未分类

执行git diff blog-test.py后结果如下:

未分类

可以看到我增加了一行,现在把文件提交到本地仓库:

未分类

可以看到,本地以及没有需要提交的文件了。这时候,我发现,这个修改是错误的,我需要撤销这次commit,我该怎么做了?

只撤销commit操作,保留文件

执行命令如下:

git reset HEAD~1

执行完效果如下:

未分类

可以看到,commit被撤销了,但是修改的部分还保留着。完美解决。不信看git log

未分类

撤销commit操作,删除变化

执行命令如下:

git reset --hard HEAD~1

执行完后效果如下:

未分类

可以看到,我增加的那一行已经没有了,git log中也没有了那次的提交记录:

未分类

完美

如何避免

  • git status: 查看是否有不需要的文件被add进来
  • git diff: 查看文件的变化部分,是否是想提交的

查看更多

Git如何取消最新一次的commit: http://bbs.bugcode.cn/t/7

如何删除分支

好,现在有个很严重的问题,我的分支里代码不用了,现在要删除,怎么整。

分支没有push到远程

删除本地的分支很简单:

git branch -d branch_name

举例截图如下:

未分类

分支已经push到远程

我现在本地和远程都有一个test分支,如下图:

未分类
未分类

执行如下的命令删除本地和远程的test分支:

git push origin --delete test
git checkout master
git branch -d test
#git branch -D test 如果有未提交的文件,用它

执行完效果如下:

未分类
未分类

可以看到都删掉了。

总结

出错不可怕,可怕的是你不知道为什么出错以及如何修复错误。所谓亡羊补牢,为时未晚。

zabbix通过stub_status模块实现对nginx的监控

原理

nginx的ngx_http_stub_status_module模块提供了基本的nginx状态信息,源码安装的话需要加上–with-http_stub_status_module编译参数,或者如果是epel源yum安装的话,已经默认启用该模块。在nginx.conf的server段中添加:

location /basic_status {
    stub_status;
    access_log off;
}

那么访问http://xxx.com/basic_status就可以得到7个nginx运行信息了:

Active connections: 291 
server accepts handled requests
 16630948 16630948 31070465 
Reading: 6 Writing: 179 Waiting: 106

各项含义摘抄如下:

Active connections  The current number of active client connections including Waiting connections.

accepts  The total number of accepted client connections.

handled  The total number of handled connections. Generally, the parameter value is the same as acceptsunless some resource limits have been reached (for example, the worker_connections limit).

requests  The total number of client requests.

Reading  The current number of connections where nginx is reading the request header.

Writing  The current number of connections where nginx is writing the response back to the client.

Waiting  The current number of idle client connections waiting for a request.

Active connections/Reading/Writing/Waiting 是状态量,体现了nginx当前的运行状态,需要重点关注。

accepts/handled/requests是统计量,是个历史计数器,其中requests可以反映出“吞吐量”的概念,accepts和handled的差值可以反映出“丢包量”,即nginx由于某种原因丢弃的连接。

由此可以看出,zabbix监控nginx就是通过搜集以上数据,并稍作加工,形成图表供分析。

自定义脚本

zabbix可以通过自定义参数收集自定义信息,详见:https://www.zabbix.com/documentation/3.2/manual/config/items/userparameters

首先需要一个脚本,得到所需数据,然后通过zabbix-agent传给zabbix-server。有几点思路:

1、使用shell脚本即可,简单实用,跟操作系统紧密结合。

2、因为有很多监控项,如果写多个脚本会很乱,最好写成函数形式。

3、直接取accepts和handled的值没什么实际意义,它们的差值表示连接丢弃数量才是我们关心的。但是,这个计算不能放在zabbix-server中进行(item type — Calculation),因为zabbix在取两个值的时候有时间差,而这个时间差得到的结果会导致计算误差。所以必须在shell中算好,直接返回给zabbix-server。

ngx_status.sh代码如下:

#!/bin/bash

URL="http://192.168.7.227:88/ngx_status"
FILE="/tmp/ngx_status.txt"

function active(){
/usr/bin/curl -s $URL |grep Active|awk '{print $3}'
}

function reading(){
/usr/bin/curl -s $URL |grep Reading|awk '{print $2}'
}

function writing(){
/usr/bin/curl -s $URL |grep Writing|awk '{print $4}'
}

function waiting(){
/usr/bin/curl -s $URL |grep Waiting|awk '{print $6}'
}

function requests(){
/usr/bin/curl -s $URL |awk '{if(NR==3) print $3}'
}

function dropped(){
/usr/bin/curl -s $URL > $FILE
accepts=`awk '{if(NR==3) print $1}' $FILE`
handled=`awk '{if(NR==3) print $2}' $FILE`
drop=`expr $accepts - $handled`
echo "$drop"
}

function ping(){
/usr/sbin/pidof nginx|wc -l
}

#根据脚本参数执行对应应函数
$1

zabbix-agent端添加以下配置:

# cat /etc/zabbix/zabbix_agentd.d/nginx_status.conf
UserParameter=nginx.status[*],/etc/zabbix/zabbix_agentd.d/nginx_status.sh $1

创建zabbix模版

active/reading/writing/waiting/requests都是一样的,方法如下:

未分类

吞吐量是由计算得出:

未分类

上面使用计算的方法没必要,官方已经提供了内置的delta数据类型来处理此类需求:

未分类

nginx存活状态是个布尔量,创建方法:

未分类

未分类

可以对这个item配置trigger,当nginx挂了做相应操作。

最后,我们可以创建几个图表,方便分析,因为是测试环境,基本没啥访问量^_^:

未分类

模版文件,适用于zabbix-3.2.7-1:https://github.com/dmli30/shell/blob/master/zabbix/ngx_status_templates.xml

Zabbix 3.2.1运行在PHP 7.1.7出现的问题解决

安装完成用admin账号登陆后,出现红色的框框显示这个:

A non well formed numeric value encountered [zabbix.php:21 → require_once() → ZBase->run() → ZBase->processRequest() → CView->getOutput() → include() → make_status_of_zbx() → CFrontendSetup->checkRequirements() → CFrontendSetup->checkPhpMemoryLimit() → str2mem() in include/func.inc.php:410]
A non well formed numeric value encountered [zabbix.php:21 → require_once() → ZBase->run() → ZBase->processRequest() → CView->getOutput() → include() → make_status_of_zbx() → CFrontendSetup->checkRequirements() → CFrontendSetup->checkPhpPostMaxSize() → str2mem() in include/func.inc.php:410]
A non well formed numeric value encountered [zabbix.php:21 → require_once() → ZBase->run() → ZBase->processRequest() → CView->getOutput() → include() → make_status_of_zbx() → CFrontendSetup->checkRequirements() → CFrontendSetup->checkPhpUploadMaxFilesize() → str2mem() in include/func.inc.php:410]

网上查了一下,这是因为PHP 7.1.7类型强化,处理方法是找到Zabbix WEB目录下include/func.inc.php文件,修改它

sed -i '/$last = strtolower(substr($val, -1));/a$val = substr($val,0,-1);' func.inc.php

问题依然未能解决,后来查看了一下func.inc.php代码,跳转到报错的位置#410,通过网上的解决方法分析,应该是val这个变量类型问题,在403行后添加一行$val = substr($val,0,-1); 保存修改后的文件,重新访问zabbix web界面即可。

ZABBIX忘记登录密码重置方法

未分类

刚刚在群里吹牛逼,由于账号比较多,脑子容易瓦特. 结果忘记自己的zabbix登录密码下面是找回登录密码的例子

未修改之前(忘记登录密码)
[root@abcdocker ~]# mysql -uroot -p -e "select * from zabbix.usersG"
Enter password: 
*************************** 1. row ***************************
            userid: 1
             alias: Admin
              name: Zabbix
           surname: Administrator
            passwd: ab66b6e18854fa4d45499d0a04a47b64
               url: 
         autologin: 1
        autologout: 0
              lang: en_GB
           refresh: 30
              type: 3
             theme: default
    attempt_failed: 0
        attempt_ip: 14.130.112.2
     attempt_clock: 1501141026
     rows_per_page: 50

登录MySQL 修改密码

[root@abcdocker ~]# mysql -uroot -p
由于密码是md5加密的,我们可以查看默认的zabbix密码的md5
mysql> use zabbix;
mysql> update users set passwd='5fce1b3e34b520afeffb37ce08c7cd66' where userid='1';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
解释:5fce1b3e34b520afeffb37ce08c7cd66  = zabbix
因为zabbix默认密码就是zabbix

登录 Web

用户名:Admin
密码:zabbix

未分类

提示:登陆上请马上修改密码

未分类

未分类

完!

zabbix添加cpu使用率图形监控

zabbix版本: 3.2.5

zabbix 自带的windows模板中没有监控cpu使用率的,可以在模板里自己添加

1、配置 —> 模板—> Template OS Windows

2、监控项 —-> 添加监控项

未分类

应用集 : CPU

3、图形 —-> 添加图形

取个名称, 监控项选择刚才的新建的

未分类

4、添加触发器

模板 —> Template OS Windows —> 触发器

未分类

{Template OS Windows:system.cpu.util[,,].avg(5m)}>85

Zabbix 3.2.6通过SNMP和iDRAC监控DELL服务器

一、总览

SNMP是监控服务器以外设备的非常好的方式,比如可以用于监控打印机、交换机、路由器等,只要是有SNMP功能,Zabbix都可以监控。

SNMP检查是通过UDP协议,从Zabbix 2.2.3开始,一次SNMP请求可以查询设备的多个值,覆盖到SNMP的所有项目值,这样是SNMP进程变得更加高效,从Zabbix 2.4开始,在创建SNMP接口的地方有一个”Use bulk requests”的选项,可以禁用对它不适用的设备。

iDRAC又称为Integrated Dell Remote Access Controller,也就是集成戴尔远程控制卡,iDRAC卡相当于是附加在服务器上的一台小电脑,通过与服务器主板上的管理芯片BMC进行通信,监控与管理服务器的硬件状态信息。它拥有自己的系统和IP地址,与服务器上的OS无关。是管理员进行远程访问和管理的利器

二、安装配置Zabbix server

1、编译zabbix server支持

要想支持通过SNMP监控服务器信息,需要在编译的时候加上参数–with-net-snmp,解决依赖需要安装如下软件包。

yum -y install net-snmp-devel

2、配置DELL管理卡

登录远程管理卡,如下

未分类

登录之后单击 —> iDRAC设置 —> 网络 —> 服务 —> SNMP代理,以下几个参数zabbix会用到。

已启用              √ 
SNMP团体名称       wzlinux 
SNMP协议          所有(SNMP v1/2/3) 
SNMP查找端口号     161

未分类

3、zabbix 服务端通过snmp验证

我们使用的工具是snmpget,需要安装如下软件包支持。

yum -y install net-snmp-utils

使用如下指令简单验证一下,我们使用SNMPv2版本。

snmpget -v 2c -c <Community> <iDRAC IP> .1.3.6.1.4.1.674.10892.2.1.1.2.0
# snmpget -v 2c -c wzlinux 10.0.0.99 .1.3.6.1.4.1.674.10892.2.1.1.2.0
SNMPv2-SMI::enterprises.674.10892.2.1.1.2.0 = STRING: "iDRAC8"

三、配置Zabbix WEB端

1、创建值映射

通常需要创建以下值映射,zabbix 3.0以上版本使用我附件的模板可以自动创建。

Menu: Administration->General->Value mapping->Create value map
  • DellDracDiskState
1 -> Unknown
2 -> Ready
3 -> Online
4 -> Foreign
5 -> Offline
6 -> Blocked
7 -> Failed
8 -> Non-RAID
9 -> Removed
  • Dell iDRAC Network Device Connection Status
1 -> Connected
2 -> Disconnected
Dell Open Manage System Status
1 -> Other
2 -> Unknown
3 -> OK
4 -> NonCritical
5 -> Critical
6 -> NonRecoverable
  • DellPowerState
1 -> Other
2 -> Unknown
3 -> Off
4 -> On
  • Dell PSU State Settings
1 -> Unknown
2 -> Online (state disabled)
4 -> not Ready
8 -> Fan Failure
10 -> Online and Fan Failure
16 -> On
242 -> Online and OK
  • DellRaidLevel
1 -> Unknown
2 -> RAID-0
3 -> RAID-1
4 -> RAID-5
5 -> RAID-6
6 -> RAID-10
7 -> RAID-50
8 -> RAID-60
9 -> Concatenated RAID 1
10 -> Concatenated RAID 5
  • DellRaidVolumeState
1 -> Unknown
2 -> Online
3 -> Failed
4 -> Degraded
  • Dell_PSU_SensorState
1 -> Presence Detected
2 -> PS Failure
4 -> Predictuve Failure
8 -> PS AC lost
16 -> AC lost or out of range
32 -> AC out of range but still present

2、配置全局变量{$SNMP_COMMUNITY_IDRAC}

Menu:Administration->General->Macros

Value处填写iDRAC的WEB上配置的SNMP团体名(Community)

未分类

3、导入模板

模板见本文附件,“Template Dell iDrac SNMPV2 zbx2.2.xml”支持zabbix2.2版本,“Template Dell iDrac SNMPV2 zbx3.xml”支持zabbix3版本。

Menu:Configuration->Templates->Import,导入“Template Dell iDrac SNMPV2”模板。

未分类

4、创建主机

Menu:Configuration->Hosts->Create host

未分类

未分类

四、验证

经过一段时间,我们可以看到SNMP正常监控了,自带模板没有Graphs,可以自己创建需要监控的项目查看。

未分类

未分类

使用percona-xtrabackup(innobackupex)工具快速配置mysql5.6.34主从同步复制

percona-xtrabackup工具实现mysql5.6.34的主从同步复制

未分类

下载并安装percona-xtrabackup工具

# wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.7/binary/redhat/6/x86_64/percona-xtrabackup-24-2.4.7-1.el6.x86_64.rpm

# yum localinstall -y percona-xtrabackup-24-2.4.7-1.el6.x86_64.rpm

1、备份,将MySQL数据库整个备份到/opt/目录下

# innobackupex --defaults-file="/etc/my.cnf" --user=root -proot --socket=/tmp/mysql.sock /opt

2、预处理,进行事物检查(也可以拷贝到从库后再进行检查)

# innobackupex --defaults-file="/etc/my.cnf" --user=root -proot --socket=/tmp/mysql.sock --apply-lg --use-memory=1G /opt/2017-05-18_00-13-42/

3、scp到从库

[root@centossz008 ~]# scp -r /opt/2017-05-18_01-34-42/ 192.168.3.13:/opt

4、关闭从库,清理从库数据,恢复数据到从库

/etc/init.d/mysqld stop

删除从库的数据和日志信息

[root@node5 ~]# rm -rf /data/mydata/*
[root@node5 ~]# rm -rf /data/binlogs/*
[root@node5 ~]# rm -rf /data/relaylogs/*

在从库上执行(将数据恢复到数据库中)

[root@node5 ~]# innobackupex --defaults-file="/etc/my.cnf" --user=root --socket=/tmp/mysql.sock --move-back /opt/2017-05-18_01-34-42/

5、修改权限,启动从库

[root@node5 mydata]# chown -R mysql.mysql /data
[root@node5 mydata]# /etc/init.d/mysqld start

查看主库中master位置

[root@node5 mydata]# cat /opt/2017-05-18_01-34-42/xtrabackup_binlog_info 
master-bin.000002    191    4c6237f8-a7da-11e6-9966-000c29f333f8:1-2

6、主库中创建建salve同步用户

mysql> grant replication slave,reload,super on *.* to [email protected] identified by 'replpass';
mysql> FLUSH PRIVILEGES;

7、从库执行同步

mysql> change master to master_host='192.168.3.12',master_user='repluser',master_password='replpass',master_log_file='master-bin.000002',master_log_pos=191;
mysql> start slave;

mysql> show slave statusG
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.3.12
Master_User: repluser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000002
Read_Master_Log_Pos: 586
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 710
Relay_Master_Log_File: master-bin.000002
Slave_IO_Running: Yes # 表示配置成功
Slave_SQL_Running: Yes
Replicate_Do_DB: 
Replicate_Ignore_DB: 
Replicate_Do_Table: 
Replicate_Ignore_Table: 
Replicate_Wild_Do_Table: 
Replicate_Wild_Ignore_Table: 
Last_Errno: 0
Last_Error: 
Skip_Counter: 0
Exec_Master_Log_Pos: 586
Relay_Log_Space: 908
Until_Condition: None
Until_Log_File: 
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File: 
Master_SSL_CA_Path: 
Master_SSL_Cert: 
Master_SSL_Cipher: 
Master_SSL_Key: 
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error: 
Last_SQL_Errno: 0
Last_SQL_Error: 
Replicate_Ignore_Server_Ids: 
Master_Server_Id: 100
Master_UUID: 4c6237f8-a7da-11e6-9966-000c29f333f8
Master_Info_File: /data/mydata/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind: 
Last_IO_Error_Timestamp: 
Last_SQL_Error_Timestamp: 
Master_SSL_Crl: 
Master_SSL_Crlpath: 
Retrieved_Gtid_Set: 4c6237f8-a7da-11e6-9966-000c29f333f8:3-4
Executed_Gtid_Set: 4c6237f8-a7da-11e6-9966-000c29f333f8:3-4
Auto_Position: 0
1 row in set (0.00 sec)

延迟复制:

启用方法:

mysql> stop slave;
mysql> change master to master_delay=600;
mysql> start slave;

应用场景:

1、误删除恢复
2、延迟测试(当有延迟时业务是否会受影响)
3、历史查询

mysql master 配置

[root@centossz008 ~]# cat /etc/my.cnf 
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4

[mysqld]
port = 3306
innodb_file_per_table = 1
binlog-format=ROW
log-slave-updates=true
gtid-mode=on 
enforce-gtid-consistency=true
master-info-repository=file
relay-log-info-repository=file
sync-master-info=1
slave-parallel-workers=4
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
server-id=100
report-port=3306
log-bin=/data/binlogs/master-bin
max_binlog_size = 200M
datadir=/data/mydata
socket=/tmp/mysql.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4

skip-name-resolve
skip-external-locking

back_log = 300
max_connections = 1024
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M

read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 16M
query_cache_limit = 2M
ft_min_word_len = 4
expire_logs_days = 10
performance_schema = 0
explicit_defaults_for_timestamp

default_storage_engine = InnoDB
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 4
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120

bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 512M
myisam_repair_threads = 1

interactive_timeout = 28800
wait_timeout = 28800

[mysqldump]
quick
max_allowed_packet = 16M

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M

mysql slave 配置

[root@node5 src]# cat /etc/my.cnf 
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4

[mysqld]

port = 3306
innodb_file_per_table = 1
binlog-format=ROW
log-slave-updates=true
gtid-mode=on 
enforce-gtid-consistency=true
master-info-repository=file
relay-log-info-repository=file
sync-master-info=1
slave-parallel-workers=4
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
server-id=200
report-port=3306
log-bin=/data/binlogs/master-bin
relay-log=/data/relaylogs/relay-bin
max_binlog_size = 200M
datadir=/data/mydata
socket=/tmp/mysql.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4

skip-name-resolve
skip-external-locking

back_log = 300
max_connections = 1024
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M

read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 16M
query_cache_limit = 2M
ft_min_word_len = 4
expire_logs_days = 10
performance_schema = 0
explicit_defaults_for_timestamp

default_storage_engine = InnoDB
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 4
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120

bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 512M
myisam_repair_threads = 1

interactive_timeout = 28800
wait_timeout = 28800

[mysqldump]
quick
max_allowed_packet = 16M

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M

cenos6上启动mysql服务报错:

070517 23:08:52 mysqld_safe Starting mysqld daemon with databases from /data/mydata
2107-05-17 23:08:56 0 [ERROR] This MySQL server doesn't support dates later then 2038
2107-05-17 23:08:56 0 [ERROR] Aborting

将时间修改为1年前,即可启动,启动完成后改回时间即可