CentOS服务搭建-02-samba文件服务
安装并启动Samba
- yum -y install samba
- systemctl start smb.service
- 关闭安全防护
- vim /etc/sysconfig/selinux
- SELINUX=enforcing 改为 SELINUX=disabled # 关闭selinux
- systemctl disable firewalld.service # 关闭防火墙
- shutdown -r now # 重启使生效
- 注:
- 防火墙不关闭,所有节点无法进行挂载。也可以采用:防火墙放行TCP端口:139、445以及UDP端口:137、138。
- selinux不关闭,无法查看共享文件夹下的文件。
配置samba共享目录
- sudo vi /etc/samba/smb.conf
- [rpi_web_notebooks]
- -- comment = 树莓派jupyter notebook目录
- -- path = /home/pi/web_notebooks
- -- browseable = Yes
- -- read only = No
- -- public = yes
- -- guest ok = yes
- -- writable = yes
- -- create mask = 0777
- -- directory mask = 0777
启动samba服务并设置自启动
- sudo systemctl start smb
- sudo systemctl enable smb.service # 设置开机启动
- sudo systemctl status smb
修改防火墙
- sudo firewall-cmd --zone=public --add-port=139/tcp --permanent
- sudo firewall-cmd --zone=public --add-port=445/tcp --permanent
- sudo firewall-cmd --zone=public --add-port=137/udp --permanent
- sudo firewall-cmd --zone=public --add-port=138/udp --permanent
- sudo firewall-cmd --reload
- sudo systemctl restart firewalld.service
配置文件共享、用户、samba
- 创建共享目录:
- mkdir /share
- 创建用户组和用户:
- groupadd samba
- useradd -g samba share
- passwd share
- 添加samba文件共享用户
- smbpasswd -a share
- 修改samba配置
- vi /etc/samba/smb.conf
- 内容修改为:
- [global]
- workgroup = SAMBA
- security = user
- map to guest = Bad User
- log file = /var/log/samba/log.%m
- [public]
- comment = Public Directories
- valid users = @samba
- read only = Yes
- path = /share
- hosts allow = 192.168.
- 注:secutity用来指定安全模式,user模式是需要账号密码来登录共享的
- valid users = @用户组,用来指定允许登录的用户组
- path指定共享的路径
- hosts allow用来指定开放的ip段,当前指定的是对192.168下的所有ip都开放
重启samba服务
systemctl restart smb.service testparm
客户端进行文件挂载
mkdir /share mount -t cifs //文件服务器ip/public /share -o "username=share,password=xxx"