一、nfs
1、环境准备
1、yum源 (一个云仓库+pepl仓库)
[root@web ~]# vim /etc/yum.repos.d/hh.repo
[a]
name=a
baseurl=file:///mnt
gpgcheck=0
[root@web ~]# vim /etc/fstab
/dev/cdrom /mnt iso9660 defaults 0 0
[root@web ~]# mount -a
[root@web ~]# yum repolist
[root@web ~]# ping www.baidu.com
[root@web ~]# yum -y install wget
[root@web ~]# vim /etc/resolv.conf
将dns该为114.114.114.114 8.8.8.8
[root@web ~]# ping www.baidu.com //可以ping通百度即可进行下一步
[root@web ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
[root@web ~]# yum clean all
[root@web ~]# yum makecache
[root@web ~]# yum -y install epel-release.noarch
[root@web ~]# yum clean all
[root@web ~]# yum makecache2、防火墙和selinux
[root@web ~]# systemctl stop firewalld
[root@web ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@web ~]# setenforce 0
[root@web ~]# vim /etc/selinux/config
SELINUX=permissive2、安装配置web服务器
1、使用自建的yum仓库下载nginx
1、先只安装不下载nginx
[root@web ~]# yum -y install --downloadonly --downloaddir=./soft/ nginx2、下载cteaterepo,自建仓库
[root@web ~]# yum -y install createrepo
[root@web ~]# createrepo ./soft/
[root@web ~]# ls soft/
[root@web ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx
baseurl=file:///root/soft/
gpgcheck=0
enable=1
[root@web ~]# yum clean all[root@web ~]# yum makecache
3、使用自己建造的仓库下载nginx
[root@web ~]# yum -y install nginx
[root@web ~]# nginx //启动nginx
检查服务是否启动:
[root@web ~]# netstat -lnput | grep nginx
[root@web ~]# ps -aux | grep nginx
4、查找nginx的配置文件位置
[root@web html]# find / | grep nginx
/usr/share/nginx/html
[root@web html]# rpm -ql nginx
/usr/share/nginx/html/404.html
[root@web nginx]# cd /usr/share/nginx/html/
[root@web html]# ls
404.html 50x.html en-US icons img index.html nginx-logo.png poweredby.png
3、安装配置nfs服务器
NFS(Network File System,网络文件系统)是一种分布式文件系统协议,允许一个系统在网络上与他人共享目录和文件。
rpcbind 是一个用于支持 RPC(Remote Procedure Call,远程过程调用)的服务。在一些操作系统中,如 CentOS 8,NFS(Network File System,网络文件系统)的实现依赖于 RPC 机制,而 rpcbind 充当了 NFS 服务器和客户端之间的中介,用于完成从远程到本地的映射过程。
搭建 NFS 服务器时,需要安装 rpcbind 以及 nfs-utils 软件包来提供 NFS 共享服务。
(1)下载nfs软件与其依赖软件
[root@nfsserver ~]# yum -y install nfs-utils.x86_64 rpcbind.x86_64
(2)创建一个目录/share并创建文件/share/passwd
[root@nfsserver ~]# mkdir /share
[root@nfsserver ~]# touch /share/passwd
(3)将web机子的图片和视频拷贝过来到/share目录下
[root@nfsserver ~]# scp root@10.0.0.30:/usr/share/nginx/html/3.jpg /share/
[root@nfsserver ~]# scp root@10.0.0.30:/usr/share/nginx/html/1.mp4 /share/
(4)编辑配置文件/etc/exports指定要暴露的文件(/share)
[root@nfsserver ~]# vim /etc/exports
/share *(rw,sync)
(5)测试
二、自动监控备份静态文件
1、配置
(1)修改hostname
[root@beifen ~]# hostnamectl set-hostname bakserver
[root@beifen ~]# reboot
(2)关闭防火墙与selinux
[root@bakserver ~]# systemctl stop firewalld
[root@nfsserver ~]# systemctl disable firewalld
[root@bakserver ~]# setenforce 0
[root@nfsserver ~]# vim /etc/selinux/config
SELINUX=permissive
(3)安装rsync,2个主机都有安装
[root@bakserver ~]# yum -y install rsync
[root@nfsserver ~]# yum -y install rsync
(4)安装inotify监控
[root@nfsserver ~]# yum -y install inotify-tools-devel.x86_64
(5)同步一份文件到bakserver上
[root@nfsserver ~]# rsync -av /share/ root@10.0.0.31:/tmp/
(6)设置免密
[root@nfsserver ~]# ssh-keygen
[root@nfsserver ~]# ssh-copy-id root@10.0.0.31
(7)确定全部都免密,测试实时rsync是否能够免密备份
[root@nfsserver ~]# rsync -av /share/ root@10.0.0.31:/tmp/
(8)在备份主机上创建/bakpu目录
[root@bakserver ~]# mkdir /bakpu //同步的信息都存放在这里
(9)在nfs上编辑脚本,并进行监控,实现自动同步
[root@nfsserver ~]# vim rn.sh
#!/bin/bash
inotifywait -mrq -e modify,create,delete,attrib,move /share/ | while read events
do
rsync -av /share/ root@10.0.0.31:/bakpu
echo "`date +%F\ %T`出现时间$events" >> /var/log/rsync.log 2>&1
done
[root@nfsserver ~]# chmod +x rn.sh
[root@nfsserver ~]# nohup ./rn.sh &
[root@nfsserver ~]# touch /share/1.txt
(10)查看是否同步成功
[root@bakserver ~]# ls /bakpu/
1.mp4 1.txt 3.jpg a.txt passwd
2、SAMBA文件共享
Samba 是在 Linux 和 Unix 系统上实现 SMB(Server Message Block)协议的一个免费软件。
SMB 协议主要用于 Windows 操作系统的文件和打印共享。通过 Samba,Linux 和 Unix 系统可以与 Windows 系统进行良好的交互和资源共享。
Samba 的主要特点和优势包括:
1.跨平台文件共享:允许 Windows、Linux 和 macOS 等不同操作系统之间共享文件和打印机。
2.易于配置:可以通过简单的配置文件和命令来设置共享目录、用户权限等。
3.支持多种身份验证方式:例如本地用户、域用户等。
在实际应用中,Samba 常用于以下场景:
·企业办公环境:让 Windows 客户端能够访问 Linux 服务器上的共享文件。
·家庭网络:在不同操作系统的设备之间共享多媒体文件。
配置 Samba 时,需要编辑 /etc/samba/smb.conf 文件来定义共享目录、访问权限、用户等信息。
三、samba
(一)SMB协议实现⽂件共享
SMB是Windows和类Unix系统之间共享⽂件的⼀种协议
客户端==主要是Windows==;
⽀持多节点同时挂载以及并发写⼊ 主要⽤于windows和Linux下的⽂件共享、打印共享
(二)配置⽂件
/etc/samba/smb.conf
[global] 全局选项
workgroup = MYGROUP 定义samba服务器所在的⼯作组
server string = Samba Server Version %v smb服务的描述
log file = /var/log/samba/log.%m ⽇志⽂件
max log size = 50 ⽇志的最⼤⼤⼩KB
security = user 认证模式:share匿名|user⽤户密
码|server外部服务器⽤户密码
passdb backend = tdbsam 密码格式
load printers = yes 加载打印机
cups options = raw 打印机选项
[homes] 局部选项(共享名称)
comment = Home Directories 描述
browseable = no 隐藏共享名称
writable = yes 可读可写
[printers] 共享名称
comment = All Printers 描述
path = /var/spool/samba 本地的共享⽬录
browseable = no 隐藏
guest ok = no ——> public = no 需要帐号和密码访问
writable = no ——> read only =yes 不可写
printable = yes 打印选项
[share]
path = /dir1
guest ok = no
writable = yes
(三)搭建⼀个SAMBA服务,共享⼀个⽬录/samba/share,客户端使⽤user01/123通过 windows或者Linux可以在该⽬录⾥创建⽂件删除⽂件
1)安装软件
[root@smb-server ~]# yum -y install samba
2)创建⼀个共享⽬录
mkdir /samba/share -p
3) 修改配置⽂件
vim /etc/samba/smb.conf
...
[smb_share]
comment = samba service
path = /samba/share
guest ok = no
writable = yes
或者
[samba_share]
path = /samba/share
public = no
writable = yes
4) 创建⼀个本地⽤户并且加⼊到samba数据库⾥
[root@smb-server samba]# useradd user01
[root@smb-server samba]# id user01
uid=508(user01) gid=510(user01) groups=510(user01)
[root@smb-server samba]# which smbpasswd
/usr/bin/smbpasswd
[root@smb-server samba]# rpm -qf /usr/bin/smbpasswd
samba-common-3.6.23-51.el6.x86_64
[root@smb-server samba]# smbpasswd -a user01
New SMB password:
Retype new SMB password:
Added user user01.
5)启动服务
systemctl start nmb.service
systemctl start smb.service
6)测试验证
Linux下:
yum -y install samba-client
查看samba服务共享资源:
smbclient //192.168.2.199/smb_share -U user01
挂载共享资源yum -y install cifs-utils
mkdir aaa
mount.cifs -o user=user01,pass=123 //192.168.2.199/smb_share ~/aaa/