本文主要是介绍Samba服务访问异常分析处理,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
之前在ubuntu上配置samba已经多次,今天突然发现,我的电脑映射到服务器的网盘无法访问了,在输入用户名和密码后,界面一直在“连接中”的界面,或者干脆提示无法访问。但删除网盘后再连接,还是会提示输入用户名和密码(这说明至少连接是正常的),输入之后同之前一样,连接中,或者无法访问。
一般这种情况应该是服务出了问题,类似之前配置SVN服务也是一样。不好检查,那我就卸载后重装下samba吧,结果除了挺多问题的。大概过程如下:
//卸载命令
sudo apt autoremove samba
//卸载最后提示有异常
Error: Sub-process /usr/bin/dpkg returned an error code (1)
按照gpt的提示,如下操:
//卸载 Samba 和依赖sudo apt remove --purge samba samba-common-bin//清理不再需要的依赖包sudo apt autoremove//删除残留的配置文件和数据sudo rm -rf /etc/sambasudo rm -rf /var/lib/samba//重启sudo reboot//重启后再安装apt-get install samba//安装最后提示如下错误
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:The following packages have unmet dependencies:
samba : Depends: python-samba but it is not going to be installed
Depends: samba-common (= 2:4.3.11+dfsg-0ubuntu0.16.04.34) but 2:4.15.13+dfsg-0ubuntu0.20.04.7 is to be installed
Depends: samba-common-bin (= 2:4.3.11+dfsg-0ubuntu0.16.04.34) but it is not going to be installed
Depends: libpython2.7 (>= 2.7) but it is not going to be installed
Depends: libwbclient0 (= 2:4.3.11+dfsg-0ubuntu0.16.04.34) but 2:4.15.13+dfsg-0ubuntu0.20.04.7 is to be installed
Depends: samba-libs (= 2:4.3.11+dfsg-0ubuntu0.16.04.34) but it is not going to be installed
Recommends: attr
Recommends: samba-dsdb-modules but it is not going to be installed
Recommends: samba-vfs-modules but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
如上提示,gpt提示2种可能:
错误表明你正在尝试安装的软件包版本之间存在不兼容性,特别是关于依赖关系。可能的原因是你的软件包存储库配置中存在问题,或者系统中有一些软件包处于 "held" 状态,无法进行升级或安装。
按照提示执行:
sudo apt update
sudo apt-get -f install
dpkg --get-selections | grep held //没有发现held的包#sudo apt-mark unhold <package_name> //如果发现有held的包,可以用此命令解除held状态//手动安装所有未满足的依赖包
sudo apt-get install python-samba samba-common=2:4.15.13+dfsg-0ubuntu0.20.04.7 samba-common-bin=2:4.15.13+dfsg-0ubuntu0.20.04.7 libpython2.7 libwbclient0=2:4.15.13+dfsg-0ubuntu0.20.04.7 samba-libs//尝试安装 Samba
sudo apt-get install samba
如上执行后,安装失败信息同上,此时gpt提示可能是sources.list有问题(一般安装问题和这个都有关系),我的sources.list文件如下:
kongcb@bull-ThinkStation-P330:~$ less /etc/apt/sources.list清华镜像源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverseubuntu版本和内核如下:
cat /proc/version
Linux version 5.15.0-107-generic (buildd@lcy02-amd64-017) (gcc (Ubuntu 9.4.0-1ubuntu120.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #11720.04.1-Ubuntu SMP Tue Apr 30 10:35:57 UTC 2024
Ubuntu 版本是 20.04(根据内核版本推断),而 /etc/apt/sources.list 文件中的软件源配置却指向了 Ubuntu 16.04(Xenial)的镜像。这是导致依赖关系问题的主要原因。
手动修改 /etc/apt/sources.list
//先备份
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak//修改文件如下
# 清华镜像源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
之后安装没有再出现如上的异常错误:
//之后更新正常了
sudo apt update//安装
sudo apt install samba//但是安装samba最后提示:
Load smb config files from /etc/samba/smb.conf
Error loading services.
dpkg: error processing package samba-common-bin (--configure):
installed samba-common-bin package post-installation script subprocess returned error exit status 1
No apport report written because the error message indicates its a followup error from a previous failure.
dpkg: dependency problems prevent configuration of samba:
samba depends on samba-common-bin (= 2:4.15.13+dfsg-0ubuntu0.20.04.7); however:
Package samba-common-bin is not configured yet.dpkg: error processing package samba (--configure):
dependency problems - leaving unconfigured
Processing triggers for ufw (0.36-6ubuntu1) ...
Processing triggers for systemd (245.4-4ubuntu3.20) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.15) ...
Errors were encountered while processing:
samba-common-bin
samba
E: Sub-process /usr/bin/dpkg returned an error code (1)
出现这个错误的原因可能是由于 Samba 安装过程中配置文件或依赖项存在问题。我们可以尝试以下步骤来解决这些问题
//清理和修复包管理器的状态:
sudo apt-get clean
sudo apt-get autoremove
sudo apt-get update
sudo apt-get install -f//重新配置未正确配置的软件包
sudo dpkg --configure -a
sudo apt-get install -f//手动删除并重新安装 Samba
sudo apt-get remove --purge samba samba-common samba-common-bin
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get update
sudo apt-get install samba//安装相关依赖
sudo apt-get install samba-common-bin
如上,安装成功,之后配置smb.conf,配置方式同之前:
[homes]
comment = Home Directories
browseable = noread only = nocreate mask = 0755directory mask = 0755valid users = %S//之后创建用户:sudo smbpasswd -a kongcb
//该用户已经在ubuntu中创建,且指定了家目录如下:
kongcb:x:1001:1001::/home/szbullsoft/kongcb:/bin/bash
但smba在用户创建,并重启服务后,远程映射磁盘的时候,提示输入密码,之后一直显示尝试连接,无法打开,现象同最开始一样的!!
对照gpt提示,逐步分析:
//1:检查Samba 服务是否正常运行
sudo systemctl status smbd
sudo systemctl status nmbd//2:确认用户是否已正确添加到 Samba
sudo pdbedit -Lkongcb@bull-ThinkStation-P330:/var/log$ sudo pdbedit -L
[sudo] password for kongcb:
kongcb:1001:
gaoh:1005:
jiaoyj:1002:
suqz:1006://3. 确认 Samba 配置文件正确
homes的配置之前都正常的//4,重启 Samba 服务
sudo systemctl restart smbd
sudo systemctl restart nmbd//5. 检查防火墙设置
//突然想到,应该就是防火墙配置导致的,之前配置SVN的时候,打开了ufw配置,
//先暂时关闭下防火墙:
sudo ufw disable//之后连接就正常了
//后续可以配置:sudo ufw allow samba
//打开防火墙,同时打开samba服务即可。
其实分析问题有个快捷方式,查看日志,如下:
sudo cat /var/log/syslog
可以查看到最新的日志,如下,基本都是提示 UFW BLOCK,就是防火墙在起作用:
Jun 18 09:03:15 bull-ThinkStation-P330 kernel: [ 2651.418220] [UFW BLOCK] IN=eno1 OUT= MAC=01:00:5e:00:00:01:24:9a:d8:38:f4:10:08:00 SRC=10.24.32.233 DST=224.0.0.1 LEN=72 TOS=0x00 PREC=0x00 TTL=1 ID=26822 DF PROTO=UDP SPT=38203 DPT=64120 LEN=52
Jun 18 09:03:33 bull-ThinkStation-P330 kernel: [ 2670.114480] [UFW BLOCK] IN=eno1 OUT= MAC=01:00:5e:00:00:01:24:9a:d8:38:f3:e8:08:00 SRC=10.24.32.232 DST=224.0.0.1 LEN=72 TOS=0x00 PREC=0x00 TTL=1 ID=16960 DF PROTO=UDP SPT=36270 DPT=64120 LEN=52
Jun 18 09:03:54 bull-ThinkStation-P330 kernel: [ 2690.929761] [UFW BLOCK] IN=eno1 OUT= MAC=01:00:5e:00:00:01:24:9a:d8:38:f4:10:08:00 SRC=10.24.32.233 DST=224.0.0.1 LEN=72 TOS=0x00 PREC=0x00 TTL=1 ID=29369 DF PROTO=UDP SPT=38203 DPT=64120 LEN=52
Jun 18 09:04:14 bull-ThinkStation-P330 kernel: [ 2710.636751] [UFW BLOCK] IN=eno1 OUT= MAC=01:00:5e:00:00:01:24:9a:d8:38:f3:a6:08:00 SRC=10.24.32.231 DST=224.0.0.1 LEN=72 TOS=0x00 PREC=0x00 TTL=1 ID=51155 DF PROTO=UDP SPT=36027 DPT=64120 LEN=52
Jun 18 09:04:33 bull-ThinkStation-P330 kernel: [ 2730.290711] [UFW BLOCK] IN=eno1 OUT= MAC=01:00:5e:00:00:01:80:5e:0c:85:f7:7e:08:00 SRC=10.24.32.234 DST=224.0.0.1 LEN=72 TOS=0x00 PREC=0x00 TTL=1 ID=59059 DF PROTO=UDP SPT=35631 DPT=64120 LEN=52
Jun 18 09:04:53 bull-ThinkStation-P330 kernel: [ 2750.150291] [UFW BLOCK] IN=eno1 OUT= MAC=01:00:5e:00:00:01:24:9a:d8:38:f3:a6:08:00 SRC=10.24.32.231 DST=224.0.0.1 LEN=72 TOS=0x00 PREC=0x00 TTL=1 ID=53512 DF PROTO=UDP SPT=36027 DPT=64120 LEN=52
Jun 18 09:05:14 bull-ThinkStation-P330 kernel: [ 2770.391963] [UFW BLOCK] IN=eno1 OUT= MAC=01:00:5e:00:00:01:24:9a:d8:38:f3:e8:08:00 SRC=10.24.32.232 DST=224.0.0.1 LEN=72 TOS=0x00 PREC=0x00 TTL=1 ID=21837 DF PROTO=UDP SPT=36270 DPT=64120 LEN=52
Jun 18 09:05:34 bull-ThinkStation-P330 kernel: [ 2790.345150] [UFW BLOCK] IN=eno1 OUT= MAC=01:00:5e:00:00:01:80:5e:0c:85:f7:7e:08:00 SRC=10.24.32.234 DST=224.0.0.1 LEN=72 TOS=0x00 PREC=0x00 TTL=1 ID=62173 DF PROTO=UDP SPT=35631 DPT=64120 LEN=52
Jun 18 09:05:54 bull-ThinkStation-P330 kernel: [ 2810.938679] [UFW BLOCK] IN=eno1 OUT= MAC=01:00:5e:00:00:01:24:9a:d8:38:f3:a6:08:00 SRC=10.24.32.231 DST=224.0.0.1 LEN=72 TOS=0x00 PREC=0x00 TTL=1 ID=56434 DF PROTO=UDP SPT=36027 DPT=64120 LEN=52
Jun 18 09:06:14 bull-ThinkStation-P330 kernel: [ 2830.731511] [UFW BLOCK] IN=eno1 OUT= MAC=01:00:5e:00:00:01:24:9a:d8:38:f4:10:08:00 SRC=10.24.32.233 DST=224.0.0.1 LEN=72 TOS=0x00 PREC=0x00 TTL=1 ID=36441 DF PROTO=UDP SPT=38203 DPT=64120 LEN=52
Jun 18 09:06:34 bull-ThinkStation-P330 kernel: [ 2850.403316] [UFW BLOCK] IN=eno1 OUT= MAC=01:00:5e:00:00:01:80:5e:0c:85:f7:7e:08:00 SRC=10.24.32.234 DST=224.0.0.1 LEN=72 TOS=0x00 PREC=0x00 TTL=1 ID=64499 DF PROTO=UDP SPT=35631 DPT=64120 LEN=52
gpt还提供日下几种方式检查,一并列举下:
//6:windows使用命令提示符尝试连接,并查看输出信息:net use \\10.32.24.7\kongcb /user:kongcb//7:确认共享目录权限
sudo chmod 755 /home/szbullsoft/kongcb
sudo chown kongcb:kongcb /home/szbullsoft/kongcb//8:使用IP地址连接,防止DNS问题导致的异常
net use \\10.13.1.189\kongcb /user:kongcb
以上就是samba服务异常的分析过程,中间包括了卸载程序方法及可能出现异常处理,希望对以后的问题处理有帮助
这篇关于Samba服务访问异常分析处理的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!