一簡單介紹
1.piwik介紹
Piwik是一個PHP和MySQL的開放源代碼的Web統計軟件,它給你一些關於你的網站的實用統計報告,好比網頁瀏覽人數,訪問最多的頁面,搜索引擎關鍵詞等等。
Piwik擁有衆多不一樣功能的插件,你能夠添加新的功能或是移除你不須要的功能,Piwik一樣能夠安裝在你的服務器上面,數據就保存在你本身的服務器上面。你能夠很是容易的插入統計圖表到你的博客或是網站亦或是後臺的控制面板中。安裝完成後,你只需將一小段代碼放到將要統計的網頁中便可。
2.piwik概況
Piwik支持插件,你能夠經過插件擴展Piwik的功能,或者去掉一些不須要的功能。用戶的界面支持Ajax技術是可定製的,你能夠輕鬆拖放控件,定製本身須要的報告。
使用者獨立擁有本身的統計數據,而不是寄存在服務商那裏,這樣就能夠更靈活的使用統計數據,不用擔憂數據丟失問題。
Piwik是安裝在服務器端的統計工具,安裝過程很簡單,可是須要服務器支持PHP和MySQL。安裝的時候上傳Piwik到服務器端,而後打開瀏覽器,Piwik會自動運行安裝,整個過程不超過5分鐘。目前Piwik已支持中文
二安裝
官網:https://piwik.org
個人阿里雲的部署環境:javascript
[root@iZ2zeigj97j9lf057px8tmZ ~]# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
能夠比我這個版本高
因爲我想安裝piwik3.2版本
因此須要的環境最低是:php5.6和mysql5.7
網站服務用:apache和nginx均可以
爲了方便環境管理,就在這裏直接使用nginx環境
mysql官網:https://dev.mysql.com
php官網:http://php.net/
nginx官網:http://nginx.org/php
源碼包放在百度雲盤中html
百度雲盤連接:http://pan.baidu.com/s/1dE3gUbB 密碼:rpst前端
爲了節省時間,咱們使用glibc版本的mysqljava
2.1安裝mysqlnode
[root@iZ2zeigj97j9lf057px8tmZ software]# mkdir -pv /home/mysql/data
[root@iZ2zeigj97j9lf057px8tmZ software]# tar -zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /home/mysql
[root@iZ2zeigj97j9lf057px8tmZ software]# mv /home/mysql/mysql-5.7.18-linux-glibc2.5-x86_64/* /home/mysql/
[root@iZ2zeigj97j9lf057px8tmZ software]# useradd -g mysql
初始化數據庫
[root@iZ2zeigj97j9lf057px8tmZ software]# /home/mysql/bin/mysqld --user=mysql --basedir=/home/mysql --datadir=/home/mysql/data --initializemysql
紅框中的密碼要牢記,一會數據庫修改密碼,須要用到
數據庫部署
[root@iZ2zeigj97j9lf057px8tmZ software]# cp /home/mysql/support-files/mysql.server /home/mysql/support-files/mysql.server.start
[root@iZ2zeigj97j9lf057px8tmZ software]# vim /home/mysql/support-files/mysql.server.startlinux
[root@iZ2zeigj97j9lf057px8tmZ software]# /home/mysql/support-files/mysql.server.start start
[root@iZ2zeigj97j9lf057px8tmZ software]# ln -s /home/mysql/bin/mysql /usr/bin/mysql
[root@iZ2zeigj97j9lf057px8tmZ software]# vim /etc/my.cnf
若是沒有my.cnf就本身添加以下內容
[mysqld]
basedir = /home/mysql
datadir = /home/mysql/data
character_set_server=utf8
init_connect='SET NAMES utf8'nginx
[client]
default-character-set=utf8sql
[root@iZ2zeigj97j9lf057px8tmZ software]# cp /home/mysql/support-files/mysql.server.start /etc/init.d/mysqld
[root@iZ2zeigj97j9lf057px8tmZ software]#chmod 755 /etc/init.d/mysqld
[root@iZ2zeigj97j9lf057px8tmZ software]#service mysqld start
修改mysql初始化密碼
不過不改,會有提示
You must reset your password using ALTER USER statement before executing this statement
# 意思就是你必須重置你的密碼在執行這個execute操做前
因此進入mysql後進行密碼更新
[root@iZ2zeigj97j9lf057px8tmZ software]#mysql -u root -p
前面出現的密碼,在這裏填入
mysql> SET PASSWORD = PASSWORD('123456');
mysql> grant all on *.* to 'root'@'%' identified by '123456';
mysql> flush privileges;
完成後爲了安裝piwik須要建立相關數據庫和權限
mysql> create database piwik;
mysql> grant all on piwik.* to piwik@locahost identified by '123456';
mysql> flush privileges;
刷新權限後,退出。
2.2安裝php
[root@iZ2zeigj97j9lf057px8tmZ software]# tar -zxvf php-5.6.30.tar.gz
[root@iZ2zeigj97j9lf057px8tmZ software]# cd /software/php-5.6.30
[root@iZ2zeigj97j9lf057px8tmZ php-5.6.30]# ./configure --prefix=/software/php --with-config-file-path=/etc --with-mysql --with-mysqli=/home/mysql/bin/mysql_config --enable-inline-optimization --enable-fpm --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --disable-mbregex --disable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-pdo-mysql --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets--enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear
[root@iZ2zeigj97j9lf057px8tmZ php-5.6.30]#make && make install
[root@iZ2zeigj97j9lf057px8tmZ php-5.6.30]#cd /software/php/etc/
[root@iZ2zeigj97j9lf057px8tmZ etc]#cp php-fpm.conf.default php-fpm.conf
[root@iZ2zeigj97j9lf057px8tmZ php-5.6.30]#cp /software/php-5.6.30/php.ini-production /etc/php.ini
[root@iZ2zeigj97j9lf057px8tmZ php-5.6.30]#cp /software/php-5.6.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@iZ2zeigj97j9lf057px8tmZ php-5.6.30]#/software/php/sbin/php-fpm -t
[root@iZ2zeigj97j9lf057px8tmZ php-5.6.30]#service php-fpm start
[root@iZ2zeigj97j9lf057px8tmZ php-5.6.30]#netstat -ntlp | grep php-fpm
2.3安裝nginx
[root@iZ2zeigj97j9lf057px8tmZ software]#tar -zxvf nginx-1.10.2.tar.gz
[root@iZ2zeigj97j9lf057px8tmZ software]#cd nginx-1.10.2
[root@iZ2zeigj97j9lf057px8tmZ software]#./configure --user=www --group=www --prefix=/software/nginx \
--conf-path=/software/nginx/conf/nginx.conf \
--pid-path=/software/nginx/run/nginx.pid \
--lock-path=/software/nginx/lock/nginx \
--with-stream \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_perl_module \
--with-mail \
--with-mail_ssl_module
[root@iZ2zeigj97j9lf057px8tmZ software]#make && make install
2.4修改nginx的配置文件,配合piwik的安裝
[root@iZ2zeigj97j9lf057px8tmZ ~]# cat /software/nginx/conf/nginx.conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user www;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
#include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /software/nginx/conf/conf.d/*.conf;
# server {
# listen 80 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
server {
listen 80;
server_name 182.92.86.125;
root /var/www/piwik;
index index.php index.html index2.htm;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/piwik$fastcgi_script_name;
}
}
}
nginx解析php項目
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/piwik$fastcgi_script_name;
}
[root@iZ2zeigj97j9lf057px8tmZ software]#/software/nginx/sbin/nginx -t
文件正常後,啓動nginx
[root@iZ2zeigj97j9lf057px8tmZ software]#/software/nginx/sbin/nginx
2.4部署piwik
[root@iZ2zeigj97j9lf057px8tmZ ~]#mkdir -pv /var/www/piwik
[root@iZ2zeigj97j9lf057px8tmZ software]#unzip piwik.zip
[root@iZ2zeigj97j9lf057px8tmZ software]#cp -r /software/piwik/* /var/www/piwik/
打開網站後報錯,並提示你如何處理
[root@iZ2zeigj97j9lf057px8tmZ software]# chown -R nobody:nobody /var/www/piwik
[root@iZ2zeigj97j9lf057px8tmZ software]# chmod -R 755 /var/www/piwik/
修改成中文後,繼續下一步,發現一個php相關的預警報錯
安裝提示修改php.ini
爲預防某些嚴重問題,您必須在 php.ini 文件中加入以下幾行:always_populate_raw_post_data=-1
作過這個改動以後,請從新啓您的網絡服務器。
修改文件 vim /etc/php.ini
加入以下幾行:always_populate_raw_post_data=-1
重啓服務 service php-fpm restart
此時在看正常後,下一步
填寫相關的數據庫內容
點擊下一步卻報錯了,以下圖
說明,數據庫處理有問題,參考數據庫安裝管理,查看用戶權限密碼等
發現指定登陸是沒有問題的,有多是php頁面的輸入寫錯了,從新輸入看看
仍然不行,嘗試放大權限看看
mysql> grant all on piwik.* to piwik@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.04 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
雖然經過了,可是報錯告警了,說是有重複的數據庫,因而點擊,刪掉
幹掉重複的
因而正常的進入下一個環節了
繼續進入下一個環節
admin
123456
而後下一個環節
下一步
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//172.16.1.225/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Piwik Code -->
將代碼給前端處理加入,就行了,完活了
代碼部署完成後,就能夠看到效果了
有時你會看到這個,直接點升級就行了
升級後效果以下
能夠選擇打賞,有錢的大人能夠給點
繼續後,進入正式界面
和前端配合後,就能夠看到效果 了