日常小记2--利用samba部署文件共享服务

今天闲来无事,就用samba部署了个文件共享服务

注:笔记参考刘遄老师的喔

1.首先安装samba服务

[root@localhost ~]# yum install samba samba-client
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.sjtu.edu.cn
 * extras: ftp.sjtu.edu.cn
 * updates: ftp.sjtu.edu.cn

2.删除掉【printers】和【print$】两个累赘,当然了,【home】留着方便共享,但多多少少有点危险,自己看着办

[root@localhost ~]# vim /etc/samba/smb.conf

3.创建账户

[root@localhost ~]# pdbedit -a -u centos
new password:
retype new password:
Unix username:        centos
NT username:          
Account Flags:        [U          ]
<此处省略部分内容>         

4.创建文件夹,由于是共享,需要注意权限

[root@localhost ~]# mkdir /home/database
[root@localhost ~]# chown -Rf centos:centos /home/database
[root@localhost ~]# semanage fcontext -a -t samba_share_t /home/database
[root@localhost ~]# restorecon -Rv /home/database
restorecon reset /home/database context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:samba_share_t:s0

5.筛选出于samba相关的策略

[root@localhost ~]# getsebool -a | grep samba
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> off
samba_export_all_ro --> off
samba_export_all_rw --> off
samba_load_libgfapi --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
tmpreaper_use_samba --> off
use_samba_home_dirs --> off
virt_use_samba --> off

6.将samba_enable_home_dirs改为开启

[root@localhost ~]# setsebool -P samba_enable_home_dirs on
[root@localhost ~]# getsebool -a | grep samba
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> on
samba_export_all_ro --> off
samba_export_all_rw --> off
samba_load_libgfapi --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
tmpreaper_use_samba --> off
use_samba_home_dirs --> off
virt_use_samba --> off

7.在 /etc/samba/smb.conf中写入以下信息

[database]
        comment = Do not arbitrarily modify the database file
        path = /home/database
        public = no
        writable = yes

8.老规矩,记得重启和加入自启

[root@localhost ~]# systemctl restart smb
[root@localhost ~]# systemctl enable smb
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.

9.万一防火墙限制共享咋办?那就-F给清掉然后将samba添加到防火墙策略

[root@localhost ~]# iptables -F
[root@localhost ~]# iptables-save
# Generated by iptables-save v1.4.21 on Thu Jul 15 14:01:51 2021
*nat
:PREROUTING ACCEPT [13:1705]
:INPUT ACCEPT [1:48]
<此处省略部分内容>
[root@localhost ~]# firewall-cmd --zone=public --permanent --add-service=samba
success
[root@localhost ~]# firewall-cmd --reload
success

10.共享了什么,一目了然(ip地址为本机的ip)

[root@localhost ~]# smbclient -U centos -L 192.168.xx.xxx
Enter SAMBA\centos's password: 

	Sharename       Type      Comment
	---------       ----      -------
	database        Disk      Do not arbitrari
	IPC$            IPC       IPC Service (Samba 4.10.16)
Reconnecting with SMB1 for workgroup listing.

	Server               Comment
	---------            -------

	Workgroup            Master
	---------            -------

11.接下来用windows10来连接centos的共享服务,win+r,\192.168.xx.xxx,然后会弹出一个用户名和密码,输入自己设定的即可成功访问

window访问界面

12.如果在centos之间访问,则需要在客户端那边安装

[root@localhost ~]# yum install cifs-utils
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.ustc.edu.cn
<此处省略部分内容>

13.创建一个用于挂载共享文件的目录,挂载时名字密码为共享机子的名字密码

[root@localhost ~]# mkdir /database
[root@localhost ~]# mount -t cifs -o username=centos,password=1234 //192.168.xx.xxx/database /database
[root@localhost ~]# df -h
文件系统                   容量  已用  可用 已用% 挂载点
devtmpfs                   894M     0  894M    0% /dev
tmpfs                      910M     0  910M    0% /dev/shm
tmpfs                      910M   11M  900M    2% /run
tmpfs                      910M     0  910M    0% /sys/fs/cgroup
/dev/mapper/centos-root     17G  6.4G   11G   38% /
/dev/sda1                 1014M  185M  830M   19% /boot
tmpfs                      182M   36K  182M    1% /run/user/0
/dev/sr0                   4.4G  4.4G     0  100% /run/media/root/CentOS 7 x86_64
//192.168.xx.xxx/database   17G  4.5G   13G   27% /database

14.为了避免每次开机都得重新连共享机子的麻烦,直接将samba用户密码写入认证文件中,记得设置为管理员才可见喔,再将挂载信息写入fstab中

[root@localhost ~]# vim auth.smb
username=centos
password=1234
domain=MYGROUP
[root@localhost ~]# chmod 600 auth.smb
[root@localhost ~]# vim /etc/fstab
//192.168.10.10/database                   /database     cifs    credentials=/root/auth.smb  0 0
[root@localhost ~]# mount -a

15.centos之间成功实现共享

[root@localhost ~]# cat /database/aisen1234
I love three things in this world
the sun,the moon,and you
sun for morning
moon for night
and you forever!

小菜鸡日常小记,打发打发时间

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值