2017-11-04 发布 v2.1.0版本
- 功能:支持设置详细的缓存条件
- 功能:支持免费的let’s encrypt https证书自动申请
2017-10-30 发布 v2.0.12版本
- 功能:新增http2支持
2017-10-29 发布 v2.0.2版本
- 功能:新增自动升级功能
2017-10-25 发布 v2.0.0-beta版本
- 功能:新增多节点支持
- 功能:支持控制面板管理反向代理网站
- 功能:新增自动开启防cc功能
- 功能:新增爬虫白名单
- 功能:新增监控中心,自动对域名和节点进行监控
由于工作需要,需要使用samba在windows下访问linux下的文件,主要是编译环境,linux下使用的是root用户,SSH登陆,而开发是在windows下,代码在windows下开发,为了开发的文件能方便共享,提高开发效率,就折腾了一下samba。
安装samba:yum install samba
开机启动:chkconfig smb on
chkconfig smb on
samba添加root用户访问:useradd root(默认已有)
smbpasswd -a root —后面输入密码
配置samba:(主要配置)
[chen]
comment = rogsm-build
path = /macc/chen
writable = yes
; public = yes
browseable = yes
valid users = root
create mask = 0777
重启samba:service smb restart;
service nmb restart
windows下清除共享用户名和密码:net use * /delete
windows下访问共享:\xx.xx.xx.xxxx
saltstack的state.sls和state.highstate之区别
state.sls默认的运行环境是base环境,但是它并不读取top.sls(top.sls定义了运行环境以及需要运行的sls)。关于state.sls的官方文档说明如下:
salt.modules.state.sls(mods, saltenv='base', test=None, exclude=None, queue=False, env=None,**kwargs)
这里saltenv指的是运行环境,默认是base环境。
state.highstate: 这个是全局的所有环境,以及所有状态都生效。它会读取每一个环境的top.sls,并且对所有sls都生效。
我只有一个base环境,这个base环境下的top.sls文件内容如下:
base:
'*':
- backup
- monitor
- sysctr
- slowlog
- offline
- conf
- statistics
- test
- shell
- dbmsdba
- dba-tools
top.sls文件并没有定义 – sync_dbconf这个sls。但是在base环境定义的目录下:
file_roots:
base:
- /data/dbms/salt
也就是/data/dbms/salt目录下,定义了sync_dbconf.sls文件,该sls定义是为了向minion下发特定的文件。
1)、使用state.highstate的时候
/data1/Python-2.7.4/bin/salt 'minion_xxxx' state.highstate
可以发现并没有将sync_dbconf.sls定义的文件下发到minion端
2)、使用state.sls的时候
/data1/Python-2.7.4/bin/salt 'minion_xxxx' state.sls sync_dbconf
发现可以将sync_dbconf.sls定义的文件下发到minion端
以上说明:
1、state.highstate会读取所有环境(包括base环境)的top.sls文件,并且执行top.sls文件内容里面定义的sls文件,不在top.sls文件里面记录的sls则不会被执行;
2、state.sls默认读取base环境,但是它并不会读取top.sls文件。你可以指定state.sls执行哪个sls文件,只要这个sls文件在base环境下存在;
3、state.sls也可以指定读取哪个环境:state.sls salt_env=’prod’ xxxx.sls,这个xxxx.sls可以不在top.sls中记录。
配置内容接上篇
server1 172.25.29.1 salt-master
server2 172.25.29.2 salt-minion haproy+keeplived
server3 172.25.29.3 salt-minion nginx
server4 172.25.29.4 salt-minion nginx
server5 172.25.29.5 salt-minion haproy+keeplived
做之前配置好本地解析
grains是minion第一次启动的时候采集的静态数据,可以用在salt的模块和其他组件中。其实grains在每次的minion启动(重启)的时候都会采集,即向master汇报一次的。
修改server3和server4的salt-minion,设定nginx角色

在server3和server4的/etc/salt下创建grains,内容如下







推送成功

1. 在master端创建_grains文件


2. 修改server3和server4的grains或者是删除grains文件,做到不影响下面master这边的grains



3. 向server3和server4同步grains

查看server3和server4的salt缓存


4. 修改top.sls推送文件

推送成功

grain和pillar区别
(1)grains存储的是静态、不常变化的内容,pillar则相反
(2)grains是存储在minion本地,而pillar存储在master本地
(3)minion有权限操作自己的grains值,如增加、删除,但minion只能查看自己的pillar,无权修改
修改server1上的master配置文件,开通pillar base目录,可以与grains共存


采集主机名





刷新

查看采集的推送项目,按照不同的主机名通过pillar下的web.sls做不同的事情




通过salt采集server3开启的服务

远程重启server3的nginx服务

将master server1上的文件群传给minion端

群查看minion的/tmp下的文件,已经传过来了

远程查看passwd文件

远程给server4安装htppd文档

远程给server4安装losf工具

Jinja是基于python的模板引擎,在saltstack中我们使用yaml_jinja渲染器来根据模板生产对应的配置文件,对于不同的操作系统或者不同的情况通过jinja可以让配置文件或者操作形成一种模板的编写方式。
模版文件里面变量使用{{名称}},例如{{PORT}}
变量使用Grains:{{ grains[‘fqdn_ip4’] }}
变量使用执行模块:{{ salt‘network.hw_addr’ }}
变量使用Pillar:{{ pillar[‘apache’][‘PORT’] }}
以httpd下的web.sls为例,添加模版,端口,地址


![]()



server3 httpd服务8080端口正常


在httpd.conf配置文件的最上面添加变量模块

下面的监听端口上按python的方式取值

在files下面新建 vim lib.sls

将之前的web.sls里的template下面注释掉

用jinja模版给server3推送httpd服务


将httpd.conf里刚才上面写的删除,因为会与下面的这个方法冲突

监听端口修改为下图所示

将web.sls文件修改为以下设置

vim lib.sls


进入到pillar的base目录下

(1)配置文件第一种写法

vim httpd.conf

(2)配置文件第二种写法

vim httpd.conf

推送

salt server4 state.sls httpd.web

1. 配置keepalived salt文件

vim keepalived.conf,添加vip

vim install.sls


vim service.sls

单击keepalived推送成功
2. 由于keepalived高可用,主备的配置文件不一样,需要添加jinja模版

在install.sls里添加jinja模版

keepalived.conf里的state和priority写成变量

3.新添加一台虚拟机server5做keepalived的高可用

将server5加入到salt-key


4. 修改top.sls文件并推送

5. 查看推送结果
haproy+keeplived正常启动,vip在主上

将主server2上的keepalived关闭,服务到备server5上

负载均衡haproxy正常


用户预置了多个规则组,其中一个规则组设置为默认。规则组有多条规则。
执行流程
– CDNFly首先查看用户是否有设置rule_name变量,如果有,则使用此变量指向的规则组名称,否则使用默认的规则组
– 遍历此规则组的规则。取出一条规则,使用此规则中的匹配器匹配请求,如果匹配失败,继续取下一条规则
– 如果匹配器匹配成功,检查此IP是否在黑名单,如果在,执行此规则中的动作。否则,使用此规则的过滤器验证一次请求,当验证失败达到一定次数时,把此IP加入到黑名单。
rsync命令的介绍和使用方法不在此介绍,本处仅记录在使用时如何跳过不想要的大目录。背景如下:
1、ubuntu服务器新增了1T硬盘;
2、需要同步原有home目录下的用户目录到新硬盘挂载的硬盘目录(/home2);
3、同步时跳过某一个用户(test)目录下的大文件目录(T3),需要跳过的目录全路径为”/home/test/T3″;
此时可以使用rsync的–exclude命令实现。直接上命令:
[html] view plain copy print?
sudo rsync -aux --exclude "test/T3" /home/ /home2/
需要注意的是–exclude之后的目录需要写相对路径(如例中的相对于/home目录的相对路径),而不能是全路径,否则无法跳过。
很多情况下我们会遇到服务器日志目录几十个G,或者附件目录过大的情况,如果我们使用常规的rm命令来进行删除的话,会非常慢。
但是rsync命令提供了这样一个功能,可以秒删。通过同步指令的–delete-before来删除目录
将空目录同步至非空目录
首先新建立一个空目录empty_dir,然后将空目录的内容同步到非空目录。
rsync --delete-before -a -H -v --progress --stats /www/webdev/newhouse/house/empty_dir /www/webdev/xxx.com/house/log
相关命令如下
--delete-before receiver deletes before transfer (default)
--delete-during receiver deletes during xfer, not before
--delete-delay find deletions during, delete after
--delete-after receiver deletes after transfer, not before
A. 要利用监控服务(inotify),监控同步数据服务器目录中信息的变化
B. 发现目录中数据产生变化,就利用rsync服务推送到备份服务器上
inotify+rsync 方式实现数据同步
sersync 方式实现实时数据同步

Inotify是一种强大的,细粒度的。异步的文件系统事件监控机制,linux内核从2.6.13起,加入了 Inotify支持,通过Inotify可以监控文件系统中添加、删除,修改、移动等各种事件,利用这个内核接口,第三方软件就可以监控文件系统下文件的各种变化情况,而 inotify-tools 正是实施这样监控的软件。国人周洋在金山公司也开发了类似的实时同步软件sersync。
提示信息:
sersync软件实际上就是在 inotify软件基础上进行开发的,功能要更加强大些 ,多了定时重传机制,过滤机制了提供接口做 CDN,支持多线程橾作。
Inotify实际是一种事件驱动机制,它为应用程序监控文件系统事件提供了实时响应事件的机制,而无须通过诸如cron等的轮询机制来获取事件。cron等机制不仅无法做到实时性,而且消耗大量系统资源。相比之下,inotify基于事件驱动,可以做到对事件处理的实时响应,也没有轮询造成的系统资源消耗,是非常自然的事件通知接口,也与自然世界事件机制相符合。
inotify的实现有几款软件:
inotify-tools,sersync,lrsyncd
inotify 对同步数据目录信息的监控
rsync 完成对数据信息的实时同步
利用脚本进行结合
需要2.6.13以后内核版本才能支持inotify软件。2.6.13内核之后版本,在没有安装inotify软件之前,应该有这三个文件。
[root@backup ~]# ll /proc/sys/fs/inotify/
total 0
-rw-r--r-- 1 root root 0 Oct 17 10:12 max_queued_events
-rw-r--r-- 1 root root 0 Oct 17 10:12 max_user_instances
-rw-r--r-- 1 root root 0 Oct 17 10:12 max_user_watches

[root@nfs01 ~]# man proc
/proc/sys/fs/inotify (since Linux 2.6.13)
This directory contains files max_queued_events,
max_user_instances, and max_user_watches, that can be used
to limit the amount of kernel memory consumed by the inotify interface.
for further details, see inotify(7).
通过man手册的第7级别中查到 inotify的默认文件的详细说明。
[root@nfs01 ~]# man 7 inotify
/proc/sys/fs/inotify/max_queued_events
The value in this file is used when an application calls
inotify_init(2) to set an upper limit on the number of
events that can be queued to the corresponding inotify
instance. Events in excess of this limit are dropped, but
an IN_Q_OVERFLOW event is always generated.
/proc/sys/fs/inotify/max_user_instances
This specifies an upper limit on the number of inotify
instances that can be created per real user ID.
/proc/sys/fs/inotify/max_user_watches
This specifies an upper limit on the number of watches
that can be created per real user ID.
1) yum install -y inotify-tools
2) 手工编译安装
注:
YUM 安装需要有epel源
http://mirrors.aliyun.com
手工编译安装方式需要到github上进行下载软件包
inotify软件的参考资料链接:
https://github.com/rvoicilas/inotify-tools/wiki
inotifywait: (主要)
在被监控的文件或目录上等待特定文件系统事件(open close delete等)发生,执行后处于阻塞状态,适合在shell脚本中使用
inotifywatch:
收集被监控的文件系统使用的统计数据,指文件系统事件发生的次数统计。
说明:在实时实时同步的时候,主要是利用inotifywait对目录进行监控


1.5.4.1 【实例】inotifywait监控中的事件测试
1、创建事件
[root@nfs01 data]# touch test2.txt
[root@nfs01 ~]# inotifywait -mrq /data --timefmt "%d-%m-%y %H:%M" --format "%T %w%f 事件信息: %e" -e create
17-10-17 11:19 /data/test2.txt 事件信息: CREATE
2、删除事件
[root@nfs01 data]# rm -f test1.txt
[root@nfs01 ~]# inotifywait -mrq /data --timefmt "%d-%m-%y %H:%M" --format "%T %w%f 事件信息: %e" -e delete
17-10-17 11:28 /data/test1.txt 事件信息: DELETE
3、修改事件
[root@nfs01 data]# echo "132" > test.txt
[root@nfs01 ~]# inotifywait -mrq /data --timefmt "%d-%m-%y %H:%M" --format "%T %w%f 事件信息: %e" -e close_write
17-10-17 11:30 /data/test.txt 事件信息: CLOSE_WRITE,CLOSE
4、移动事件 moved_to
[root@nfs01 data]# mv /etc/hosts .
[root@nfs01 ~]# inotifywait -mrq /data --timefmt "%d-%m-%y %H:%M" --format "%T %w%f 事件信息: %e" -e moved_to
17-10-17 11:33 /data/hosts 事件信息: MOVED_TO
移动事件 moved_from
[root@nfs01 data]# mv ./hosts /tmp/
[root@nfs01 ~]# inotifywait -mrq /data --timefmt "%d-%m-%y %H:%M" --format "%T %w%f 事件信息: %e" -e moved_from
17-10-17 11:34 /data/hosts 事件信息: MOVED_FROM


1.5.6.1 修改输出的日期格式
[root@nfs01 ~]# inotifywait -mrq /data --timefmt "%d/%m/%y %H:%M" --format "%T %w%f"
17/10/17 11:12 /data/test1.txt

对inotifywait命令测试的说明:
需要打开两个连接窗口
窗口对文件夹进行操作,可在一窗口中查看出inotifywait的监控记录
[root@nfs01 ~]# inotifywait /data
Setting up watches.
Watches established.
/data/ CREATE test1.txt
/data/ OPEN test1.txt
/data/ ATTRIB test1.txt
/data/ CLOSE_WRITE,CLOSE test1.txt
创建文件,inotifywait显示创建文件的过程↑
[root@nfs01 data]# touch test1.txt
[root@nfs01 data]# mkdir testdir
[root@nfs01 ~]#
/data/ CREATE,ISDIR testdir
[root@nfs01 data]# touch testdir/test01.txt
[root@nfs01 ~]# inotifywait -mrq /data
/data/testdir/ OPEN test01.txt
/data/testdir/ ATTRIB test01.txt
/data/testdir/ CLOSE_WRITE,CLOSE test01.txt
[root@nfs01 data]# sed 's#132#123#g' test.txt -i
[root@nfs01 ~]# inotifywait -mrq /data --timefmt "%d-%m-%y %H:%M" --format "%T %w%f 事件信息: %e" -e moved_from
/data/test.txt 事件信息: OPEN
/data/sedDh5R8v 事件信息: CREATE
/data/sedDh5R8v 事件信息: OPEN
/data/test.txt 事件信息: ACCESS
/data/sedDh5R8v 事件信息: MODIFY
/data/sedDh5R8v 事件信息: ATTRIB
/data/sedDh5R8v 事件信息: ATTRIB
/data/test.txt 事件信息: CLOSE_NOWRITE,CLOSE
/data/sedDh5R8v 事件信息: CLOSE_WRITE,CLOSE
/data/sedDh5R8v 事件信息: MOVED_FROM
/data/test.txt 事件信息: MOVED_TO
sed命令替换逻辑 :
将原文件内容放置到临时文件中,修改替换临时文件中的内容,原有文件不做改动
重命名临时文件,覆盖原文件
inotifywait -mrq /data --timefmt "%d/%m/%y %H:%M" --format "%T %w%f 事件信息: %e" -e create
说明:表示只监听create事件
inotifywait -mrq /data --timefmt "%d/%m/%y %H:%M" --format "%T %w%f 事件信息: %e"
说明:不指定-e参数,表示监听所有事件
# inotifywait -mrq /data --timefmt "%F %H:%M" --format "%T %w%f 事件信息: %@e" -e delete
2017-10-17 11:28 /data/02.txt 事件信息: DELETE
2017-10-17 11:28 /data/03.txt 事件信息: DELETE
2017-10-17 11:28 /data/04.txt 事件信息: DELETE
# inotifywait -mrq /data --timefmt "%F %H:%M" --format "%T %w%f 事件信息: %@e" -e delete,close_write
2017-10-17 11:30 /data/oldgirl.txt 事件信息: CLOSE_WRITE@CLOSE
2017-10-17 11:30 /data/.oldgirl.txt.swx 事件信息: CLOSE_WRITE@CLOSE
2017-10-17 11:30 /data/.oldgirl.txt.swx 事件信息: DELETE
2017-10-17 11:30 /data/.oldgirl.txt.swp 事件信息: CLOSE_WRITE@CLOSE
2017-10-17 11:30 /data/.oldgirl.txt.swp 事件信息: DELETE
2017-10-17 11:30 /data/.oldgirl.txt.swp 事件信息: CLOSE_WRITE@CLOSE
2017-10-17 11:30 /data/.oldgirl.txt.swp 事件信息: DELETE
inotifywait -mrq /data --timefmt "%F %H:%M" --format "%T %w%f 事件信息: %@e" -e delete,close_write,moved_to
2017-10-17 11:34 /data/hosts 事件信息: MOVED_TO

1)软件是否存在
[root@backup ~]# rpm -qa |grep rsync
rsync-3.0.6-12.el6.x86_64
需求:查询到某个命令非常有用。但是不知道属于哪个软件包
yum provides rysnc
provides Find what package provides the given value
2)进行软件服务配置
[root@backup ~]# vim /etc/rsyncd.conf
uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24
auth users = rsync_backup
secrets file = /etc/rsync.password
[backup]
comment = "backup dir by oldboy"
path = /backup
[nfsbackup]
comment = "nfsbackup dir by hzs"
path = /nfsbackup
3)创建rsync管理用户
[root@backup ~]# useradd -s /sbin/nologin -M rsync
4)创建数据备份储存目录,目录修改属主
[root@backup ~]# mkdir /nfsbackup/
[root@backup ~]# chown -R rsync.rsync /nfsbackup/
5)创建认证用户密码文件并进行授权600
echo "rsync_backup:oldboy123" >>/etc/rsync.password
chmod 600 /etc/rsync.password
6)启动rsync服务
rsync --daemon
至此服务端配置完成
[root@backup ~]# ps -ef |grep rsync
root 2076 1 0 17:05 ? 00:00:00 rsync --daemon
root 2163 1817 0 17:38 pts/1 00:00:00 grep --color=auto rsync
1)软件是否存在
[root@backup ~]# rpm -qa |grep rsync
rsync-3.0.6-12.el6.x86_64
2)创建安全认证文件,并进行修改权限600
echo "oldboy123" >>/etc/rsync.password
chmod 600 /etc/rsync.password
3) 测试数据传输
[root@nfs01 sersync]# rsync -avz /data [email protected]::nfsbackup --password-file=/etc/rsync.password
sending incremental file list
data/
data/.hzs
data/.tar.gz
data/.txt
首先先确认是否有epel源用来安装inotify-tools软件
[root@nfs01 ~]# yum repolist
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
repo id repo name status
base CentOS-6 - Base - mirrors.aliyun.com 6,706
epel Extra Packages for Enterprise Linux 6 - x86_64 12,401
extras CentOS-6 - Extras - mirrors.aliyun.com 46
updates CentOS-6 - Updates - mirrors.aliyun.com 722
repolist: 19,875
两种安装方式
1) yum install -y inotify-tools
2) 手工编译安装
注:
手工编译安装方式需要到github上进行下载软件包
inotify软件的参考资料链接:
https://github.com/rvoicilas/inotify-tools/wiki
[root@nfs01 ~]# rpm -ql inotify-tools
/usr/bin/inotifywait #主要
/usr/bin/inotifywatch
2.2.2.1 inotifywait和inotifywatch的作用:
一共安装了2个工具(命令),即inotifywait和inotifywatch
inotifywait : 在被监控的文件或目录上等待特定文件系统事件(open close delete等)发生,
执行后处于阻塞状态,适合在shell脚本中使用
inotifywatch :收集被监控的文件系统使用的统计数据,指文件系统事件发生的次数统计。
说明:yum安装后可以直接使用,如果编译安装需要进入到相应软件目录的bin目录下使用
#命令 man手册说明
# man inotifywait
inotifywait - wait for changes to files using inotify
使用inotify进行监控,等待产生变化的文件信息
# man inotifywatch
inotifywatch - gather filesystem access statistics using inotify
使用inotify进行监控,收集文件系统访问统计佶息
rsync -avz --delete /data/ [email protected]::nfsbackup --password-file=/etc/rsync.password
inotifywait -mrq /data -format "%w%f" -e create,delete,move_to,close_write
[root@nfs01 sersync]# vim /server/scripts/inotify.sh
#!/bin/bash
inotifywait -mrq /data --format "%w%f" -e create,delete,moved_to,close_write|
while read line
do
rsync -az --delete /data/ [email protected]::nfsbackup --password-
file=/etc/rsync.password
done
脚本说明:
for循环会定义一个条件,当条件不满足时停止循环
while循环:只要条件满足就一直循环下去
#!/bin/bash
Path=/data
backup_Server=172.16.1.41
/usr/bin/inotifywait -mrq --format '%w%f' -e create,close_write,delete /data | while read line
do
if [ -f $line ];then
rsync -az $line --delete rsync_backup@$backup_Server::nfsbackup --password-file=/etc/rsync.password
else
cd $Path &&
rsync -az ./ --delete rsync_backup@$backup_Server::nfsbackup --password-file=/etc/rsync.password
fi
done
在/data 目录先创建6个文件
[root@nfs01 data]# sh /server/scripts/inotify.sh &
[root@nfs01 data]# touch {1..6}.txt
在backup服务器上,已经时候同步过去了6个文件。
[root@backup ~]# ll /nfsbackup/
total 8
-rw-r--r-- 1 rsync rsync 0 Oct 17 12:06 1.txt
-rw-r--r-- 1 rsync rsync 0 Oct 17 12:06 2.txt
-rw-r--r-- 1 rsync rsync 0 Oct 17 12:06 3.txt
-rw-r--r-- 1 rsync rsync 0 Oct 17 12:06 4.txt
-rw-r--r-- 1 rsync rsync 0 Oct 17 12:06 5.txt
-rw-r--r-- 1 rsync rsync 0 Oct 17 12:06 6.txt
不要暂停程序,直接利用杀手三剑客进行杀进程
说明:kill三个杀手不是万能的,在进程暂停时,无法杀死;kill -9 (危险)
[root@nfs01 data]# jobs
[1]+ Running sh /server/scripts/inotify.sh &
[root@nfs01 data]# fg 1
sh /server/scripts/inotify.sh
fg -- 前台
bg -- 后台
01. sh inotify.sh &
02. nohup sh inotify.sh &
03. screen实现脚本程序后台运行
sh /server/scripts/inotify.sh &
nohup
nohup sh inotify.sh &
[root@test ~]# yum provides screen
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.7 kB 00:00
epel | 4.3 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
screen-4.0.3-19.el6.x86_64 : A screen manager that supports multiple logins on
: one terminal
Repo : base
Matched from:
[root@test ~]# yum install -y screen
在shell中输入 screen即可进入screen 视图
[root@test ~]# screen
Screen实现后台运行程序的简单步骤:
screen -ls :可看screen会话
screen -r ID :指定进入哪个screen会话
Screen命令中用到的快捷键
Ctrl+a c :创建窗口
Ctrl+a w :窗口列表
Ctrl+a n :下一个窗口
Ctrl+a p :上一个窗口
Ctrl+a 0-9 :在第0个窗口和第9个窗口之间切换
Ctrl+a K(大写) :关闭当前窗口,并且切换到下一个窗口 ,
(当退出最后一个窗口时,该终端自动终止,并且退回到原始shell状态)
exit :关闭当前窗口,并且切换到下一个窗口
(当退出最后一个窗口时,该终端自动终止,并且退回到原始shell状态)
Ctrl+a d :退出当前终端,返回加载screen前的shell命令状态
Ctrl+a " : 窗口列表不同于w
http://www.linuxidc.com/Linux/2017-10/147899.htm
本博文中所使用的系统版本为: CentOS release 6.9 (Final) 内核版本为: 2.6.32-696.10.1.el6.x86_64 望读者注意!
创建配置文件:
文件本身不存在需要手动创建
vi /etc/rsyncd.conf
#Rsync server
#created by kendall 2017.10.18
##rsyncd.conf start##
uid = rsync #客户端连过来具有什么权限
gid = rsync
use chroot = no #安全相关,程序出bug开启有好处
max connections = 2000 #最大客户端连接数
timeout = 300 #超时断开时间
pid file = /var/run/rsyncd.pid #daemon进程号记录
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log #日志文件位置
ignore errors #忽略错误
read only = false #只读 假的(可读写)
list = false #不可以查看服务端列表
hosts allow = 172.16.1.0/24 #允许IP段
#hosts deny = 0.0.0.0/32 #拒绝
auth users = rsync_backup #远程连接的用户(纯虚拟用户,不是系统用户)
secrets file = /etc/rsync.password #存放用户密码的文件位置
[backup] #第一个模块
path = /backup #共享的目录
[oldboy] #第二个模块
path = /data #共享的目录
创建用户,及共享目录
useradd rsync -s /sbin/nologin -M
id rsync
mkdir /backup /data
chown -R rsync.rsync /backup/ /data/
创建密码文件
echo "rsync_backup:654321" >/etc/rsync.password
chmod 600 /etc/rsync.password
启动rsync
rsync --daemon
netstat -lntup|grep rsync
ps -ef|grep rsync|grep -v grep
加入开机自启动
echo "rsync --daemon" >>/etc/rc.local
cat /etc/rc.local
创建密码文件
echo "654321" >/etc/rsync.password
chmod 600 /etc/rsync.password
ll /etc/rsync.password
cat /etc/rsync.password
推送文件测试
rsync -avz /tmp/ rsync_backup@server_ip::backup --password-file=/etc/rsync.password
rsync -avz /tmp/ rsync://rsync_backup@servr_ip/backup/tmp/ --password-file=/etc/rsync.password
rsync服务端配置修改后,需要重启rsync
pkill rsync
rsync --daemon
lsof -i:873
推送时,排除特定文件
rsync -avz --exlude={a,b} /backup/ rsync_backup@server_ip::backup --password-file=/etc/rsync.password
rsync -avz --exlude={a..g} /backup/ rsync_backup@server_ip::backup --password-file=/etc/rsync.password
rsync -avz --exlude-from=paichu.log /backup/ rsync_backup@server_ip::backup --password-file=/etc/rsync.password
无差异同步,增量同步千万别用
rsync -avz --delete /backup/ rsync_backup@server_ip::backup --password-file=/etc/rsync.password
限速推送
dd if=/dev/zero of=test1 bs=1M count=128
rsync -avz --bwlimit=100 /tmp/ rsync_backup@server_ip::backup --password-file=/etc/rsync.password
rsync的三种工作模式
本地 cp
通道 rsync -avzP -e 'ssh -p22' /etc root@server_ip:/tmp/
daemon 内网明文传输
题外:操作文件前的备份方法:
cp /etc/rsyncd.conf{,.bak}
示例
x = {'a': 1, 'b': 2}
y = {'b': 3, 'c': 4}
相同属性合并,后者覆盖前者的值。x和y合并后
>>> z
{'a': 1, 'b': 3, 'c': 4}
Python 3.5
在Python 3.5新增了字典合并的语法,只需要一条语句就可以实现字典的合并
z = {**x, **y}
其中**为字典解包操作符(dictionary unpacking operator)。
详细查看:https://docs.python.org/dev/whatsnew/3.5.html#pep-448-additional-unpacking-generalizations
Python 2 以及 Python 3.0-3.4
在Python 3.5之前,需要自己实现合并函数。
def merge_dicts(*dicts):
result = {}
for dict in dicts:
result.update(dict)
return result