1
2
3
4
|
useradd
rsync
password
rsync
mkdir
/backup
rsync
-arzvH --delete
rsync
@192.168.0.200:
/var/www/html//web/
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
ssh
-keygen -t rsa
#一直回车
ssh
-copy-
id
rsync
@192.168.0.200
#将公钥分发给服务器
sshr
sync
@192.168.0.200
#现在就可以无密码登陆了,成功实现免交互自动登录
vi
/root/rsync_web
.sh
#写一个脚本,创建任务计划
#!/bin/bash
CMD=
"/usr/bin/rsync"
RSYNC_USER=
"rsync"
ARGS=
"-az --delete"
SRC=
"192.168.0.200:/var/www/html"
DST=
"/web"
mkdir
-p $DST
$CMD $ARGS $RSYNC_USER@SRC $DST
保存退出!
chmod
700
/root/rsync_web
.sh
crontab
-e
00 23 * * *
/root/rsync_web
.sh
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
vi
/etc/rsyncd
.conf
uid=nobody
#指定当该模块传输文件时守护进程用户,默认是nobody
gid=nobody
#指定当该模块传输文件时守护进程组,默认是nobody
port=873
#后台程序使用端口,默认是873
use chroot=
yes
max connections=4
#最大连接数
log
file
=
/var/log/rsyncd
.log
#存放日志位置
pid
file
=
/var/run/rsyncd
.pid
#存放进程位置
hosts allow=192.168.0.200,192.168.0.201
#允许主机,或者是网段
hosts deny=0.0.0.0
/0
#禁止主机,没有这行,默认没有
[web]
path=
/var/www/html
comment=rsyncto web www.
test
.com
read
only=
yes
#只允许下载,no是允许下载和上传,上传建议使用SSH
dont compress=*.gz *.bz2 *.tgz *.zip *.
tar
*.z
auth
users
=
rsync
#认证的用户名,没有这两行表示是匿名,此用户与系统用户无关
secrets
file
=
/etc/rsync
.pass
#密码和用户名对比表,密码文件自己创建
|
1
2
3
4
5
6
|
vi
/etc/rsync
.pass
rsync
:123.com
rsync
--daemon
#启动rsync服务
killall -9
rsync
#关闭rsync服务
echo
“
rsync
--daemon” >>
/etc/rc
.
local
#设置开机启动
iptables -A INPUT -p tcp --dport 873 -j ACCEPT
#设置防火墙
|
1
2
3
4
5
6
7
8
9
10
11
|
vi
/etc/xinetd
.d
/rsync
service
rsync
{
disable =
yes
#修改为yes
socket_type = stream
wait = no
user = root
server =
/usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
|
1
|
rsync
-avz rysnc@192.168.0.200::
/var/www/html//web
#下行格式是这样,再加一个冒号
|
1
2
|
echo
"export RSYNC_PASSWORD="
123.com
""
>>
/etc/profile
rsync
-avz --delete rysnc:
//rsync
@192.168.0.200
/var/www/html//web
#这个命令格式和上面是一样效果
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
grep
-
v
"^#"
/etc/rsyslog
.conf |
grep
-
v
"^$"
#筛选掉注释和空行
$ModLoad imuxsock
# provides support for local system logging (e.g. via logger command)
$ModLoad imklog
# provides kernel logging support (previously done by rklogd)
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$IncludeConfig
/etc/rsyslog
.d/*.conf
*.info;mail.none;authpriv.none;
cron
.none
/var/log/messages
#内核及应用程序公共消息日志
authpriv.*
/var/log/secure
#系统安全日志
mail.*
/var/log/maillog
#电子邮件系统的功能
cron
.*
/var/log/cron
#计划任务相关的日志
*.emerg *
#syslog对日志所设置的级别
uucp,news.crit
/var/log/spooler
#syslog对news和uucp的日志所设置的级别,crit表示危急,但事故还没有发生,将要发生。news 是新闻组服务器的;uucp全称是UNIX-TO-UNIX COPY PROTOCOL的信息
local7.*
/var/log/boot
.log
#开机系统日志
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
vi
/etc/sysconfig/rsyslog
#修改如下
SYSLOGD_OPTIONS=
"-r -c 2"
vi
/etc/rsyslog
.conf
#去掉注释13、14、17、18
$ModLoad imudp
$UDPServerRun 514
$ModLoad imtcp
$InputTCPServerRun 514
service rsyslog restart
#重启rsyslog
netstat
-tupln |
grep
rsyslog
#已经启动,监听是TCP/UDP协议514
tcp 0 0 0.0.0.0:514 0.0.0.0:* LISTEN 1408
/rsyslogd
tcp 0 0 :::514 :::* LISTEN 1408
/rsyslogd
udp 0 0 0.0.0.0:514 0.0.0.0:* 1408
/rsyslogd
udp 0 0 :::514 :::* 1408
/rsyslogd
|
1
2
3
4
5
6
7
8
9
10
11
|
vi
/etc/rsyslog
.conf
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$IncludeConfig
/etc/rsyslog
.d/*.conf
*.info;mail.none;authpriv.none;
cron
.none @192.168.0.2
authpriv.* @192.168.0.2
mail.*
/var/log/maillog
cron
.*
/var/log/cron
*.emerg *
uucp,news.crit
/var/log/spooler
local7.*
/var/log/boot
.log
service rsyslog restart
#重启rsyslog
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
yum
install
-y logwatch
cp
-rf
/usr/share/logwatch/default
.conf
/logwatch
.conf
/etc/logwatch/conf/logwatch
.conf
vi
/etc/logwatch/conf/logwatch
.conf
LogDir =
/var/log
#日志文件
TmpDir =
/var/cache/logwatch
#缓存文件
Detail = High
#日志详细程度为高
MailTo = user@
test
.com
#收件人邮箱地址,多个邮箱有逗号隔开
MailFrom = root@
test
.com
#发件人邮箱地址,默认每天执行一次向邮箱发送邮件,可以从/etc/cron.daily里看到
Print = No
#可选项, Yes 会被打印到系统标准输出, 并且不会以邮件的形式发送到 MailTo 设定的邮箱里 , No 选项则会发到邮箱中
Range = yesterday
#处理什么时候的日志,可选项All,Yesterday,Today,即所有,昨天的,今天的
Detail = Low
# 日志详细度,可选项 Low,Med,High ,或是 0-10数字
Service = All
#监控所有服务all
Service =
"-httpd"
#不监控的服务前面加“-”,可以添加多条
|
1
|
perl
/usr/share/logwatch/scripts/logwatch
.pl
|
1
2
3
4
|
vi
/usr/local/sbin/logwatch
.sh
#!/bin/bash
perl
/usr/share/logwatch/scripts/logwatch
.pl
chmod
u+x
/usr/local/sbin/logwatch
.pl
|
1
2
|
crontab
–e
30 08 * * *
/usr/local/sbin/logwatch
.sh
#每台早上八点三十发一次邮件
|
1
2
3
|
yum
install
-y ntp
service ntpd start
#不需要配置,启动即可
iptables -I INPUT -p udp --dport 123 -j ACCEPT
#ntp使用upd协议123端口,设置允许规则
|
1
|
ntpdate 192.168.0.1
|
1
2
|
crontab
-e
00 21 * * *
/usr/sbin/ntpdate
192.168.0.1;
/sbin/hwclock
-w
#设置每天晚上9点同步,hwclock -w 将系统时间写入系统硬件
|
1
2
3
4
5
6
7
8
9
10
11
|
grep
-
v
"^#"
/etc/ntp
.conf |
grep
-
v
"^$"
driftfile
/var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
#限制其他计算机查询、修改本机上的NTP服务,其中default表示所有IP
restrict -6 default kod nomodify notrap nopeer noquery
#应用于IPV6地址的主机
restrict 127.0.0.1
#开放本机内部接口,用于反馈;以便于在本地对NTP服务进行监控及配置
restrict -6 ::1
#开放这个网段,不能修改;即允许192.168.1.0/24网段的NTP客户端都可以用本机的NTP服务器进行网络校时,但不允许它们修改本机的NTP服务配置
server 0.centos.pool.ntp.org
#指定真实上层NTP服务器
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org
includefile
/etc/ntp/crypto/pw
keys
/etc/ntp/keys
|