部署samba操作记录
在Linux上面有特别多的储存服务,这边小编主要记录samba的操作记录,
其实来说samba是一个实现Linux与Windows之间传输的一个较好的工具,就搭建这块来说还是比较简单的
安装samba之前系统配置
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
#更改主机名,修改完重启生效,暂时不要重启,因为下面修改selinux也需要重启
[root@localhost ~]# hostnamectl set-hostname samba-server
[root@localhost ~]# vim /etc/selinux/config
-bash: vim: 未找到命令 #这个报错说的饿是没有vim命令,不用管,下面我们用vi命令
#修改selinux的配置文件,关闭selinix
[root@localhost ~]# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=diaabled #主要是修改这一行,修改完之后重启生效
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@localhost ~]# init 6 #重启服务器
[root@samba-server ~]# rpm -aq | grep samba #检查之前有没有安装过samba,如果用的话,请自行百度移除
[root@samba-server ~]# yum -y install samba #yum安装samba
已加载插件:fastestmirror
Determining fastest mirrors
#################省去中间过程
完毕!
添加samba到防火墙
[root@samba-server ~]# firewall-cmd --add-service samba --permanent #添加到防火墙
success
[root@samba-server ~]# firewall-cmd --reload #重启防火墙
success
[root@samba-server ~]# firewall-cmd --list-all|grep samba #检查防火墙规则,是不是正确添加了samba
services: ssh dhcpv6-client samba
[root@samba-server ~]# getenforce
Permissive
配置samba的配置文件
[root@samba-server ~]# cp /etc/samba/smb.conf /etc/samba/smb.conf.bak #将配置文件进行备份
[root@samba-server ~]# vi /etc/samba/smb.conf #修改配置文件
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.
[global]
workgroup = SAMBA
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
##下面是需要我们手动添加上去的
[samba]
comment = This is samba #这个就是一个描述提示
path = /home/samba #需要共享的目录
writable = yes #支持写
public = no #不公开
为samba添加账号
root@samba-server ~]# useradd -d /home/samba -s /sbin/nologin samba #添加一个叫samba的系统用户
[root@samba-server ~]# id samba #查看是否添加成功
uid=1000(samba) gid=1000(samba) 组=1000(samba)
[root@samba-server ~]# pdbedit -a -u samba #为这个samba账号授权添加到samba服务中
new password: #设置密码
retype new password: #验证密码
Unix username: samba
NT username:
Account Flags: [U ]
User SID: S-1-5-21-3049709432-1464918937-3569770485-1000
Primary Group SID: S-1-5-21-3049709432-1464918937-3569770485-513
Full Name:
Home Directory: \\samba-server\samba
HomeDir Drive:
Logon Script:
Profile Path: \\samba-server\samba\profile
Domain: SAMBA-SERVER
Account desc:
Workstations:
Munged dial:
Logon time: 0
Logoff time: 三, 06 2月 2036 23:06:39 CST
Kickoff time: 三, 06 2月 2036 23:06:39 CST
Password last set: 六, 06 3月 2021 11:13:41 CST
Password can change: 六, 06 3月 2021 11:13:41 CST
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
启动samba.
[root@samba-server ~]# chown -Rf samba.samba /home/samba #为samba账号访问的目录授权
[root@samba-server ~]# systemctl start smb #启动samba服务
[root@samba-server ~]# systemctl enable smb #添加到开机自启动里面
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
[root@samba-server ~]# systemctl status smb #查看当前samba状态
● smb.service - Samba SMB Daemon
Loaded: loaded (/usr/lib/systemd/system/smb.service; enabled; vendor preset: disabled)
Active: active (running) since 六 2021-03-06 11:14:40 CST; 31s ago
Docs: man:smbd(8)
man:samba(7)
man:smb.conf(5)
Main PID: 1494 (smbd)
Status: "smbd: ready to serve connections..."
CGroup: /system.slice/smb.service
├─1494 /usr/sbin/smbd --foreground --no-process-group
├─1496 /usr/sbin/smbd --foreground --no-process-group
├─1497 /usr/sbin/smbd --foreground --no-process-group
└─1498 /usr/sbin/smbd --foreground --no-process-group
3月 06 11:14:40 samba-server systemd[1]: Starting Samba SMB Daemon...
3月 06 11:14:40 samba-server smbd[1494]: [2021/03/06 11:14:40.72843...
3月 06 11:14:40 samba-server systemd[1]: Started Samba SMB Daemon.
3月 06 11:14:40 samba-server smbd[1494]: daemon_ready: daemon 'sm...
Hint: Some lines were ellipsized, use -l to show in full.
##在配置文件中的共享目录里面创建几个测试文件
[root@samba-server ~]# cd /home/samba/
[root@samba-server samba]# ls
[root@samba-server samba]# mkdir a aa aaa
[root@samba-server samba]# touch b.txt bb.txt bbb.txt
[root@samba-server samba]# echo 123 > b.txt
[root@samba-server samba]# ls
a aa aaa bbb.txt bb.txt b.txt
验证一下下
结束语
Linux的存储方式有好多种,小编的其他文章会做一个简单的介绍,谢谢大家赏脸