rsync Sync nginx Log encounters a problem summary

Source: Internet
Author: User
Tags system log rsync

First, the purpose

The Nginx log is synced to the local server in real time via the Rsync public key authentication method, and then processed using the Elk program.

Second, the problem encountered and the way to solve the idea

1. File permissions: Nginx Log default permissions are as follows:

[[email protected] ~]# ll/var/log/nginx/access.log136330:26 /var/log/nginx/access.log

I created a normal user, the standard user group, with rsync synchronization, reported a mistake, said that there is no permission to the file

File1file"/var/log/nginx/access.log": Permission denied ()

Problem 1 Workaround: So I directly modify the permissions of the file for other users can also be read. The following permissions are modified:

 [email protected] ~]# ll/var/log/nginx/access.log136330 : /var/log/nginx/access.log

After the above method is modified, the normal account can read the log. Rsync syncing to local is no problem

Question 2. The next day, you will see that the Rsync Sync program has failed error messages. Check that the file permissions are turned into the previous 640.

I checked the nginx. Related information: The task schedule for log cutting, log default permissions, and permissions for the Linux user group are described in the next section.

Issue 2 Workaround: Add the normal user previously used for synchronization to an affiliate group, which is in the ADM group. or re-establish a user with the appropriate permissions (for the system log read-only, and attached ADM group), as follows:

[Email protected] ~]# useradd-m-G Systemd-journal-g adm Logersync

Third, the knowledge points involved

1.nginx log logrotate Program automatic cutting:

Nginx log files are automatically segmented,/var/log/nginx/*.log, and automatically gzip packed and stored in and log siblings every day.

First look at the Logrotate program in the nginx split configuration file

cat /etc/logrotate.d//var/log/nginx/*. Log {        daily        Missingok        rotate 52        Compress        delaycompress        notifempty        Create 640 Nginx adm        sharedscripts        postrotate                [-f/var/run/nginx.pid] && kill-usr1 ' cat/var/run/nginx.pid '        endscript}

Default parameter explanation:

    • Daily: Log cut per day (weekly, monthly)
    • Missingok: Ignore error when log does not exist
    • Rotate: After cutting 52 times, it will then delete the oldest
    • Compress: Use gzip to compress post-cut logs
    • Delaycompress: If a log is still being written to or used by the program, it will be compressed later when it is split.
    • Notifempty: Do not cut empty files
    • Create 640 Nginx ADM: Set the new log file permissions after the cut is 640, is the master is Nginx, belongs to the group is ADM (here is my first two reasons for the problem)
    • Sharedscripts: After all the log files have been cut, execute the following script
    • Postrotate: The contents of the following [] are sent to the Nginx main process to send a USR1 signal, tell Nginx that the log has been cut, you should use the new file.
    • Endsrciprs: End of script

Nginx

Resources:

Https://zh.wikipedia.org/wiki/SIGUSR1%E5%92%8CSIGUSR2

http://drumcoder.co.uk/blog/2012/feb/03/nginx-and-logrotate/

2. User group Permissions issues

You can specify a group when you add a user, as follows:

[[email protected] ~]# useradd-ID  testuser1uid=1002(testuser1) gid=4 groups=4(ADM)

It adds a testuser1 user and specifies that the group is an ADM group. If you do not specify a group when creating a user, a group name and GID number with the same name as the user name will be created automatically

You can also add multiple groups to a user. This will have permissions under the other groups, such as:

[[email protected] ~]# gpasswd-ID  testuser1uid=1002(testuser1) gid=4 groups=4(ADM),(users)

The TestUser1 is also attached to the Users group.

Iv. Summary

Mainly related to the Nginx service log cutting default.

Reference article:

Https://wiki.archlinux.org/index.php/Users_and_groups_ (English)

rsync Sync nginx Log encounters a problem summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.