解决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/ apache日志文件显示写只读数据库被拒绝 \[root@baoguo accounts\]# ausearch -m AVC -ts recent \ 搜索审计信息显示找不到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 该步是关键:-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审计开关 我的操作系统平台是centos stream 9

相关推荐
言德斐18 小时前
Python Web框架深度对比:Django vs Flask vs FastAPI(含优缺点与选型策略)
前端·python·django
belldeep19 小时前
python:怎样用 Django 开发电子商务程序
django·电子商务·1024程序员节
清静诗意1 天前
【Django FilterSet 深入解析】类属性过滤器与 Meta.fields 的关系详解(附源码分析)
django·filter
大叔_爱编程1 天前
基于随机森林算法的Boss直聘数据分析及可视化-hadoop+django+spider
hadoop·django·1024程序员节·spider·随机森林算法·boss直聘
tritone1 天前
在优豆云免费云服务器上搭建与配置Apache的实践笔记
服务器·网络·apache·1024程序员节
白小筠2 天前
创建Django项目
数据库·django·sqlite
计算机毕业设计小帅2 天前
【2026计算机毕业设计】基于Django的社区婴幼儿预防接种系统
数据库·django·课程设计
黑猫酋长2 天前
Apache Zeppelin:一款强大的数据分析和可视化工具
数据挖掘·数据分析·apache
belldeep2 天前
网络安全:Apache Druid 安全漏洞
网络安全·apache·druid
SelectDB2 天前
Apache Doris 4.0 版本正式发布:全面升级 AI 与搜索能力,强化离线计算
数据库·数据分析·apache