cuckoo数据库变更

1、cuckoo版本升级

cuckoo默认的数据库为sqlite,默认连接方式为sqlite:///os.path.join(REPORT_ROOT, "db", "cuckoo.db")

升级cuckoo版本需要升级数据库版本,各个cuckoo版本的数据库有对应字段的修改,每个cuckoo版本的数据库有对应的

SCHEMA_VERSION,定义在lib/cuckoo/core/database.py中,因此升级cuckoo首先需要将数据库内容进行更新(主要是一些字段的改变和表内容的更新),方法:cd utils/db_migration/ && alembic upgrade head

image

2、数据库变更

通过查看cuckoo.conf配置文件,cuckoo目前主要支持三种形式的数据库sqlite、postgresql、mysql

cuckoo中对数据库进行判断,如果虚拟机数量大于1并且数据库类型为sqlite,那么并行处理任务可能会有一些问题

image

2.1、切换mysql

1、安装mysql(略过)

mysql> select version();
+------------+
| version()  |
+------------+
| 5.6.24-log |

+------------+

2、创建cuckoo数据库

mysql –uroot –ppassword 进入mysql数据库

create database cuckoo;  数据库路径在/polydata/data/db/mysql

查看数据库:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cuckoo             |
| mysql              |
| performance_schema |
| polydata           |
+--------------------+

3、修改配置文件

cuckoo.conf—>database—>connection =  mysql://root:password@localhost/cuckoo

4、安装MySQLdb模块

sudo apt-get install python-mysqldb

python交互命令中如果能import MySQLdb则安装成功

如果未安装或安装失败,会报导入数据库驱动问题

raise CuckooDependencyError("Missing database driver, unable to import %s (install with `pip install %s`)" % (lib, lib))

5、解决不能通过mysql .sock连接MySQL问题

现象:Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

解决方法:ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock

reference:http://blog.csdn.net/ixidof/article/details/5958904

至此cuckoo就可以使用mysql数据库,如果出现CuckooDatabaseError,即

"DB schema version mismatch: found {0}, expected {1}. "
"Try to apply all migrations (cd utils/db_migration/ && "
"alembic upgrade head).".format(last.version_num, SCHEMA_VERSION))
原因:数据库中会有一个字段alembic_version,其中的version_num就是定义的SCHEMA_VERSION,通过此内容来判断不同的cuckoo版本,如果安装了高版本的cuckoo,现在想使用低版本的cuckoo,则只能先删除该数据库或者直接更改该数据库的version_num

删除数据库:drop database cuckoo;

 

2.2、切换postgresql

1、安装postgresql

apt-get install postgresql

sudo passwd postgres  #修改postgres密码

版本:postgres=# select version();
                                                  version                                                 
-----------------------------------------------------------------------------------------------------------
PostgreSQL 9.3.9 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4, 64-bit

2、创建cuckoo数据库

sudo -u postgres psql  #其中,sudo -u postgres 是使用postgres 用户登录的意思

postgres=# create database cuckoo; #创建cuckoo database

查看数据库:\l

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges  
-----------+----------+----------+-------------+-------------+-----------------------
cuckoo    | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 rows)

常用命令:\l 查看系统中现存的数据库

                   \c database1 切换到database1

                   \dt 查看表             

3、修改配置文件

cuckoo.conf—>database—>connection =  postgresql://postgres:polydata@localhost:5432/cuckoo

4、安装psycopg2模块

sudo apt-get install python-psycopg2

python交互命令中如果能import psycopg2则安装成功

如果未安装或安装失败,会报导入数据库驱动问题

raise CuckooDependencyError("Missing database driver, unable to import %s (install with `pip install %s`)" % (lib, lib))
5、修改db user postgres 密码
问题:启动cuckoo时出现FATAL: password authentication failed for user "postgres"
原因:首先有两个账户概念,DB User和OS User,sudo passwd postgres修改的是OS User:postgres的password,而默认DB User:postgres的密码仍为空,因此需要修改DB User:postgres的密码
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'password';"


 

posted on 2015-07-23 14:59  月流霜  阅读(1456)  评论(0编辑  收藏  举报