2.创建备份服务器: ntp+cron rsync --daemon

创建备份服务器:   ntp+cron   rsync --daemon

# optimization by onekey

sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#‘ /etc/selinux/config

grep SELINUX=disabled /etc/selinux/config

setenforce 0

getenforce

/etc/init.d/iptables stop

/etc/init.d/iptables stop

chkconfig iptables off

chkconfig|egrep -v "crond|sshd|network|rsyslog|sysstat"|awk ‘{print "chkconfig",$1,"off"}‘|bash

useradd oldboy

\cp /etc/sudoers /etc/sudoers.bak

echo "oldboy ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

tail -l /etc/sudoers

visudo -c

echo ‘export TMOUT=1800‘ >> /etc/profile

echo ‘export HISTSIZE=5‘  >> /etc/profile

echo ‘export HISTFILESIZE=5‘ >> /etc/profile

. /etc/profile

echo ‘*                -       nofile          65535‘ >> /etc/security/limits.conf

echo ">/etc/udev/rules.d/70-persistent-net.rules" >>/etc/rc.local

#about selinux

cat >> /etc/sysctl.conf <<EOF

net.ipv4.tcp_fin_timeout = 2

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_syncookies = 1

net.ipv4.tcp_keepalive_time = 600

net.ipv4.ip_local_port_range = 4000   65000

net.ipv4.tcp_max_syn_backlog = 16384

net.ipv4.tcp_max_tw_buckets = 36000

net.ipv4.route.gc_timeout = 100

net.ipv4.tcp_syn_retries = 1

net.ipv4.tcp_synack_retries = 1

net.core.somaxconn = 16384

net.core.netdv_max_backlog = 16384

net.ipv4.tcp_max_orphans = 16384

net.nf_conntrack_max = 25000000

net.netfilter.nf_conntrack_max = 25000000

net.netfilter.nf_conntrack_tcp_timeout_established = 180

net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120

net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60

net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120

EOF

#set ip and hosts for backup

cat >/etc/sysconfig/network-scripts/ifcfg-eth0<<EOF

DEVICE=eth0

TYPE=Ethernet

ONBOOT=yes

NM_CONTROLLED=yes

BOOTPROTO=static

IPADDR=10.0.0.41

NETSK=255.255.255.0

GATEWAY=10.0.0.2

nameserver=202.96.128.86

EOF

cat >/etc/sysconfig/network-scripts/ifcfg-eth1 <<EOF

DEVICE=eth1

TYPE=Ethernet

ONBOOT=yes

NM_CONTROLLED=yes

IPADDR=172.16.1.41

NETSK=255.255.255.0

EOF

cat >/etc/sysconfig/network<<EOF

NETWORKING=yes

HOSTNAME=backup

EOF

hostname backup

cat >/etc/hosts <<EOF

127.0.0.1    localhost localhost.localdomain localhost4 localhost4.localdomain4

::1          localhost localhost.localdomain localhost6 localhost6.localdomain6

172.16.1.5   lb01

172.16.1.6   lb02

172.16.1.7   web02

172.16.1.8   web01

172.16.1.31  nfs01

172.16.1.41  backup

172.16.1.51  db01

172.16.1.61  m01

EOF

#/etc/init.d/network reload

#make some dir

mkdir -p /server/scripts /server/tools /application /data

reboot

=======================================================================================================

#yum repo and epel

yum -y install  wget

\cp /etc/yum.repos.d/CentOS-Base.repo{,.backup}

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

yum clean all

yum makecache

#setup some tools and develpment

yum -y install lrzsz nmap tree dos2unix nc wget

yum groupinstall -y "Base" "Compatibility libraries" "Debugging Tools" "Development tools"

#set ntp cron

echo ‘#time sync by NTP Server at 20170608‘ >>/var/spool/cron/root

echo ‘*/5 * * * * /usr/sbin/ntpdate 172.16.1.61 >/dev/null 2>&1‘ >>/var/spool/cron/root

crontab -l

#setup rsync --daemon

#install rsync

yum -y install rsync

#useradd rsync

useradd -s /sbin/nologin -M -u889 rsync

id rsync

#create /etc/rsyncd.conf

user=rsync

authuser=rsync_backup

passwd=oldboy

passwdfile=/etc/rsync.password

bakpath1=/backup

bakpath2=/nfsbackup

bakpath3=/webbackup

cat >/etc/rsyncd.conf <<EOF

#rsync_config________________________start

#create by 20has at 20170608

uid = $user

gid = $user

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

#hosts deny = 0.0.0.0/32

auth users = $authuser

secrets file = $passwdfile

[backup]

path = $bakpath1

[nfsbackup]

path = $bakpath2

[webbackup]

path = $bakpath3

#rsync_config________________________end

EOF

#create passwordfile

echo "rsync_backup:oldboy" > $passwdfile

chmod 600 $passwdfile

#create backuppath

mkdir -p $bakpath1 $bakpath2 $bakpath3

chown -R rsync.rsync $bakpath1 $bakpath2 $bakpath3

#onboot

echo "rsync --daemon " >>/etc/rc.local

#start daemon

rsync --daemon

lsof -i :873

backup:      这部分是未来backup校验全网备份和文件(暂时未完成)

mkdir /backup

chown rsync.rsync /backup

rm -f `find /backup -type f -name "*.tar.gz" -mtime +180`

改进的脚本:

[[email protected] scripts]# vim check.sh

#!/bin/sh

#################check /backup by 20has at 20170514

/bin/find /backup -type f -name "*.tar.gz" -and ! -name "$date +%F_%W" -mtime +180|xargs /bin/rm -f

/usr/bin/md5sum -c /backup/10.0.0.8/flag.txt >>/backup/10.0.0.8/result.txt

mail -s "$(date +%F) bak result " [email protected] </backup/10.0.0.8/result.txt

客户端rsync过来的必要设置:

web01-8 客户端:

#install rsync

yum -y install rsync

#create passwordfile

echo "oldboy" >/etc/rsync.password

chmod 600 /etc/rsync.password

mkdir -p /server/scripts

cat >>/server/scripts/bak.sh <<EOF

#!/bin/sh

##create by 20has at 2017-5-18

IP=$(ifconfig eth1|awk -F "[ :]+" ‘NR==2{print $4}‘)

TIME=$(date +%F)

mkdir -p /backup/$IP

cd / && \

tar -zcf /backup/$IP/$TIME.tar.gz var/spool/cron/root etc/rc.local server/scripts etc/sysconfig/iptables var/html

md5sum /backup/$IP/$TIME.tar.gz >/backup/$IP/flag.log

rsync -az /backup/ [email protected]::backup --password-file=/etc/rsync.password

#del

find /backup -type f -name "*.tar.gz" -mtime +180 |xargs rm -f

EOF

#add cron to rsync backup

echo ‘add cron to rsync backup at 20170608‘ >>/var/spool/cron/root

echo ‘00 00 * * * /bin/sh /server/scripts/bak.sh &>/dev/null‘ >>/var/spool/cron/root

时间: 2024-10-25 17:04:33

2.创建备份服务器: ntp+cron rsync --daemon的相关文章

搭建rsync daemon 备份服务器

搭建rsync daemon 备份服务器 [[email protected] ~]# rpm -qa rsync rsync-3.0.6-12.el6.x86_64[[email protected] ~]# touch /etc/rsyncd.conf [[email protected] ~]# vim /etc/rsyncd.conf  #created by yvonne 2015-7-5 21:59:55  ##rsyncd.conf start##  uid = rsync  gi

搭建企业级全网数据定时备份方案【cron + rsync】

1.1.1. 服务端的配置[192.168.25.141] Rsync的端口是:873 man rsyncd.conf 查看帮助 1.vim /etc/rsyncd.conf vi /etc/rsyncd.conf -->man rsyncd.conf 查看帮助 ######rsyncd.conf####### uid = rsync ----->非系统虚拟用户 gid = rsync use chroot =no -->防止出现安全问题 maxconnections = 200 ---

rsync --daemon模式的实现

一 配置环境: [[email protected] ~]# cat /etc/redhat-release CentOS release 6.7 (Final) [[email protected] ~]# uname -r 2.6.32-573.el6.x86_64 [[email protected] ~]# uname -i x86_64 二 查看有没有安装: rpm -aq rsync 三 安装: yum install rsync -y 四 配置 服务群配置 vim /etc/rsy

rsync daemon实践

rsync - a fast, versatile, remote (and local) file-copying tool rsync是一个快速,可靠得远程(和本地)文件拷贝工具,有点像cp命令,但是!cp是全量拷贝,而rsync是增量拷贝. 三种同步方式: 1.Local:  rsync [OPTION...] SRC... [DEST 2.远程通道,例如:ssh Push: rsync -avz data_192.168.234.131 -e 'ssh' [email protected

backup部署rsync --daemon和遇到的问题总结

本文算是系统搭建的一部分 硬件环境: 统统IBM3650M4服务器 两台nginx_proxy.两台web_server.nfs.DB.backup 系统环境: 操作系统为Centos 6.5.rsync version 3.0.6 目的:部署rsync --daemon进程用于备份文件 服务端: 1.安装(PC/Server都需要安装rsync命令) 系统自带rsync命令,如若需要安装请使用下面命令: yum install -y rsync 2.创建rsync --daemon进程用户 u

Rsync daemon服务器端安装配置步骤

1.查看rsync是否安装rpm -qa rsync yum install rsync openssh-clients -y 2.添加用户 rsync useradd rsync -s /sbin/nologin -M tail -1 /etc/passwd 3.配置rsyncd.conf vim /etc/rsyncd.conf #rsync_config___start ##rsyncd.conf start##uid = rsync //虚拟用户,远端的命令需要使用rsync访问共享目录

Rsync --daemon(守护进程模式)

服务端: [[email protected] ~]# cat /etc/rsyncd.conf(默认没有这个配置文件) [[email protected] ~]# vi /etc/rsyncd.conf(编辑配置文件) #rsync_config_______________start #created by oldboy 15:01 2007-6-5 #QQ 31333741 blog: http://oldboy.blog.51cto.com ##rsyncd.conf start##

那些年我踩过的坑之 rsync daemon详解

服务端设置 /etc/rsyncd.conf 设置 #rsync.conf--------------------------------------------start ##这个地方被坑过 报错信息 uid rsync error 类似的##原因是把##注释加到了uid=rsync后面,这里定义的是系统用户,以后的配置文##注释必须换行加uid = rsync gid = rsync use chroot = nomax connections = 200timeout = 300 ##这条

Linux自动同步网络时间,并创建本地Ntp服务器。

NTP (Network Time Protocol)作用:将网络中的各个主机的时间进行同步,局域网中的误差<0.1ms架构:C/S实验环境:两台有网络的Centos,其中134为服务端,135为客户端.134同步网络时间,其他服务器同步134时间.1.查看134的系统信息.时间和时区cat /etc/redhat-release datetimedatectl | grep "Time zone"此时可以看到134时区为上海.时间和网络时间不同步2.查看135的系统信息.时间和