rsync
基于sshc传输比较慢
rsync -avz -e 'ssh'	源文件   root@ip:目标文件位置
rysnc传输,源服务器配置发出方
mkdir /root/yangdata		#源服务器传输目录,想传输的目录
#设置密码
echo "yangcheng:yangcheng007" > /etc/rsyncd.passwd #yangcheng:yangcheng007密钥文件
chmod 600 /etc/rsyncd.passwd #必须600
rsync配置
配置模块密码传输vi /etc/rsyncd.conf  #注释必须要全部清除不然会报错
[rsyncdata]
uid = root #主
gid = root #组
hosts allow = 192.168.13.0/24 #这个网段
hosts deny = * #任何都拒绝
max connections = 200
timeout = 600
ignore errors
read only = no #不只读
write only = no #不只写
auth users = yangcheng #用户名yangcheng需要这个认证用户来远程传输的很重要
secrets file = /etc/rsyncd.passwd #密码文件yangcheng:yangcheng007
log file = /var/log/rsync/rsync.log #日志文件
path=/root/yangdata #传输目录
rsync启动
rsync --daemon
systemctl restart rsyncd.service
systemctl enable rsyncd.service
netstat -nltp|grep 873 #查看端口
客户端服务器配置,接收方
#注传输yangcheng用户名很重要
yum install rsync -y #安装
echo "yangcheng007" > /etc/rsyncd.passwd #配置密码yangcheng007
chmod 600 /etc/rsyncd.passwd #密码文件必须要配置600
客户端拉传输
#客户端拉取服务端数据
#这边远程拉过来的是文件不是整个目录,所以本地直接加目录
rsync -avz yangcheng@192.168.216.164::rsyncdata /root/{目录} --password-file=/etc/rsyncd.passwd
客户端推传输
#客户端数据推到服务端
#把www目录,推送到源rsyncdat配置的目录中
rsync -avz /root/www yangcheng@192.168.216.164::rsyncdata --password-file=/etc/rsyncd.passwd
源服务器推传输,场景一台源服务器同时每天推送多台客户端服务器,不需要每天客户端去接收数据,每台客户端都需要配置

#场景一台源服务器同时每天推送多台客户端服务器,不需要每天客户端去接收数据
每台客户端都需要配置
所有客户端配置一下操作
#配置模块密码传输vi /etc/rsyncd.conf  #注释必须要全部清除不然会报错
[rsyncdata]
uid = root #主
gid = root #组
hosts allow = 192.168.13.0/24 #这个网段
hosts deny = * #任何都拒绝
max connections = 200
timeout = 600
ignore errors
read only = no #不只读
write only = no #不只写
auth users = yangcheng #用户名yangcheng需要这个认证用户来远程传输的很重要
secrets file = /etc/rsyncd.passwd #密码文件yangcheng:yangcheng007
log file = /var/log/rsync/rsync.log #日志文件
path=/root/yangdata #传输目录
--------------------------------------------------------
rsync --daemon
systemctl restart rsyncd.service
systemctl enable rsyncd.service
netstat -nltp|grep 873 #查看端口

源服务器配置

#注传输yangcheng用户名很重要
yum install rsync -y #安装
echo "yangcheng007" > /etc/rsyncd.passwd #配置密码yangcheng007
chmod 600 /etc/rsyncd.passwd #密码文件必须要配置600
#1基于ssh传输
rsync -avz /root/eee root@192.168.216.165:/root #不需要启动rsyncd简单高效
#2模块密码传输
rsync -avz /root/eee yangcheng@192.168.216.165::rsyncdata --password-file=/etc/rsyncd.passwd
rsync参数
--av						#基本参数都加
--delete #rsync带上--delete的参数后,当源目录中的文件删除,同步后目标目录中的文件也会被删除,同步的作用
--progress #显示备份过程
--exclude='path' #排除不传输的文件或目录
--z #对备份文件传输时进行压缩
nfs
服务端安装NFS服务
#NFS必须要rpc调用协议端口,rpcbind tcp/udp端口111
yum install -y nfs-utils #安装nfs服务
yum install -y rpcbind #安装nfs服务

配置共享文件目录,编辑配置文件

#(ro)只读,(rw)读写,(rw,no_root_squash)读写,root写入需要这个参数no_root_squash	
# /共享文件名 ip(ro只读,rw只写 anonuid=用户id号,不是root,是id号0{anongid=0})no_root_squash不需要属组属主
mkdir /root/eee #创建public共享目录
vi /etc/exports #编辑
/root/eee 192.168.245.0/24 (rw) #前面目录 ip端 权限
systemctl reload nfs #重新加载NFS服务,使配置文件生效
启动查看
#启动服务和设置开启启动
systemctl restart rpcbind #先启动rpc服务
systemctl enable rpcbind #设置开机启动
systemctl restart nfs-server #reload也可以
systemctl enable nfs-server
systemctl status rpcbind.service
systemctl status nfs-server.service
showmount -e 192.168.216.164 #查看挂载信息本机ip
exportfs -v #确认共享生效
客户端安装配置
yum install -y  nfs-utils 					#安装nfs服务
systemctl restart nfs-server #reload也可以
systemctl enable nfs-server
showmount -e 192.168.216.164 #查看服务端挂载信息本机ip
mount 192.168.216.164:/root/eee /root/haha #客户端挂载服务端目录,共享
umount /root/haha #接触挂载
df -h #查看挂载成功

开机自动挂载
vi /etc/fstab
192.168.216.164:/root/eee /root/haha nfs defaults 0 0
samba
samba监听端口 TCP:139/445 UDP:137/138
#测试
Samba用户为三个(yangcheng,cuiyan,zhangzhou);
3个用户都可以浏览共享目录/share/;
yangcheng和cuiyan可以写入文件共享目录,zhangzhou只能看不能写
安装smaba相关软件包
没有安装的话,使用 yum install epel-release -y安装
yum -y install samba samba-client
创建共享目录
mkdir  /share
chmod -R 777 /share/
新建samba用户
useradd -d /home/yangcheng yangcheng
useradd -d /home/cuiyan cuiyan
useradd -d /home/zhangzhou zhangzhou
smbpasswd -a yangcheng #设置密码
smbpasswd -a cuiyan
smbpasswd -a zhangzhou
查看samba用户列表
pdbedit -L
编辑samba主配置文件
#先备份/etc/samba/smb.conf文件
cp -r /etc/samba/smb.conf /etc/samba/smb.conf.bak
#在/etc/samba/smb.conf文件中,新增以下部分:
[share]
comment = share
path = /share
browseable = yes
read only = no
guest ok = no
create mask = 0644
directory mask = 0755
valid users = samba
hosts allow = 192.168.145.0/24
hosts deny = 0.0.0.0/0
#测试配置文件语法,确保配置文件修改正确
testparm /etc/samba/smb.conf
#访问权限设置参数含义
[share]:定义了共享名称,这里称为 "share"。在Windows中会显示为 "\你的服务器IP\share"。
comment:为共享提供注释或描述,这个字段是可选的。
path:指定了共享目录的路径,这需要替换为您的实际共享目录路径。
browseable:设置为 yes,表示这个共享在网络上可以被浏览;如果设置为no,这个共享不会出现在浏览列表中,但是如果知道共享名称还是可以访问的。
read only:设置为 no,表示允许用户读写文件;如果设置为yes,则表示共享是只读的,用户不能修改文件。
guest ok:设置为 no,表示不允许未授权的访问;如果是yes,则表示不需要用户名和密码即可访问。
create mask和directory mask:设置新创建的文件和目录的默认权限。这里,新文件的权限被设置为644(即用户读写、组读、其他读),新目录的权限被设置为755(即用户读写执行、组和其他读执行)。
valid users:限制哪些用户可以访问这个共享。这里,只有名为 samba 的用户可以访问,用户名可以添加多个或一个,多个以逗号分隔。
hosts allow:定义哪些主机可以访问Samba服务器。这里仅允许IP x.x.x.x 访问。
hosts deny:定义哪些主机被禁止访问Samba服务器。这里禁止所有IP地址(0.0.0.0/0 代表所有网络)访问共享
启动samba服务
systemctl start smb
systemctl enable smb