# CDBTune **Repository Path**: Uncle-Justice/CDBTune ## Basic Information - **Project Name**: CDBTune - **Description**: No description available - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 2 - **Created**: 2022-05-04 - **Last Updated**: 2022-06-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### 环境 | 主机名 | ip | 必装软件 | 功能 | 密码 | 操作系统 | Python版本 | | -------- | -------------- | ----------- | ------------------ | -------- | ----------- | ---------- | | CDBTune1 | 192.168.110.10 | sysbench1.0 | 网络训练,主动压测 | 123456 | Ubuntu16.04 | 2.7 | | CDBTune2 | 192.168.110.11 | mysql5.6 | 数据库服务器 | 123456 | Ubuntu16.04 | 2.7 | ### 搭建步骤 1. 将训练模型的项目CDBTune放至两台服务器的home目录下,即目录为:/home/work/CDBTune1&2 ```bash cd /home/work git clone https://gitee.com/Uncle-Justice/CDBTune.git mv CDBTune CDBTune1 git clone https://gitee.com/Uncle-Justice/CDBTune.git mv CDBTune CDBTune2 ``` 2. 在CDBTune1安装sysbench1.0,安装方法参考:[Ubuntu安装sysbench1.0](https://blog.csdn.net/cxin917/article/details/81557453) ```bash # 在CDBTune1安装sysbench1.0,apt直接装的话是只能装0.4的版本的,想装1.0需要自己编译安装 curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh | bash apt -y install sysbench # 这里默认会安装1.0.20版本,而原作者的安装版本是1.0.14,如果不改源代码的话,那么就要把sysbench的代码位置移动一下才可以 cp -r /usr/share/sysbench /usr/local/sysbench pip install enum enum34 pip install -U scikit-learn==0.19 -i https://pypi.tuna.tsinghua.edu.cn/simple ``` 3. 在CDBTune2安装**mysql5.6**,root初始密码设置为123456。[Ubuntu安装mysql5.6](https://blog.csdn.net/qq_36641556/article/details/80921737) ```bash apt-get install software-properties-common # 要在sources.list加上mysql5.6对应的源 # 下面这句话不要运行,就把引号内的内容加入到sources.list即可 add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty universe' apt-get update apt install mysql-server-5.6 apt install mysql-client-5.6 pip install pexpect --user apt-get install net-tools update-rc.d mysql defaults sudo vim /etc/mysql/my.cnf # 换上以下内容 # The MySQL database server configuration file. # # You can copy this to one of: # - "/etc/mysql/my.cnf" to set global options, # - "~/.my.cnf" to set user-specific options. # # One can use all long options that the program supports. # Run program with --help to get a list of available options and with # --print-defaults to see which it would actually understand and use. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html # This will be passed to all mysql clients # It has been reported that passwords should be enclosed with ticks/quotes # escpecially if they contain "#" chars... # Remember to edit /etc/mysql/debian.cnf when changing the socket location. # Here is entries for some specific programs # The following values assume you have at least 32M ram !includedir /etc/mysql/conf.d/ # add here [mysqld] default-time_zone = '+8:00' lower_case_table_names=1 # end ``` 4. 在CDBTune2上登录mysql,创建一个database,名为sbtest ```bash service mysql restart mysql -u root -p create database sbtest; ``` 5. [给mysql的root用户开启远程访问权限](https://www.cnblogs.com/goxcheer/p/8797377.html) user如果写root好像会出问题,但是写cdbtune就没事,**这里的IP要注意一下是sysbench端的ip,要对应的改一下** ```mysql use mysql; select User,authentication_string,Host from user; GRANT ALL PRIVILEGES ON *.* TO 'cdbtune'@'172.17.0.3' IDENTIFIED BY '123456' ; flush privileges; select User,authentication_string,Host from user; ``` 6. 在mysql中,使用命令: ```mysql select name from innodb_metrics where status="enabled" order by name; ``` 再使用如下命令将adaptive_hash_searches_btree这个向量开启: ```mysql set global innodb_monitor_enable = "adaptive_hash_searches_btree"; ``` 打开计数器即可。具体计数器打开/关闭/重置可以参考:[mysql如何打开/关闭/重置计数器](https://www.cnblogs.com/yuyutianxia/p/7747035.html) 7. 在CDBTune1上使用sysbench对CDBTune2的sbtest进行初始化,使用的是/home/cheng/AutoTuner/scripts/prepare.sh脚本,首先用vim将prepare.sh中的script_path修改为:"/usr/share/sysbench/" (注意最后有一个”/”)。之后使用命令: ```bash sh prepare.sh read 192.168.110.11 3306 123456 ``` (当前在/home/cheng/AutoTuner/scripts目录下)对CDBTune2的sbtest数据库建了8张表,每张表1000000条数据(这一步耗时可能会有点长,耐心等待即可)。 8. 对两台机器,都进行requirement.txt的安装 ```bash # 针对python库版本兼容问题和下载慢问题,先装requirements.txt,然后再单独装torch以及相关库 pip install -r requirements.txt --user -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir # torch的下载有的时候很慢,有的时候很快,如果很慢可以尝试重新下载 pip install http://download.pytorch.org/whl/cu80/torch-0.3.1-cp27-cp27mu-linux_x86_64.whl ``` 9. 在CDBTune2上安装pexpect,执行如下命令: ```bash pip install pexpect --user ``` 10. 在CDBTune2的/home/work/CDBTuner2/server目录下执行命令: ```bash sh ./start_server.sh ``` 11. 在CDBTune2上输入命令:netstat -apn | grep 20000,若观察到端口20000对应的状态为LISTEN,即为启动成功。 12. (**忽略此步**)在CDBTune1的/home/cheng/AutoTuner/tuner仿照CDBTune2的start_server.sh脚本,写一个start_train.sh的脚本。内容如下: ```bash #!/usr/bin/env bash nohup python train.py >> train.log & ``` 13. 在CDBTune1使用pip安装enum。命令: ```bash pip install enum enum34 ``` 1. 在CDBTune1的/home/work/CDBTune1/environment/configs.py中添加CDBTune2的mysql信息(对象须是**mysql1**,**并且要改掉对应IP**),如下: ```python instance_config = { 'mysql1': { 'host': '192.168.110.11', 'user': 'root', 'passwd': '123456', 'port': 3306, 'database': 'sbtest', 'memory': 34359738368 } } ``` 15. 在python2.7的环境安装sklearn,使用命令: ```bash pip install -U scikit-learn==0.19 ``` 16. (忽略此步)将CDBTune1的/home/cheng/AutoTuner/environment/mysql.py中的TEMP_FILES和PROJECT_DIR变量中的用户名改为”cheng”(服务器的用户名)。 17. (忽略此步)将CDBTune1的/home/cheng/AutoTuner/scripts/run_sysbench.sh中的script_path修改为"/usr/share/sysbench/"。 18. 需要自行设置environment模块下knobs.py文件中各个knob的默认值。 19. 修改/etc/mysql/my.cnf文件,将内容替换为如下: ```bash # DEFAULT_VALUE为上一步在knobs.py中设置的默认值 [mysqld] binlog_format = MIXED innodb_buffer_pool_size = 134217728 innodb_log_files_in_group = 2 innodb_log_file_size = 50331648 innodb_read_io_threads = 4 binlog_cache_size = 32768 innodb_buffer_pool_instances = 8 binlog_checksum = NONE max_binlog_size = 1073741824 skip_name_resolve = OFF innodb_write_io_threads = 4 innodb_purge_threads = 1 innodb_file_per_table = OFF table_open_cache = 2000 max_connections = 151 [mysqld_safe] [mysqldump] max_allowed_packet = 16M ``` 20. 需要自行设置tuner模块下tuner_configs.py中的一些超参数的值。 21. 运行CDBTune1的tuner/train.py文件,可以指定代码里提供的参数,不指定则按默认参数运行,开始训练model。 22. 模型训练完成后,运行CDBTune1的tuner/evaluate.py文件,对模型进行评估。同时必须指定params参数,参数值为tuner/model_params下的文件名部分前缀,如下: ~~~shell python2 evaluate.py --params train_ddpg_1571382343_4600 ~~~