Tải bản đầy đủ (.pdf) (8 trang)

Topic 11 File Sharing

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (581.12 KB, 8 trang )

Topic 11: File Sharing
NFS Server Configuration
Samba Server Configuration


NFS Server Configuration
NFS: là dịch vụ chia sẻ file giữa các máy linux
1. Cài đặt NFS
NFS là dịch vụ hỗ trợ cơ chế chia sẻ tài nguyên giữa các máy chủ Linux.
- Kiểm tra NFS đã được cài đặt hay chưa:
[root@localhost ~]# rpm -qa | grep nfs
libnfsidmap-0.25-17.el7.x86_64
nfs4-acl-tools-0.3.3-15.el7.x86_64
nfs-utils-1.3.0-0.48.el7.x86_64
Ngồi ra NFS cịn đỏi hỏi phải có một Daemon quan trọng dùng để quản lý các kết nối đó là
rpcbind. Mặc định rpcbind được cài đặt sẵn trên hệ thống. rpcbind listen trên TCP port 111.
- Kiểm tra rpcbindđã được cài đặt trên hệ thống:
[root@localhost Desktop]# rpm -qa rpcbind
rpcbind-0.2.0-26.el7.x86_64
2. Cấu hình NFS server
# vi /etc/idmapd.conf
5 Domain = nhatnghe.com
file dùng để cấu hình NFS là /etc/exports
- Tạo một thư mục chia sẻ như sau:
[root@may1 ~]# mkdir -p /data/{software,dulieu,database}
[root@may1 ~]# cp -rv /etc/* /data/dulieu/
- Cấp quyền truy cập vào thư mục /share:
[root@may1 ~]# chmod 777 /data/dulieu/
[root@may1 ~]# chmod 777 /data/database/
- Sửa file /etc/exports thêm vào dịng sau:
/data/software


*(ro,sync)
/data/dulieu
192.168.1.0/24(rw,sync)
/data/database
192.168.1.100/32(rw,sync)
NFS Gồm có các quyền truy cập thơng dụng như sau:
secure
: Port từ client requests phải nhỏ hơn 1024
ro
: Read only
rw
: Read – write
noaccess
: Denied access
root_squash
: Ngăn remote root users
no_root_squash
: Cho phép remote root users
- Khởi động các dich vụ:
# systemctl restart rpcbind
# systemctl start nfs-server
#systemctl start nfs-lock
#systemctl start nfs-idmap
154

Phiên Bản Thử Nghiệm – Lưu Hành Nội Bộ


# systemctl enable rpcbind
# systemctl enable nfs-server

# systemctl enable nfs-lock
# systemctl enable nfs-idmap
- Kiểm tra rpcbind daemon:
[root@may1 ~]# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address
tcp
0 0 0.0.0.0:111
0.0.0.0:*
tcp
0 0 0.0.0.0:22
0.0.0.0:*

State
LISTEN
LISTEN

PID/Program name
1471/rpcbind
8502/sshd

Lưu ý: sau khi thay đổi file /etc/exports bạn phải restart daemon nfs hay dùng các lệnh sau:
exportfs -a
: Reload lại tồn bộ cấu hình cho NFS
exportfs -r
: Reload lại những thay đổi trong cấu hình cho NFS
- Do NFS cần mở một số port khi chạy như (111, 2049..) nên ta cần cấu hình firewall mở các port
này hay tắt firewall:
- Kiểm tra nfs đã được quản trị bởi rpcinfo
[root@may1 ~]# rpcin

100000 4 tcp6
100000 3 tcp6
100000 4 udp6
100000 3 udp6
100000 4 tcp
100000 3 tcp
100000 2 tcp
100000 4 udp

o
::.0.111
::.0.111
::.0.111
::.0.111
0.0.0.0.0.111
0.0.0.0.0.111
0.0.0.0.0.111
0.0.0.0.0.111

portmapper superuser
portmapper superuser
portmapper superuser
portmapper superuser
portmapper superuser
portmapper superuser
portmapper superuser
portmapper superuser

3. Cấu hình NFS client:
3.1. Cấu hình truy cập bằng tay

- Tạo thư mục:
[root@localhost ~]# mkdir -p /server/{software,dulieu,database}
- Mount NFS file:
[root@localhost ~]# mount -t nfs 192.168.1.101:/data/software /server/software
[root@localhost ~]# mount -t nfs 192.168.1.101:/data/dulieu /server/dulieu
[root@localhost ~]# mount -t nfs 192.168.1.101:/data/database /server/database
- Kiểm tra các mount point trên hệ thống:


- Kiểm tra:

3.2. Cấu hình truy cập trong file /etc/fstab
- Sửa file /etc/fstab như sau:
[root@localhost ~]# vi /etc/fstab
[root@localhost ~]# vi /etc/fstab
tmpfs defaults
00
tmpfs
/dev/shm
devpts
/dev/pts
devpts gid=5,mode=620 0 0
sysfs
/sys
sysfs defaults
00
proc
/proc
proc defaults
00

192.168.1.101:/data/software /server/software
nfs soft,nfsvers=2 0 0
192.168.1.101:/data/dulieu /server/dulieu
nfs soft,nfsvers=2 0 0
192.168.1.101:/data/database /server/database
nfs soft,nfsvers=2 0 0
- Reboot lại hệ thống: init 6
- mount, kiểm tra các mount point đã được tạo.
chú ý: sử dụng lệnh man nfsstat để xem thêm các option của lênh nfsstat.
- Liệt kê danh sách các portmapper đã đăng ký trên host
[root@may1 ~]# rpcinfo -p localhost
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 34563 status
100024 1 tcp 41552 status

156

Phiên Bản Thử Nghiệm – Lưu Hành Nội Bộ


Samba server
1. Cài đặt samba:
Là dịch vụ hỗ trợ chia sẻ tài nguyên từ hệ thống Linux với các hệ thống khác như Linux,
Windows.

- Kiểm tra samba đã được cài đặt hay chưa:
# rpm -qa | grep samba
samba-common-4.1.12-21.el7_1.x86_64
samba-4.1.12-21.el7_1.x86_64
samba-client-4.1.12-21.el7_1.x86_64
samba-libs-4.1.12-21.el7_1.x86_64
2. Cấu hình samba server
- Tạo cây thư mục chia sẻ như sau:
[root@may1 ~]# mkdir -p /nhatnghe/{giaovien,hocsinh,baithi,software}
[root@may1 ~]# chmod 777 /nhatnghe/giaovien/
[root@may1 ~]# chmod 777 /nhatnghe/hocsinh
[root@may1 ~]# chmod 777 /nhatnghe/baithi
[root@may1 ~]#
- Sửa file /etc/samba/smb.conf sửa các dòng sau:
[root@may1 ~]# vi /etc/samba/smb.conf
Thêm dòng
66 unix charset = UTF-8
Sửa dòng:
89
workgroup = WORKGROUP
124
passdb backend = smbpasswd
- Tạo user truy cập
[root@may1 ~]# groupadd giaovien
[root@may1 ~]# groupadd hocsinh
[root@may1 ~]# useradd -G giaovien gv1
[root@may1 ~]# useradd -G giaovien gv2
[root@may1 ~]# useradd -G hocsinh hs1
[root@may1 ~]# useradd -G hocsinh hs2
- Tạo mật khẩu cho người dùng samba

[root@may1 ~]# smbpasswd -a gv1
[root@may1 ~]# smbpasswd -a gv2
[root@may1 ~]# smbpasswd -a hs1
[root@may1 ~]# smbpasswd -a hs2
- Start daemon smb:
[root@localhost Desktop]# systemctl start smb
[root@localhost Desktop]# systemctl start nmb


[root@localhost Desktop]# systemctl enable smb
ln -s '/usr/lib/systemd/system/smb.service' '/etc/systemd/system/multiuser.target.wants/smb.service'
[root@localhost Desktop]# systemctl enable nmb
ln -s '/usr/lib/systemd/system/nmb.service' '/etc/systemd/system/multiuser.target.wants/nmb.service'
- Do samba cần mở một số port khi chạy như (139,445,..) nên ta cần cấu hình firewall mở các
port này hay tắt firewall:
3. Cấu hình samba client
3.1. Trên Windows
Vào Start menu -> chọn Run: \\192.168.1.101
Nhập user hs1, password: 123

3.2. Trên Linux
- Tạo thư mục:
[root@localhost ~]# mkdir /giaovien/
- Mount smb file:
[root@localhost ~]# mount -o username=gv1,password=123 //192.168.1.20/gv1 /giaovien
4. Share tài nguyên file
[global]
workgroup = MYGROUP
server string = Samba Server Version %v
passdb backend = smbpasswd

log file = /var/log/samba/log.%m
max log size = 50
create mask = 0766
directory mask = 0777
cups options = raw
[homes]

158

Phiên Bản Thử Nghiệm – Lưu Hành Nội Bộ


comment = Home Directories
read only = No
browseable = No
[printers]
comment = All Printers
path = /var/spool/samba
printable = Yes
browseable = No
# Tạo share hocsinh: mọi user có thể đọc, ghi
[Hocsinh]
comment = Du lieu dung chung
path = /nhatnghe/hocsinh
read only = No
# Tạo share Baithi: nhóm giaovien được đọc, ghi, nhóm
hocsinh chỉ có thể đọc
[Baithi]
comment = Bai thi hoc ky
path = /nhatnghe/baithi

valid users = +hocsinh, +giaovien
write list = +giaovien
# Tạo share Giaovien, gv1 tạo, gv2 không thể xem
[Giaovien]
comment = Bai thi hoc ky
path = /nhatnghe/giaovien
valid users = +giaovien
write list = +giaovien
create mask = 0760
directory mask = 0770
# Tạo share Software mọi user chỉ đọc
[Software]
comment = Phan mem co ban
path = /nhatnghe/software
# Tạo share ẩn bgh chỉ có user ht mới có thể truy cập
[bgh]
comment = Ban giam hieu
path = /nhatnghe/bgh
valid users = ht
read only = No
browseable = No

Tại client thử truy cập: \\192.168.1.101


160

Phiên Bản Thử Nghiệm – Lưu Hành Nội Bộ




Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×