最终实现: 搭建一个本地Crash收集系统
准备工作:
服务器端使用开源项目QuincyKit,我们先clone或下载下来;
由于QuincyKit的服务器端是PHP写的,所以我还需要部署PHP,这里我使用的是MAMP PRO,按照里面方法下载安装即可。
部署QuincyKit service 到 服务器
下面是QuincyKit的目录结构
- 将QuincyKit中的sever文件夹拷贝到
/Applications/MAMP/htdocs
,这个目录是MAMP默认的服务器文件目录,当然这个目录你可以在MAMP的hosts下自定义
- 将QuincyKit中的sever文件夹拷贝到
- 编辑server目录下的config.php.sample文件,
$server = 'localhost:8889'; // database server hostname
$loginsql = 'root'; // username to access the database
$passsql = 'root'; // password for the above username
$base = 'CrashDataBase'; // database name which contains the below listed tables
重命名config.php.sample
为config.php
- 访问http://localhost:8888时出现403信息:
You don't have permission to access / on this server.
解决方法:在MAMP下进入hosts,选择Extended下勾选Indexes即可,当然你在htdocs目录下创建一个index.php也可以解决
- 访问http://localhost:8888时出现403信息:
4.进入phpMyAdmin,点击 MAMP上的WebStart按钮会打开phpMyAdmin,当点击localhosts:8889时弹出:
Error in Processing Request Error code: 404 Error text: Not Found
解决方法: 参数stackoverflow中的方案:
进入/Library/Application Support/appsolute/MAMP PRO/phpMyAdmin/
目录,打开config.inc.php
,找到:
$cfg['DefaultTabServer'] = 'main.php';
将其修改为:
$cfg['DefaultTabServer'] = 'index.php';
或者将其注释掉:
#$cfg['DefaultTabServer'] = 'main.php';
不过我最终选择了升级MAMP,使用4.1版本解决-
5.测试是否配置成功:
在浏览器执行http://localhost/test_setup.php
如果全部为passed
则说明部署成功,否则根据哪项不是passed
查找原因;
这里最初我的Database access:
并没有显示passed,查看日志得知原因:php连接数据库失败,日志PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /Applications/MAMP/htdocs/server/admin/test_setup.php:
;
原因是我的php是7版本的,而php7不支持mysql函数,不过可以替换为mysqli的相关函数;再次测试,全部passed
对QuincyKit的server代码修改:
mysqli_select_db() 函数用于更改连接的默认数据库。
如果是php7, 请按照下面修改
mysql_select_db() 修改为mysqli_select_db() mysql_select_db()只有一个参数,是数据库的名称,mysqli_select_db()有两个参数:
<?php
// 假定数据库用户名:root,密码:123456,数据库:RUNOOB
$con=mysqli_connect("localhost","root","123456","RUNOOB");
if (mysqli_connect_errno($con))
{
echo "连接 MySQL 失败: " . mysqli_connect_error();
}
// ...查询 "RUNOOB" 数据库的一些 PHP 代码...
// 修改数据库为 "test"
mysqli_select_db($con,"test");
// ...查询 "test" 数据库的一些 PHP 代码...
mysqli_close($con);
?>
Waring:
PHP Warning: mysqli_query() expects at least 2 parameters, 1 given in /Applications/MAMP/htdocs/server/admin/app_versions.php on line 115
解决方法:修改mysqli_query()MAMP PRO 数据库文件的本地路径:
/Library/Application Support/appsolute/MAMP PRO/db/mysql/
MAMP 下连接数据库日志问题:
`RSA private key file not found: /Library/Application Support/appsolute/MAMP PRO/db/mysql56//private_key.pem. Some authentication plugins will not work.
RSA public key file not found: /Library/Application Support/appsolute/MAMP PRO/db/mysql56//public_key.pem. Some authentication plugins will not work.
解决方法:RSA private key file not found的问题,sha256_password这个插件是MySQL5.6内置的,支持更为强大的用户密码加密方式。
- 检查是否安装openssl
$rpm -qa openssl
openssl-1.0.0-20.el6_2.5.x86_64
2.利用openssl生成公有和私有key
$ openssl genrsa -out mykey.pem 1024
Generating RSA private key, 1024 bit long modulus
..........++++++
.++++++
e is 65537 (0x10001)
$ openssl rsa -in mykey.pem -pubout -out mykey.pub writing RSA key
$ ll mykey*
-rw-r--r-- 1 db mysql 887 2014-10-26 12:59:05 mykey.pem
-rw-r--r-- 1 db mysql 272 2014-10-26 12:59:12 mykey.pub
3.修改key的权限
$ chmod 400 mykey.pem
$ chmod 444 mykey.pub
$ ll mykey*
-r-------- 1 db mysql 887 2014-10-26 12:59:05 mykey.pem
-r--r--r-- 1 db mysql 272 2014-10-26 12:59:12 mykey.pub
4.把公私有key的路径加入到my.cnf中
sha256_password_private_key_path=mykey.pem
sha256_password_public_key_path=mykey.pub
如果key放在datadir目录下,直接写key名即可。否则要指定key的全路径。
5.重启mysql,SHOW STATUS查看Rsa_public_key状态,如果不为空,则OK.
mysql> SHOW STATUS LIKE 'Rsa_public_key'\G
*************************** 1. row ***************************
Variable_name: Rsa_public_key
Value: -----BEGIN PUBLIC KEY-----
MIGfMA0ACSqGSIb2DQEBAQUAA4GNADCBiQKBgQDEnZaBWzo/4Ygm435LFKT8HBoX
bPkXATx9eJ4TWDtklLKidoWYj182fXdIpIA1Jt0CNm1MdLKwdcxuEOvSq/ortfmr
Y9doNlcpiLWUmDRD9LBH0AAJR1Tk7L8XLWEuq/nm3eiEnCUZE9+yF1gGxeDJQ2kG
oVHJhFxk0TST0R1nAQDDAQAB
-----END PUBLIC KEY-----
1 row in set (0.01 sec)
6.检查重启后的error log,相关的提示已经消失
Mac 下ll命令 command not found
打开终端
cd ~
vim .bash_profile
加入:
alias ll='ls -alF' alias la='ls -A' alias l='ls -CF'
保存后,执行
source .bash_profile
编辑MAMP4.1下my.cnf文件:
打开MAMP PRO,点击主界面左侧LANGUAGES中PHP,右侧Extensions分类中点击Manually enable other extensions右侧按钮(或者打开菜单栏File->Edit Template->MySQL->(选择版本)),这时打开的文件就是my.cnfmysql自动停止 Plugin 'FEDERATED' is disabled
2017-11-29 23:46:17 7272 [Note] Plugin 'FEDERATED' is disabled.
2017-11-29 23:46:17 7272 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-11-29 23:46:17 7272 [Note] InnoDB: The InnoDB memory heap is disabled
2017-11-29 23:46:17 7272 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-11-29 23:46:17 7272 [Note] InnoDB: Memory barrier is not used
2017-11-29 23:46:17 7272 [Note] InnoDB: Compressed tables use zlib 1.2.8
2017-11-29 23:46:17 7272 [Note] InnoDB: Using CPU crc32 instructions
2017-11-29 23:46:17 7272 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-11-29 23:46:17 7272 [Note] InnoDB: Completed initialization of buffer pool
2017-11-29 23:46:17 7272 [Note] InnoDB: Highest supported file format is Barracuda.
2017-11-29 23:46:17 7272 [Note] InnoDB: 128 rollback segment(s) are active.
2017-11-29 23:46:17 7272 [Note] InnoDB: Waiting for purge to start
2017-11-29 23:46:18 7272 [Note] InnoDB: 5.6.35 started; log sequence number 1677335
2017-11-29 23:46:18 7272 [Note] RSA private key file not found: /Library/Application Support/appsolute/MAMP PRO/db/mysql56//private_key.pem. Some authentication plugins will not work.
2017-11-29 23:46:18 7272 [Note] RSA public key file not found: /Library/Application Support/appsolute/MAMP PRO/db/mysql56//public_key.pem. Some authentication plugins will not work.
2017-11-29 23:46:18 7272 [Note] Server hostname (bind-address): '127.0.0.1'; port: 8889
2017-11-29 23:46:18 7272 [Note] - '127.0.0.1' resolves to '127.0.0.1';
2017-11-29 23:46:18 7272 [Note] Server socket created on IP: '127.0.0.1'.
2017-11-29 23:46:18 7272 [Note] Event Scheduler: Loaded 0 events
2017-11-29 23:46:18 7272 [Note] /Applications/MAMP/Library/bin/mysqld: ready for connections.
Version: '5.6.35' socket: '/Applications/MAMP/tmp/mysql/mysql.sock' port: 8889 MySQL Community Server (GPL)
2017-11-29 23:48:52 7272 [Note] /Applications/MAMP/Library/bin/mysqld: Normal shutdown
解决方法:
打开my.cnf
在[mysqld]
下面添加
federated
skip-external-locking
skip-name-resolve