20150215-1 选题

This commit is contained in:
DeadFire 2015-02-15 14:41:18 +08:00
parent 76559ab6dc
commit e06edfcc7d
3 changed files with 335 additions and 0 deletions

View File

@ -0,0 +1,143 @@
How to analyze and view Apache web server logs interactively on Linux
================================================================================
Whether you are in the web hosting business, or run a few web sites on a VPS yourself, chances are you want to display visitor statistics such as top visitors, requested files (dynamic or static), used bandwidth, client browsers, and referring sites, and so forth.
[GoAccess][1] is a command-line log analyzer and interactive viewer for Apache or Nginx web server. With this tool, you will not only be able to browse the data mentioned earlier, but also parse the web server logs to dig for further data as well - and **all of this within a terminal window in real time**. Since as of today [most web servers][2] use either a Debian derivative or a Red Hat based distribution as the underlying operating system, I will show you how to install and use GoAccess in Debian and CentOS.
### Installing GoAccess on Linux ###
In Debian, Ubuntu and derivatives, run the following command to install GoAccess:
# aptitude install goaccess
In CentOS, you'll need to enable the [EPEL repository][3] and then:
# yum install goaccess
In Fedora, simply use yum command:
# yum install goaccess
If you want to install GoAccess from the source to enable further options (such as GeoIP location), install [required dependencies][4] for your operating system, and then follow these steps:
# wget http://tar.goaccess.io/goaccess-0.8.5.tar.gz
# tar -xzvf goaccess-0.8.5.tar.gz
# cd goaccess-0.8.5/
# ./configure --enable-geoip
# make
# make install
That will install version 0.8.5, but you can always verify what is the latest version in the [Downloads page][5] of the project's web site.
Since GoAccess does not require any further configurations, once it's installed you are ready to go.
### Running GoAccess ###
To start using GoAccess, just run it against your Apache access log.
For Debian and derivatives:
# goaccess -f /var/log/apache2/access.log
For Red Hat based distros:
# goaccess -f /var/log/httpd/access_log
When you first launch GoAccess, you will be presented with the following screen to choose the date and log format. As explained, you can toggle between options using the spacebar and proceed with F10. As for the date and log formats, you may want to refer to the [Apache documentation][6] if you need to refresh your memory.
In this case, Choose Common Log Format (CLF):
![](https://farm8.staticflickr.com/7422/15868350373_30c16d7c30.jpg)
and then press F10. You will be presented with the statistics screen. For the sake of brevity, only the header, which shows the summary of the log file, is shown in the next image:
![](https://farm9.staticflickr.com/8683/16486742901_7a35b5df69_b.jpg)
### Browsing Web Server Statistics with GoAccess ###
As you scroll down the page with the down arrow, you will find the following sections, sorted by requests. The order of the categories presented here may vary depending on your distribution or your preferred installation method (from repositories or from source):
1. Unique visitors per day (HTTP requests having the same IP, same date and same agent are considered an unique visit)
![](https://farm8.staticflickr.com/7308/16488483965_a439dbc5e2_b.jpg)
2. Requested files (Pages-URL)
![](https://farm9.staticflickr.com/8651/16488483975_66d05dce51_b.jpg)
3. Requested static files (e.g., .png, .js, etc)
4. Referrers URLs (the URLs where each request came from)
5. HTTP 404 Not Found response code
![](https://farm9.staticflickr.com/8669/16486742951_436539b0da_b.jpg)
6. Operating Systems
7. Browsers
8. Hosts (client IPs)
![](https://farm8.staticflickr.com/7392/16488483995_56e706d77c_z.jpg)
9. HTTP status codes
![](https://farm8.staticflickr.com/7282/16462493896_77b856f670_b.jpg)
10. Top referring sites
11. Top keyphrases used on Google's search engine
If you also want to inspect the archived logs, you can pipe them to GoAccess as follows.
For Debian and derivatives:
# zcat -f /var/log/apache2/access.log* | goaccess
For Red Hat based distributions:
# cat /var/log/httpd/access* | goaccess
Should you need a more detailed report of any of the above (1 through 11), press the desired section number and then O (uppercase o) to bring up what is called the Detailed View. The following image shows the output of 5-O (press 5, then press O):
![](https://farm8.staticflickr.com/7382/16302213429_48d9233f40_b.jpg)
To display GeoIP location information, open the Detail View in the Hosts section, as explained earlier, and you will see the location of the client IPs that performed requests to your web server:
![](https://farm8.staticflickr.com/7393/16488484075_d778aa91a2_z.jpg)
If your system has not been very busy lately, some of the above sections will not show a great deal of information, but that situation can change as more and more requests are made to your web server.
### Saving Reports for Offline Analysis ###
There will be times when you don't want to inspect your system's stats in real time, but save it to a file for offline analysis or printing. To generate an HTML report, simply redirect the output of the GoAccess commands mentioned earlier to an HTML file. Then just point your web browser to the file to open it.
# zcat -f /var/log/apache2/access.log* | goaccess > /var/www/webserverstats.html
Once the report is displayed, you will need to click on the Expand link to show the detail view on each category:
![](https://farm9.staticflickr.com/8658/16486743041_bd8a80794d_o.png)
注释youtube视频
<iframe width="615" height="346" frameborder="0" allowfullscreen="" src="https://www.youtube.com/embed/UVbLuaOpYdg?feature=oembed"></iframe>
As we have discussed throughout this article, GoAccess is an invaluable tool that will provide you, as a system administrator, with HTTP statistics in a visual report on the fly. Although GoAccess by default presents its results to the standard output, you can also save them to JSON, HTML, or CSV files. This converts GoAccess in an incredibly useful tool to monitor and display statistics of a web server.
--------------------------------------------------------------------------------
via: http://xmodulo.com/interactive-apache-web-server-log-analyzer-linux.html
作者:[Gabriel Cánepa][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://xmodulo.com/author/gabriel
[1]:http://goaccess.io/
[2]:http://w3techs.com/technologies/details/os-linux/all/all
[3]:http://xmodulo.com/how-to-set-up-epel-repository-on-centos.html
[4]:http://goaccess.io/download#dependencies
[5]:http://goaccess.io/download
[6]:http://httpd.apache.org/docs/2.4/logs.html

View File

@ -0,0 +1,136 @@
How to share files between computers over network with btsync
================================================================================
If you are the type of person who uses several devices to work online, I'm sure you must be using, or at least wishing to use, a method for syncing files and directories among those devices.
BitTorrent Sync, also known as btsync for short, is a cross-platform sync tool (freeware) which is powered by BitTorrent, the famous protocol for peer-to-peer (P2P) file sharing. Unlike classic BitTorrent clients, however, btsync encrypts traffic and grants access to shared files based on auto-generated keys across different operating system and device types.
More specifically, when you add files or folder to btsync as shareable, corresponding read/write keys (so-called secret codes) are created. These keys are then shared among different devices via HTTPS links, emails, QR codes, etc. Once two devices are paired via a key, the linked content can be synced directly between them. There is no file size limit, and transfer speeds are never throttled unless you explicitly say so. You will be able to create accounts inside btsync, under which you can create and manage keys and files to share via web interface.
BitTorrent Sync is available on multiple operating systems including Linux, MacOS X, Windows, as well as [Android][1] and [iOS][2]. In this tutorial, I will show you how to use BitTorrent Sync to sync files between a Linux box (a home server), and a Windows machine (a work laptop).
### Installing Btsync on Linux ###
BitTorrent Sync is available for download from the [project's website][3]. I assume that the Windows version of BiTorrent Sync is installed on a Windows laptop, which can be done very easily. I will focus on installing and configuring it on the Linux server.
In the download page, choose your architecture, right click on the corresponding link, choose Copy link location (or similar, depending on your browser), and paste the link to wget in your terminal, as follows:
**For 64-bit Linux:**
# wget http://download.getsyncapp.com/endpoint/btsync/os/linux-x64/track/stable
**For 32-bit Linux:**
# wget http://download.getsyncapp.com/endpoint/btsync/os/linux-i386/track/stable
![](https://farm9.staticflickr.com/8635/15895277773_8acf317e3c_c.jpg)
Once the download has completed, extract the contents of the tarball into a directory specially created for that purpose:
# cd /usr/local/bin
# mkdir btsync
# tar xzf stable -C btsync
![](https://farm8.staticflickr.com/7306/16329173869_7dc8b64a39_b.jpg)
You can now either add /usr/local/bin/btsync to your PATH environment variable.
export PATH=$PATH:/usr/local/bin/btsync
or run the btsync binary right from that folder. We'll go with the first option as it requires less typing and is easier to remember.
### Configuring Btsync ###
Btsync comes with a built-in web server which is used as the management interface for BitTorrent Sync. To be able to access the web interface, you need to create a configuration file. You can do that with the following command:
# btsync --dump-sample-config > btsync.config
Then edit the btsync.config file (webui section) with your preferred text editor, as follows:
"listen" : "0.0.0.0:8888",
"login" : "yourusername",
"password" : "yourpassword"
You can choose any username and password.
![](https://farm9.staticflickr.com/8599/15895277793_da63841433_b.jpg)
![](Feel free to check the README file in /usr/local/bin/btsync directory if you want to tweak the configuration further, but this will do for now.)
### Running Btsync for the First Time ###
As system administrators we believe in logs! So before we launch btsync, we will create a log file for btsync.
# touch /var/log/btsync.log
Finally it's time to start btsync:
# btsync --config /usr/local/bin/btsync/btsync.config --log /var/log/btsync.log
![](https://farm8.staticflickr.com/7288/16327720298_ccf2cbedea_c.jpg)
Now point your web browser to the IP address of the Linux server and the port where btsync is listening on (192.168.0.15:8888 in my case), and agree to the privacy policies, terms, and EULA:
![](https://farm9.staticflickr.com/8597/16327720318_d52551fc44_b.jpg)
and you will be taken to the home page of your btsync installation:
![](https://farm8.staticflickr.com/7412/16329544687_9a174527d8_c.jpg)
Click on Add a folder, and choose a directory in your file system that you want to share. In our example, we will use /btsync:
![](https://farm8.staticflickr.com/7407/16515452485_e25ded559f_b.jpg)
That's enough by now. Please install BitTorrent Sync on your Windows machine (or another Linux box, if you want) before proceeding.
### Sharing Files with Btsync ###
The following screencast shows how to sync an existing folder in a Windows 8 machine [192.168.0.106]. After adding the desired folder, get its key, and add it in your Linux installation via the "Enter a key or link" menu (as shown in the previous image), and the sync will start:
注释youtube视频
<iframe width="615" height="346" frameborder="0" allowfullscreen="" src="http://www.youtube.com/embed/f7kLM0lAqF4?feature=oembed"></iframe>
Now repeat the process for other computers or devices; selecting a folder or files to share, and importing the corresponding key(s) in your "central" btsync installation via the web interface on your Linux server.
### Auto-start Btsync as a Normal User ###
You will notice that the synced files in the screencast were created in the /btsync directory belonging to user and group 'root'. That is because we launched BitTorrent Sync manually as the superuser. However, under normal circumstances, you will want to have BitTorrent Sync start on boot and running as a non-privileged user (www-data or other special account created for that purpose, btsync user for example).
To do so, create a user called btsync, and add the following stanza to the /etc/rc.local file (before the exit 0 line):
sudo -u btsync /usr/local/bin/btsync/btsync --config /usr/local/bin/btsync/btsync.config --log /var/log/btsync.log
Finally, create the pid file:
# touch /usr/local/bin/btsync/.sync//sync.pid
and change the ownership of /usr/local/bin/btsync recursively:
# chown -R btsync:root /usr/local/bin/btsync
Now reboot and verify that btsync is running as the intended user:
![](https://farm9.staticflickr.com/8647/16327988660_644f6d4505_c.jpg)
Based on your chosen distribution, you may find other ways to enable btsync to start on boot. In this tutorial I chose the rc.local approach since it's distribution-agnostic.
### Final Remarks ###
As you can see, BitTorrent Sync is almost like server-less Dropbox for you. I said "almost" because of this: When you sync between devices on the same local network, sync happens directly between two devices. However, if you try to sync across different networks, and the devices to be paired are behind restrictive firewalls, there is a chance that the sync traffic goes through a third-party relay server operated by BitTorrent. While they claim that the traffic is [AES-encrypted][4], you may still not want this to happen. For your privacy, be sure to turn off relay/tracker server options in every folder that you are sharing.
Hope it helps! Happy syncing!
--------------------------------------------------------------------------------
via: http://xmodulo.com/share-files-between-computers-over-network.html
作者:[Gabriel Cánepa][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://xmodulo.com/author/gabriel
[1]:https://play.google.com/store/apps/details?id=com.bittorrent.sync
[2]:https://itunes.apple.com/us/app/bittorrent-sync/id665156116
[3]:http://www.getsync.com/
[4]:http://www.getsync.com/tech-specs

View File

@ -0,0 +1,56 @@
How to Hide PHP Version in Linux
================================================================================
In general, most of the web server software has been installed with default settings that will lead to information leakage. One of them is a PHP software. PHP (Hypertest Preprocessor) is one of the most popular server-side HTML embedded scripting language for the websites today. In the current challenging times, there are lots of attacker will try to discover the weaknesses in your your server system. Hence, i will describe the simple way to hide the PHP information in Linux server.
By default **expose_php** is set to On. Turning off the “expose_php” parameter causes that PHP will hide it version details.
[root@centos66 ~]# vi /etc/php.ini
In your php.ini, locate the line containing expose_php On and set it to Off:
expose_php = Off
Before the changes, web server header will look like below :
[root@centos66 ~]# curl -I http://www.ehowstuff.com/
----------
HTTP/1.1 200 OK
Server: nginx
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
X-Powered-By: PHP/5.3.3
X-Pingback: http://www.ehowstuff.com/xmlrpc.php
Date: Wed, 11 Feb 2015 14:10:43 GMT
X-Page-Speed: 1.9.32.2-4321
Cache-Control: max-age=0, no-cache
After the changes, PHP will no longer show the version to the web server header :
[root@centos66 ~]# curl -I http://www.ehowstuff.com/
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 11 Feb 2015 15:38:14 GMT
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
X-Pingback: http://www.ehowstuff.com/xmlrpc.php
Date: Wed, 11 Feb 2015 14:10:43 GMT
X-Page-Speed: 1.9.32.2-4321
Cache-Control: max-age=0, no-cache
As always if you need any help you can reach us on twitter @ehowstuff or drop us a comment below. [Jumping through archives page to read more articles..][1]
--------------------------------------------------------------------------------
via: http://www.ehowstuff.com/how-to-hide-php-version-in-linux/
作者:[skytech][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://www.ehowstuff.com/author/mhstar/
[1]:http://www.ehowstuff.com/archives/