当前位置: 首页 > news >正文

解决django.db.utils.OperationalError: attempt to write a readonly database问题

打开浏览器访问learning_log登录页面,出现如下错误:

执行如下命令:
[root@baoguo learning_log]# ll db.sqlite3
-rwxrwxrwx. 1 zhang zhang 147456 Oct  2 16:11 db.sqlite3
[root@baoguo learning_log]# ll -d .
drwxrwxrwx. 12 zhang zhang 4096 Oct  2 16:11 .
显示文件和目录权限为777,任何用户有写入的权限。

cat /var/log/httpd/error_log
[Thu Oct 02 14:31:43.373497 2025] [wsgi:error] [pid 7466:tid 7626] [client 192.168.1.44:55482] django.db.utils.OperationalError: attempt to write a readonly database, referer: http://192.168.1.101/accounts/register/
日志文件显示写入只读数据库被拒绝

[root@baoguo accounts]# ausearch -m AVC -ts recent
<no matches>
审计信息显示找不到selinux访问拒绝记录

[root@baoguo learning_log]# man semodule
EXAMPLE
# Turn on all AVC Messages for which SELinux currently is "dontaudit"ing.
$ semodule -DB
[root@baoguo learning_log]# semodule -DB
重点:该选项打开AVC审计信息

[root@baoguo learning_log]# ausearch -m AVC -ts recent
type=AVC msg=audit(1759392419.488:4923): avc:  denied  { setattr } for  pid=8104 comm="rpm" name="rpmdb.sqlite-shm" dev="dm-0" ino=67240075 scontext=system_u:system_r:setroubleshootd_t:s0 tcontext=system_u:object_r:rpm_var_lib_t:s0 tclass=file permissive=0
有AVC记录了

[root@baoguo learning_log]# ausearch -m AVC -ts recent | audit2why
type=AVC msg=audit(1759392468.280:4934): avc:  denied  { net_admin } for  pid=7462 comm="httpd" capability=12  scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:system_r:httpd_t:s0 tclass=capability permissive=0
Was caused by:
Missing type enforcement (TE) allow rule.
You can use audit2allow to generate a loadable module to allow this access.
从AVC记录分析拒绝原因和解决方法

[root@baoguo learning_log]# grep httpd /var/log/audit/audit.log | audit2allow -M net_admin
******************** IMPORTANT ***********************
To make this policy package active, execute:
semodule -i net_admin.pp
生成允许访问策略

[root@baoguo learning_log]# semodule -i net_admin.pp
安装策略模块

[root@baoguo learning_log]# cat net_admin.te
module net_admin 1.0;
require {
type user_home_t;
type httpd_t;
class capability net_admin;
class dir write;
}
#============= httpd_t ==============
allow httpd_t self:capability net_admin;
allow httpd_t user_home_t:dir write;
te(type enforement)文件定义的具体规则
所以解决该问题的关键步骤是执行semodule -DB命令以打开AVC审计开关

http://www.dtcms.com/a/434563.html

相关文章:

  • Django SimpleUI 配置与优化详解
  • 从入门到精通:Django的深度探索之旅
  • 【数据结构】考研重点掌握:顺序查找算法实现与ASL计算详解
  • 大型网站建立1800做网站因为专业
  • 医疗AI平台化转型:从单点试点到体系化建设的互操作性与质量控制路径研究(上)
  • 做装修效果图的网站沈阳哪有wordpress
  • Linux命令行指令返回值data空降Python的机枪与大炮(DeepSeek)
  • c++中this指针使用bug
  • 网站源码中国有限公司外贸网站建设怎么制作
  • 哪家公司做网站专业安装wordpress主题放哪里
  • 我们为什么要封装 localStorage
  • 【AI论文】LongLive:实时交互式长视频生成
  • 企业网站推广总结网站降权是什么意思
  • 消息队列(面试)
  • Presto:一款免费开源的大数据SQL查询引擎
  • AI驱动的软件测试变革:从自动化框架到智能决策
  • The 2024 ICPC Asia Nanjing Regional Contest(2024南京区域赛EJKBG)
  • 面试场景题-
  • 怎样接做网站的活做校园网站代码
  • 【github】秘钥
  • 申请网站建设费教育网站制作定制
  • 网站ipv6改造怎么做让别人做网站怎样才安全
  • 开源库入门教程 Cesium:3D地球和地图库
  • WSL2 的 Ubuntu 系统从 G 盘移动到 F 盘
  • ubuntu20.04编译qt源码5.15.3
  • 保定哪家公司做网站安徽优化推广
  • 网站服务器租赁费用表格网络营销的效果表现在哪几个方面
  • HarmonyOS应用深度开发:ArkTS语法精解与状态管理实践
  • 开源 C# 快速开发(十六)数据库--sqlserver增删改查
  • 在相亲网站认识了一个做红酒生意的深圳做品牌网站