Matomo(以前称为Piwik)是Linux操作系统的开源分析应用程序。它与Google Analytics(分析)非常相似,可帮助您跟踪和显示用户访问的位置。它是由一组国际开发人员开发的,它们在PHP / MySQL网络服务器上运行。它提供了许多功能,下面列出了其中的一些功能:
- 灵活性,可靠性和安全性
- 自托管,简单易用
- 100%数据所有权
- 符合GDPR
- 网络和移动分析
在本教程中,我们将向您展示如何在CentOS 8服务器上安装和设置Piwik分析应用程序。
先决条件
- 运行CentOS的服务器8。
- 指向服务器IP的有效域名。
- 在您的服务器上配置了root密码。
安装LAMP服务器
Piwik在LAMP服务器上运行,因此您需要在系统上安装Apache,MariaDB,PHP和其他PHP扩展。您可以使用以下命令安装所有组件:
dnf install httpd mariadb-server php php-mysqlnd php-fpm unzip wget php-json php-dom php-gd php-mbstring -y
安装完所有软件包后,编辑php.ini文件并设置一些所需的值:
nano /etc/php.ini
更改以下值:
upload_max_filesize = 10M post_max_size = 10M max_execution_time = 300 max_input_time = 300 memory_limit = 256M
保存并关闭文件,然后启动Apache和MariaDB服务,并使它们能够在系统重新引导时启动:
systemctl start mariadb
systemctl start httpd
systemctl enable mariadb
systemctl enable httpd
为Piwik创建数据库
接下来,您将需要为Piwik创建数据库和用户。首先,使用以下命令登录MariaDB:
mysql
登录后,使用以下命令创建数据库和用户:
mysql> CREATE DATABASE matomo;
mysql> CREATE USER `matomo`@`localhost` IDENTIFIED BY 'password';
接下来,使用以下命令将所有特权授予数据库:
mysql> GRANT ALL ON matomo.* TO `matomo`@`localhost`;
接下来,刷新特权并使用以下命令从MariaDB退出:
mysql> FLUSH PRIVILEGES;
mysql> EXIT;
安装Piwik
接下来,您需要从其官方网站下载最新版本的Piwik。首先,使用以下命令将目录更改为Apache Web根目录:
cd /var/www/html
接下来,使用以下命令下载Piwik:
wget https://builds.matomo.org/matomo-latest.zip
下载完成后,使用以下命令解压缩下载的文件:
unzip matomo-latest.zip
接下来,使用以下命令为Web根目录设置适当的权限和所有权:
chown -R apache:apache /var/www/html/matomo
chmod -R 775 /var/www/html/matomo
完成后,您可以继续下一步。
配置SELinux和防火墙
接下来,您将需要允许端口80和443通过防火墙。您可以使用以下命令允许它们:
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
接下来,重新加载firewalld以应用更改:
firewall-cmd --reload
接下来,您还需要为Piwik设置SELinux。您可以使用以下命令进行设置:
chcon -R -t httpd_sys_rw_content_t /var/www/html/matomo/
setsebool httpd_can_network_connect on -P
完成后,您可以继续下一步。
为Piwik配置Apache
接下来,您将需要配置Apache Web服务器以托管Piwik网站。您可以通过创建一个新的Apache虚拟主机配置文件来做到这一点:
nano /etc/httpd/conf.d/piwik.conf
添加以下行:
<VirtualHost *:80> ServerAdmin admin@example.com DocumentRoot "/var/www/html/matomo" ServerName piwik.example.com <Directory "/var/www/html/matomo/"> Options MultiViews FollowSymlinks AllowOverride All Order allow,deny Allow from all </Directory> TransferLog /var/log/httpd/matomo_access.log ErrorLog /var/log/httpd/matomo_error.log </VirtualHost>
完成后,保存并关闭文件。然后,重新启动Apache Web服务器以应用更改:
systemctl restart httpd
现在,您可以使用以下命令检查Apache的状态:
systemctl status httpd
您应该获得以下输出:
? httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Drop-In: /usr/lib/systemd/system/httpd.service.d ??php-fpm.conf Active: active (running) since Sun 2020-12-27 05:38:29 EST; 5s ago Docs: man:httpd.service(8) Main PID: 4228 (httpd) Status: "Started, listening on: port 80" Tasks: 213 (limit: 12523) Memory: 36.8M CGroup: /system.slice/httpd.service ??4228 /usr/sbin/httpd -DFOREGROUND ??4229 /usr/sbin/httpd -DFOREGROUND ??4230 /usr/sbin/httpd -DFOREGROUND ??4231 /usr/sbin/httpd -DFOREGROUND ??4232 /usr/sbin/httpd -DFOREGROUND Dec 27 05:38:28 centos8 systemd[1]: Stopped The Apache HTTP Server. Dec 27 05:38:28 centos8 systemd[1]: Starting The Apache HTTP Server...
完成后,您可以继续下一步。
访问Piwik Web界面
现在,打开您的Web浏览器,并使用URL http://piwik.example.com访问Piwik Web界面。您将被重定向到以下页面:
点击NEXT,您应该会看到系统检查页面:
单击NEXT,您将看到数据库设置页面:
提供您的数据库用户名,数据库名称,密码,然后单击NEXT,您应该看到以下页面:
点击NEXT,您将看到admin用户创建页面:
提供您的管理员用户名,密码,电子邮件,然后单击“下一步”。您应该看到网站设置页面:
提供您的网站详细信息,然后单击NEXT。您应该在以下页面中看到您的跟踪代码:
单击下一步。安装完成后。您应该看到以下页面:
单击继续到MATOMO。您应该看到MATOMO登录页面:
提供您的管理员用户名,密码,然后单击“登录”。您应该在以下页面中看到MATOMO仪表板:
让我们加密SSL保护Matomo
接下来,您将需要在系统中安装Certbot实用程序,才能为Piwik网站下载并安装“让我们加密SSL”。
您可以使用以下命令安装Certbot客户端:
wget https://dl.eff.org/certbot-auto
mv certbot-auto /usr/local/bin/certbot-auto
chown root /usr/local/bin/certbot-auto
chmod 0755 /usr/local/bin/certbot-auto
接下来,使用以下命令为您的Mantis网站获取并安装SSL证书:
certbot-auto --apache -d piwik.example.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator apache, Installer apache Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): hitjethva@gmail.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (A)gree/(C)ancel: A - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: Y Obtaining a new certificate Performing the following challenges: http-01 challenge for piwik.example.com Waiting for verification... Cleaning up challenges Deploying Certificate to VirtualHost /etc/httpd/conf.d/piwik.conf
接下来,您将需要选择是否将HTTP流量重定向到HTTPS,如下所示:
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: No redirect - Make no further changes to the webserver configuration. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
输入2,然后按Enter键继续。安装完成后,您应该看到以下输出:
Redirecting all traffic on port 80 to ssl in /etc/httpd/conf.d/piwik.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://piwik.example.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=piwik.example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/piwik.example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/piwik.example.com/privkey.pem Your cert will expire on 2020-03-23. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot-auto renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
此时,您的网站已使用“让我们加密SSL”保护。
结论恭喜!您已经成功使用Apache和CentOS 8上的Let’s Encrypt SSL成功安装并设置了Piwik。您现在可以在网站中添加跟踪代码,并开始从Piwik仪表板监视网站访问者。如有任何问题,随时问我。