标签存档: 后端

文件增量同步rsync中delete和exclude参数的使用

实例需求:

3台主机,host1和host3之间文件的单向同步和双向同步问题。

1.同步脚本:

#!/bin/bash

HOST1="172.31.29.221"
USER1="w1"
PASSWORD1="Server123"

HOST2="172.31.28.61"
USER2="w2"
PASSWORD2="Server123"

HOST3="172.31.19.244"
USER3="w3"

# 如果 rsync 守护进程需要此密码文件
RSYNC_OPTS="--password-file=/etc/rsyncd/w.secrets"

#host3向host1单向同步/www/wwwroot/test.com/文件夹,
#同时子目录public/不同步
REMOTE_SOURCE="$USER3@$HOST3::rsync_test"
LOCAL_DIR="/www/wwwroot/test.com/"
rsync -avz --delete --exclude="public/" --exclude="runtime/" \
 $RSYNC_OPTS "$REMOTE_SOURCE" "$LOCAL_DIR"
# 可选:记录日志
echo "$(date): Sync completed from $HOST3 to local server." \
 >> /var/log/sync_from_host3.log

#host1和host3的/www/wwwroot/test.com/public/uploads/
#文件夹双向同步
SOURCE_DIR="$USER3@$HOST3::rsync_test_uploads"
DES_DIR="/www/wwwroot/test.com/public/uploads/"
rsync $RSYNC_OPTS -avz  "$SOURCE_DIR"  "$DES_DIR"
rsync $RSYNC_OPTS -avz  "$DES_DIR"  "$SOURCE_DIR"
# 可选:记录日志
echo "$(date): Sync completed." >> /var/log/sync_to_host3.log

#host3向host1单向同步/www/wwwroot/test.com/public/文件夹,
#同时子目录uploads/不同步
REM_SOURCE="$USER3@$HOST3::rsync_test_public"
LOL_DIR="/www/wwwroot/test.com/public/"
rsync -avz --delete --exclude="uploads/" \
 $RSYNC_OPTS "$REM_SOURCE" "$LOL_DIR"
# 可选:记录日志
echo "$(date): Sync completed from $HOST3 to local server." \ 
 >> /var/log/sync_from_host3.log

2.host3的rsyncd.conf配置文件:

# sample rsyncd.conf configuration file
# GLOBAL OPTIONS
#motd file=/etc/motd
#log file=/var/log/rsyncd
# for pid file, do not use /var/run/rsync.pid if
# you are going to run rsync out of the init.d script.
# The init.d script does its own pid file handling,
# so omit the "pid file" line completely in that case.
# pid file=/var/run/rsyncd.pid
#syslog facility=daemon
#socket options=

# MODULE OPTIONS
address = 172.31.19.244
port = 873
uid = user1_myrsync
gid = myrsync
use chroot = no
max connections=10
timeout = 600

# motd file=/etc/rsyncd/rsyncd.motd
pid file=/var/run/rsyncd.pid
lock file = /var/lock/rsyncd
log file=/var/log/rsync.log
log format = %t: host %h (%a) %o %f (%l bytes). Total %b bytes.
dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz

[rsync_test]
    comment = abc.com phpcode rsync
    path = /www/wwwroot/test.com
    exclude = public/*** runtime/***
    lock file = /var/lock/rsyncd
# the default for read only is yes. ..
    read only = true
    write only = false
    list = yes

    auth users = user1_myrsync w1 w2 w3 w4
    secrets file = /etc/rsyncd/rsyncd.secrets
    strict modes = no
    hosts allow = 172.31.19.244 172.31.28.61 172.31.29.221 172.31.16.193 172.31.21.140
# hosts deny =
    ignore errors = no
    ignore nonreadable = yes
    transfer logging = no
# log format = %t: host %h (%a) %o %f (%l bytes). Total %b bytes.
    timeout = 600
    refuse options = checksum dry-run
[rsync_test_uploads]
    comment = public archive is ok by yyyyyyy
    path = /www/wwwroot/test.com/public/uploads/
    lock file = /var/lock/rsyncd
# the default for read only is yes...
    read only = no
    write only = no
    list = yes

    auth users = user1_myrsync w1 w2 w3 w4
    secrets file = /etc/rsyncd/rsyncd.secrets
    strict modes = no
    hosts allow = 172.31.19.244 172.31.28.61 172.31.29.221 172.31.16.193 172.31.21.140
# hosts deny =
    ignore errors = no
    ignore nonreadable = yes
    transfer logging = no
# log format = %t: host %h (%a) %o %f (%l bytes). Total %b bytes.
    timeout = 600
    refuse options = checksum dry-run
[rsync_test_public]
    comment = test.com phpcode rsync
    path = /www/wwwroot/test.com/public/
    exclude = uploads/*** 
    lock file = /var/lock/rsyncd
# the default for read only is yes. ..
    read only = true
    write only = false
    list = yes

    auth users = user1_myrsync w1 w2 w3 w4
    secrets file = /etc/rsyncd/rsyncd.secrets
    strict modes = no
    hosts allow = 172.31.19.244 172.31.28.61 172.31.29.221 172.31.16.193 172.31.21.140
# hosts deny =
    ignore errors = no
    ignore nonreadable = yes
    transfer logging = no
# log format = %t: host %h (%a) %o %f (%l bytes). Total %b bytes.
    timeout = 600
    refuse options = checksum dry-run


阿里云Centos配置腾讯SMTP邮箱

which mail
yum -y install mailx
vim /etc/mail.rc

写入:

# mail config
set from=zpmail@wp.cpxiang.tech 
set smtp=smtps://smtp.qq.com:465  
set smtp-auth-user=1324928751
set smtp-auth-password=<授权码> 
set smtp-auth=login 
set nss-config-dir=/root/.certs  
set ssl-verify=ignore
mkdir -p /root/.certs
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
cd /root/.certs/
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
echo "hallo" | mail -v -s "this is Test Mail" 1324928751@qq.com

数据库设计三大范式

第一范式:当关系模式R的所有属性都不能在分解为更基本的数据单位时,称R是满足第一范式的,简记为1NF。满足第一范式是关系模式规范化的最低要求,否则,将有很多基本操作在这样的关系模式中实现不了。

第二范式:如果关系模式R满足第一范式,并且R得所有非主属性都完全依赖于R的每一个候选关键属性,称R满足第二范式,简记为2NF。

第三范式:设R是一个满足第一范式条件的关系模式,X是R的任意属性集,如果X非传递依赖于R的任意一个候选关键字,称R满足第三范式,简记为3NF。

Ubuntu通过mail发送邮件

先修改/etc/s-nail.rc中来添加外部SMTP服务器如下:

set from=zpmail@wp.cpxiang.tech
set smtp="smtps://smtp.qq.com:465"
set smtp-auth=login
set smtp-auth-user=1324928751
set smtp-auth-password=<授权码>

尝试发送

echo "nihao" | mail -s "test" 1324928751@qq.com

Httpd配置多个顶级域名

先找到httpd.conf文件后添加:

LoadModule vhost_alias_module modules/mod_vhost_alias.so
#
#
#
Include conf/extra/httpd-vhosts.conf

然后是extra目录内的httpd-vhosts.conf文件:

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.localhost
    DocumentRoot "/var/www/site1"
    ServerName site1.com
    ServerAlias *.site1.com
    ErrorLog "logs/localhost-error_log"
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.localhost
    DocumentRoot "/var/www/site2"
    ServerName site2.com
    ServerAlias *.site2.com
    ErrorLog "logs/localhost-error_log"
</VirtualHost>