Samba服务访问异常分析处理

2024-06-18 21:20

本文主要是介绍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服务访问异常分析处理的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1073091

相关文章

Debian 13升级后网络转发等功能异常怎么办? 并非错误而是管理机制变更

《Debian13升级后网络转发等功能异常怎么办?并非错误而是管理机制变更》很多朋友反馈,更新到Debian13后网络转发等功能异常,这并非BUG而是Debian13Trixie调整... 日前 Debian 13 Trixie 发布后已经有众多网友升级到新版本,只不过升级后发现某些功能存在异常,例如网络转

C#文件复制异常:"未能找到文件"的解决方案与预防措施

《C#文件复制异常:未能找到文件的解决方案与预防措施》在C#开发中,文件操作是基础中的基础,但有时最基础的File.Copy()方法也会抛出令人困惑的异常,当targetFilePath设置为D:2... 目录一个看似简单的文件操作问题问题重现与错误分析错误代码示例错误信息根本原因分析全面解决方案1. 确保

sysmain服务可以禁用吗? 电脑sysmain服务关闭后的影响与操作指南

《sysmain服务可以禁用吗?电脑sysmain服务关闭后的影响与操作指南》在Windows系统中,SysMain服务(原名Superfetch)作为一个旨在提升系统性能的关键组件,一直备受用户关... 在使用 Windows 系统时,有时候真有点像在「开盲盒」。全新安装系统后的「默认设置」,往往并不尽编

Python自动化处理PDF文档的操作完整指南

《Python自动化处理PDF文档的操作完整指南》在办公自动化中,PDF文档处理是一项常见需求,本文将介绍如何使用Python实现PDF文档的自动化处理,感兴趣的小伙伴可以跟随小编一起学习一下... 目录使用pymupdf读写PDF文件基本概念安装pymupdf提取文本内容提取图像添加水印使用pdfplum

C# LiteDB处理时间序列数据的高性能解决方案

《C#LiteDB处理时间序列数据的高性能解决方案》LiteDB作为.NET生态下的轻量级嵌入式NoSQL数据库,一直是时间序列处理的优选方案,本文将为大家大家简单介绍一下LiteDB处理时间序列数... 目录为什么选择LiteDB处理时间序列数据第一章:LiteDB时间序列数据模型设计1.1 核心设计原则

Python 基于http.server模块实现简单http服务的代码举例

《Python基于http.server模块实现简单http服务的代码举例》Pythonhttp.server模块通过继承BaseHTTPRequestHandler处理HTTP请求,使用Threa... 目录测试环境代码实现相关介绍模块简介类及相关函数简介参考链接测试环境win11专业版python

基于Redis自动过期的流处理暂停机制

《基于Redis自动过期的流处理暂停机制》基于Redis自动过期的流处理暂停机制是一种高效、可靠且易于实现的解决方案,防止延时过大的数据影响实时处理自动恢复处理,以避免积压的数据影响实时性,下面就来详... 目录核心思路代码实现1. 初始化Redis连接和键前缀2. 接收数据时检查暂停状态3. 检测到延时过

Nginx中配置使用非默认80端口进行服务的完整指南

《Nginx中配置使用非默认80端口进行服务的完整指南》在实际生产环境中,我们经常需要将Nginx配置在其他端口上运行,本文将详细介绍如何在Nginx中配置使用非默认端口进行服务,希望对大家有所帮助... 目录一、为什么需要使用非默认端口二、配置Nginx使用非默认端口的基本方法2.1 修改listen指令

Java利用@SneakyThrows注解提升异常处理效率详解

《Java利用@SneakyThrows注解提升异常处理效率详解》这篇文章将深度剖析@SneakyThrows的原理,用法,适用场景以及隐藏的陷阱,看看它如何让Java异常处理效率飙升50%,感兴趣的... 目录前言一、检查型异常的“诅咒”:为什么Java开发者讨厌它1.1 检查型异常的痛点1.2 为什么说

SysMain服务可以关吗? 解决SysMain服务导致的高CPU使用率问题

《SysMain服务可以关吗?解决SysMain服务导致的高CPU使用率问题》SysMain服务是超级预读取,该服务会记录您打开应用程序的模式,并预先将它们加载到内存中以节省时间,但它可能占用大量... 在使用电脑的过程中,CPU使用率居高不下是许多用户都遇到过的问题,其中名为SysMain的服务往往是罪魁