![Graphite SQLite3 DatabaseError:尝试写入只读数据库](https://linux22.com/image/640243/Graphite%20SQLite3%20DatabaseError%EF%BC%9A%E5%B0%9D%E8%AF%95%E5%86%99%E5%85%A5%E5%8F%AA%E8%AF%BB%E6%95%B0%E6%8D%AE%E5%BA%93.png)
在 apache httpd 下运行 graphite,使用 slqite 数据库,我拥有正确的文件夹权限
[root@liaan55 httpd]# ls -ltr /var/lib | grep graphite
drwxr-xr-x. 2 apache apache 4096 Aug 23 19:36 graphite-web
和
[root@liaan55 httpd]# ls -ltr /var/lib/graphite-web/
total 68
-rw-r--r--. 1 apache apache 65536 Aug 23 19:46 graphite.db
syncdb 似乎也运行正常
[root@liaan55 httpd]# sudo -su apache
bash-4.1$ whoami
apache
bash-4.1$ python /usr/lib/python2.6/site-packages/graphite/manage.py syncdb
/usr/lib/python2.6/site-packages/graphite/settings.py:231: UserWarning: SECRET_KEY is set to an unsafe default. This should be set in local_settings.py for better security
warn('SECRET_KEY is set to an unsafe default. This should be set in local_settings.py for better security')
/usr/lib/python2.6/site-packages/django/conf/__init__.py:75: DeprecationWarning: The ADMIN_MEDIA_PREFIX setting has been removed; use STATIC_URL instead.
"use STATIC_URL instead.", DeprecationWarning)
/usr/lib/python2.6/site-packages/django/core/cache/__init__.py:82: DeprecationWarning: settings.CACHE_* is deprecated; use settings.CACHES instead.
DeprecationWarning
Creating tables ...
Creating table account_profile
Creating table account_variable
Creating table account_view
Creating table account_window
Creating table account_mygraph
Creating table dashboard_dashboard_owners
Creating table dashboard_dashboard
Creating table events_event
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table django_session
Creating table django_admin_log
Creating table django_content_type
Creating table tagging_tag
Creating table tagging_taggeditem
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'apache'): root
E-mail address: [email protected]
Password:
Password (again):
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
bash-4.1$ exit
local-settings.py 文件如下
STORAGE_DIR = '/var/lib/graphite-web'
INDEX_FILE = '/var/lib/graphite-web/index'
DATABASES = {
'default': {
'NAME': '/var/lib/graphite-web/graphite.db',
'ENGINE': 'django.db.backends.sqlite3',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': ''
}
}
我仍然收到此错误
[Sat Aug 23 19:47:17 2014] [error] [client 10.42.33.238] File "/usr/lib/python2.6/site-packages/django/db/backends/sqlite3/base.py", line 344, in execute
[Sat Aug 23 19:47:17 2014] [error] [client 10.42.33.238] return Database.Cursor.execute(self, query, params)
[Sat Aug 23 19:47:17 2014] [error] [client 10.42.33.238] DatabaseError: attempt to write a readonly database
不确定此配置中缺少什么
答案1
检查了父级(即 )的所有者和组/var/lib/graphite
。结果发现两者都是 ,_graphite
而不是apache
。将所有者和组更改为_graphite
并重新启动apache2
:
user@host:~$ sudo chown _graphite:_graphite /var/lib/graphite/graphite.db
user@host:~$ sudo service apache2 restart
解决了 Ubuntu Xenial 上的问题。
答案2
来自石墨安装文件:
如果您在访问数据库文件时遇到问题,则可能需要将数据库文件的所有权更改为拥有 Apache 进程的同一用户。如果您的发行版以用户“nobody”的身份运行 apache:
sudo chown nobody:nobody /opt/graphite/storage/graphite.db
就我而言,由于我在 CentOS 上使用 Graphite 的 RPM 安装,因此 graphite.db 文件位于此处:
-rw-r--r-- 1 apache apache 69632 Sep 30 08:02 /var/lib/graphite-web/graphite.db