| | 1 | = AWStats = |
| | 2 | |
| | 3 | == Copying the logs to penguin == |
| | 4 | |
| | 5 | The nginx logs on wiki:PuffinServer are copied to wiki:PenguinServer using scp, in {{{/etc/logrotate.d/nginx}}} the {{{nginx-logs}}} script is run just before the logs are rotated: |
| | 6 | |
| | 7 | {{{ |
| | 8 | prerotate |
| | 9 | /usr/local/bin/nginx-logs |
| | 10 | /usr/local/bin/50x-errors chris@webarchitects.co.uk |
| | 11 | if [ -d /etc/logrotate.d/httpd-prerotate ]; then \ |
| | 12 | run-parts /etc/logrotate.d/httpd-prerotate; \ |
| | 13 | fi \ |
| | 14 | endscript |
| | 15 | }}} |
| | 16 | |
| | 17 | This script contains: |
| | 18 | |
| | 19 | {{{ |
| | 20 | #!/bin/bash |
| | 21 | |
| | 22 | DATE=$(date "+%Y-%m-%d") |
| | 23 | LOG_FILE=/var/log/nginx/access.log |
| | 24 | REMOTE_FILE=puffin-nginx-$DATE.log |
| | 25 | |
| | 26 | scp $LOG_FILE penguin:nginx/$REMOTE_FILE |
| | 27 | }}} |
| | 28 | |
| | 29 | It depends on the {{{/root/.ssh/config}}} file on puffin containing: |
| | 30 | |
| | 31 | {{{ |
| | 32 | Host penguin |
| | 33 | Hostname penguin.webarch.net |
| | 34 | User puffin |
| | 35 | }}} |
| | 36 | |
| | 37 | And the puffin root users public key being on penguin. |
| | 38 | |
| | 39 | On penguin the {{{/etc/ssh/sshd_config}}} file contains: |
| | 40 | |
| | 41 | {{{ |
| | 42 | AllowGroups sudo sshaccess |
| | 43 | }}} |
| | 44 | |
| | 45 | And the puffin user on penguin was created with no password and in the sshaccess group: |
| | 46 | |
| | 47 | {{{ |
| | 48 | adduser --disabled-password --ingroup sshaccess puffin |
| | 49 | }}} |
| | 50 | |
| | 51 | Then the ssh public key was copied to {{{/home/puffin/.ssh/authorized_keys}}} on penguin and this was added at the start so it can only be used from puffin's IP address: |
| | 52 | |
| | 53 | {{{ |
| | 54 | from="puffin.webarch.net" ssh-rsa AAAA... |
| | 55 | }}} |
| | 56 | |
| | 57 | The log files that are created on penguin are in {{{/home/puffin/nginx/}}} and have a file name based on the date they are created, eg: |
| | 58 | |
| | 59 | {{{ |
| | 60 | -rw-r----- 1 puffin puffin 11M Jun 22 06:25 puffin-nginx-2013-06-22.log |
| | 61 | }}} |
| | 62 | |