安装pixel
1.安装node.js
wget http://nodejs.org/dist/v0.6.1/node-v0.6.1.tar.gz
本地测试下载的是这个版本,如果要高版本的话可以找高版本的地址
tar zxvf node-v0.6.1.tar.gz
./configure
如果出现以下情况:
Checking for program g++ or c++ : not found
Checking for program icpc : not found
Checking for program c++ : not found
/home/admin/pkgs/node-v0.6.10/wscript:261: error: could not configure a cxx compiler!
解决办法是:
安装gcc-c++
sudo yum install gcc-c++
如果还有
Checking for openssl : not found
Checking for function SSL_library_init : not found
Checking for header openssl/crypto.h : not found
/home/admin/pkgs/node-v0.6.10/wscript:374: error: Could not autodetect OpenSSL support. Make sure OpenSSL development packages are installed. Use configure --without-ssl to disable this message.
解决办法:安装openssl-devel
sudo yum install openssl-devel
然后,就可以正常编译安装了。
./configure
make
sudo make install
node -v可以查看node的相关信息
2.安装npm
curl http://npmjs.org/install.sh | sudo sh
提示网址有问题的话就改为:curl https://npmjs.org/install.sh | sudo sh
如果提示,找不到node,所以:再做一个软链接:
sudo ln -s /usr/local/bin/node /usr/bin/node
curl http://npmjs.org/install.sh | sudo sh
可以正常运行。
3.安装pixel
sudo npm install pixel-ping
此时会在当前所在目录下生成一个node_modules目录,该文件夹下就是安装的pixel ping的相关文件。
4.配置pixel
(1)进入node_modules/pixel-ping目录,修改config.json文件。将config.example.json复制一份,重命名为config.json。然后打开,修改端口,将host修改为自己的对外的主机地址,如我自己本地虚拟机的是192.168.1.1。修改相应后请求的方法参数endpoint,改为http://romy.redidai.com/save_hits.html。如果是上线服务器的话,就改域名可以了,后面的方法保持不动。
(2)进入node_modules/pixel-ping/lib/下,修改pixel-ping.js文件。
修改record方法。
store[key] || (store[key] = 0);此句后面增加的参数代码:
if (undefined != params.query.ip) {
store['ip'] = params.query.ip;
}
if (undefined != params.query.area) {
store['area'] = params.query.area;
}
if (undefined != params.query.keyword) {
store['search'] = params.query.keyword;
}
if (undefined != params.query.uid) {
store['uid'] = params.query.uid;
}
if (undefined != params.query.referer) {
store['referer'] = params.query.referer;
}
if (undefined != params.query.objClick) {
store['objClick'] = params.query.objClick;
}
5.项目主要配置文件修改说明1
(1)在 index.html中添加
<div class='hitImg'><img src="http://192.168.1.1:9187/pixel.gif?key=index_hit&ip={$clientIP}&area={$area}&uid={$uid}&referer={$httpReferer}&keyword=" alt=""/></div>
将192.168.1.1改为跟config.json中的一致。
(5)IndexAction.class.php文件中的pixel()方法就是追踪生成的logs日志方法。