Linux(Centos)服务器间共享文件夹及文件传输

【文件共享-nfs】

如: 将 /192.168.1.171/root/share/ 共享,挂载到 192.168.1.172 的目录/root/share/ 

 

安装 nfs:

yum -y install nfs-utils rpcbind

chkconfig rpcbind on
chkconfig nfs on

service rpcbind start
service nfs start

192.168.1.171 的配置:

#192.168.1.171 配置
firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=mountd
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --reload

mkdir -p /root/share
chmod 777 /root/share
echo '/root/share/ 192.168.1.172(rw,insecure,sync,all_squash)'>>/etc/exports

exportfs -r
exportfs

#查看
showmount -e
showmount -e 192.168.1.171

192.168.1.172 的配置:

#192.168.1.172 配置
mkdir -p /root/share
mount -t nfs 192.168.1.171:/root/share/ /root/share/

#查看
showmount -e 192.168.1.171

linux 访问 windows 共享文件夹:

yum list samba-client

yum install -y samba-client

mkdir -p /opt/share

mount -t cifs -o username=admin,password=admin //192.168.1.101/share /opt/share

# umount /opt/share

参考:

18.7. The /etc/exports Configuration File

NFS /etc/export配置

 

【文件传输-rsync】

服务端

====================================================
服务端
====================================================

# 是否已安装
rpm -qa | grep rsync

# 查看版本
rsync --version

# 配置文件
vim /etc/rsyncd.conf

uid = rsync
gid = rsync
use chroot = no
timeout = 900
max connections = 10
read only = false
ignore errors
list = false
exclude = lost+found/
transfer logging = yes
ignore nonreadable = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
hosts allow = 192.168.1.0/24
fake super = yes
auth users = user_rsync
secrets file = /etc/rsync.password
[backup]
path = /opt/rsync_backup


# 备份目录
mkdir -p /opt/rsync_backup
chmod 774 /opt/rsync_backup
adduser rsync
chown rsync.rsync /opt/rsync_backup

# 虚拟用户密码
echo "user_rsync:pwd_rsync" >/etc/rsync.password
chmod 600 /etc/rsync.password

# 启动 rsync 服务
rsync --daemon --config=/etc/rsyncd.conf
ps -ef | grep rsync
netstat -lntup | grep rsync

客户端

====================================================
客户端
====================================================
# 是否已安装
rpm -qa | grep rsync

# 查看版本
rsync --version

# 添加虚拟密码
echo "pwd_rsync" >/etc/rsync.password
chmod 600 /etc/rsync.password

# 启动 rsync 服务
rsync --daemon --config=/etc/rsyncd.conf
ps -ef | grep rsync
netstat -lntup | grep rsync


# 客户端同步文件到服务端
rsync -azv aaa.tgz [email protected]::backup --password-file=/etc/rsync.password 

【ssh/scp 免密码访问】

# A 服务器 ssh 公钥认证创建(可配置 scp、ssh 免密码登陆)
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

# A 公钥传到 B 服务器(首次输入密码)
scp -r -P 22 /root/.ssh/id_rsa.pub [email protected]:/root/.ssh/authorized_keys


# B 服务器 ssh 公钥认证创建
ssh-keygen -t rsa

# B 公钥传到 A 服务器(首次输入密码)
scp -r -P 22 /root/.ssh/id_rsa.pub [email protected]:/root/.ssh/authorized_keys


# 接下来 AB之间传输文件不需要密码了
scp /root/test.sh server171:/root/

多服务器配置免密码访问:

# 192.168.1.171
ssh-keygen -t rsa

# 192.168.1.172
ssh-keygen -t rsa

# 192.168.1.173
ssh-keygen -t rsa

# 171、172、173 都执行
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]

 

你可能感兴趣的:(Linux)