当前位置首页 > Linux知识

Linux--简单实现nfs的目录挂载,ntp时间同步

阅读次数:264 次  来源:admin  发布时间:

一、NFS (Network FileSystem)

网络文件系统
是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源。
在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样。

简单实现nfs的目录挂载 服务端配置:

1)安装软件包
    yum -y install nfs-utils rpcbind

2)配置

#vim /etc/exports [root@server ~]# cat /etc/exports /data 192.168.1.0/24(rw,all_squash,anonuid=6666,anongid=6666)

3)启动
    systemctl start nfs
    systemctl start rpcbind
 4)创建用户(建立一个新组,并设置组ID加入系统:)
    groupadd -g 6666 www
    useradd -u 6666 -g 6666 www

id www

 5)创建挂载目录
    mkdir -p /data/
    chown -R www.www /data

客户端配置:

 1)安装软件包
    yum -y install nfs-utils rpcbind

 2)启动
    systemctl start rpcbind
 3)检查服务端是否挂载成功
    [root@client ~]# showmount -e 192.168.1.224
    Export list for 192.168.1.224:
    /data 192.168.1.0/24
 4)挂载目录
    mount -t nfs 192.168.1.224:data /opt
 5)检查是否挂载成功
    [root@client ~]# df -h
    Filesystem               Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root   18G  1.1G   17G   7% /
    devtmpfs                 475M     0  475M   0% /dev
    tmpfs                    487M     0  487M   0% /dev/shm
    tmpfs                    487M  7.7M  479M   2% /run
    tmpfs                    487M     0  487M   0% /sys/fs/cgroup
    /dev/sda1                997M  133M  865M  14% /boot
    /dev/mapper/centos-var   997M  150M  847M  16% /var
    tmpfs                     98M     0   98M   0% /run/user/0
    192.168.1.224:/data       18G  1.1G   17G   7% /opt
  6)加入开机自启动
    [root@client ~]# cat /etc/fstab 
    192.168.1.224:/data/    /opt                    nfs     defaults        0 0

二、NTP(Network Time Protocol)

NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。

服务端:

查看自己的服务器有没有ntp软件
[root@m01 ~]# rpm -qa ntp
没有就装一个
[root@m01 ~]# yum -y install ntp
修改配置文件
[root@m01 ~]# vim /etc/ntp.conf
#server 0.centos.pool.ntp.org iburst        #注释掉原本的时间
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 127.127.1.0 iburst                   #添加一个新的服务时间,也可以是阿里云时间
启动服务并加入开机自启动
[root@m01 ~]# systemctl start ntpd
[root@m01 ~]# systemctl enable ntpd
查看是否同步
[root@m01 ~]# ntpq -p
              remote           refid      st t when poll reach   delay   offset  jitter
              ==============================================================================
              *LOCAL(0)        .LOCL.           5 l    3   64  377    0.000    0.000   0.000
设置防火墙打开udp123端口
[root@m01 ~]#firewall-cmd --permanent --add-port=123/udp
[root@m01 ~]#firewall-cmd --reload

客户端:

安装ntp,修改配置文件
yum -y install ntp
[root@backup ~]# vim /etc/ntp.conf
#server 0.centos.pool.ntp.org iburst           #原有的注释掉,新添加一个
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 192.168.1.224                             #服务的时间指向ntp的服务端
restrict 192.168.1.224 nomodify notrap noquery   #配置允许上游时间服务器主动修改本机的时间
启动服务加入开机自启动
[root@m01 ~]# systemctl start ntpd
[root@m01 ~]# systemctl enable ntpd
本地与服务端的时间同步
[root@backup ~]#ntpdate -u 192.168.1.224 
查看状态
[root@backup ~]# ntpq -p
               remote           refid      st t when poll reach   delay   offset  jitter            

============================================================================== *192.168.1.224 LOCAL(0) 6 u 20 64 377 0.179 0.003 0.426 ======================================================================================= 第二种 定时任务实现同步阿里云时间服务器 crontable -e # 定时任务 */10 * * * * /usr/sbin/ntpdate ntp1.aliyun.com &> /dev/null 5 SSH without password

上一篇:Fedora9建立交叉编译环境
下一篇:centos安装php