Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
Logging system
- How do I view logs in Linux?
The common commands for viewing logs include tail, more, less, grep, and cat, each of which has its advantages. 1. Tail Command with parameter -f logfile outputs 10 lines by default. Also can use grep | pipe filtering log 2, 3 more/less used for paging search log, the cat is not recommended, if the log file is too big, will appear stuck more than 4, grep and combinations of the above command, Keyword filtering log information -n Line number of the keyword to be queried and output -i case insensitive -a n: displays the line where the matched string is located and the n lines after the matched string is displayed. After -b n: displays the line where the matched string is located and the n lines before the matched string. Before -c n: displays the line where the matched string is located and the n lines before the matched string. Displays the line containing the matched string and n lines before and after it, contextCopy the code
- How to quickly select to view application service logs?
We know to view the service log, one command: tailf logfile, but what if there are multiple services deployed on one server? 1. Let's not talk about building a log collection integration system; 2. If you use a tool, such as Xshell, write the command and set it as a shortcut key is also an option; 3. You can also set an alias in Linux using alias. That is, the view log command is replaced by a short and straightforward alias. 4. There is also the method I currently use, which is to write shell scripts to view application service logs.
#! /usr/bin/shEcho "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" echo "* * * * XXX background services log view system * * * *" echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" echo "* * * * to view current logging services include: * * * * * * * * 1, basic service * * * * * * * * 2, user service * * * * * * * * 3, XX services * * * * * * * * 4, XX services * * * * * * * * 5, XX * * * * * * * * 6, XX services * * * * * * * * 7, the XX center **** **** enter a value not between 1 and 7, Can exit the current script * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "read - p * * * * please enter choose to view the log service number, not input lines (the default display 10 lines) :" no line
#-z Checks whether the string type is empty. If the string type is true, the value is assigned. If the string type is not empty, the value is falseif [ -z $line ]; Then line=10 fi while: do case $no in 1)echo" 2)echo "tailf yourfilenamepath"; 3)echo "tailf yourfilenamepath"; 4)echo "tailf yourfilenamepath.log; Tailf yourFilenamepath.log;; 6)echo "tailf yourFilenamepath"; 7)echo "tailf yourFilenamepath"; *)echo "$no "echo "$no" break ;; esac doneCopy the code
- Why log collectors?
The above approach is not always the way to go, and flexibility needs to be developed again, so resource solutions are needed: log collectors (elK is recommended here) can collect and analyze log presentations from multiple services on a single platformCopy the code
- What are the mainstream logging systems?
ELK is a solution for the industry, the other is nothing more than collage, L is changed to FileBeat, where ELasticsearch is responsible for log saving and searching, Logstash is responsible for collecting logs, Kibana is responsible for interface drawbacks: • High operation and maintenance cost, every time a log collection is added, the configuration needs to be manually modified • The monitoring is missing, and the logstash state cannot be accurately obtained • Customized development and maintenance cannot be replaced with F: • Low intrusion, no need to modify any current code and configuration of the program • High performance compared to Logstash, which is a large IO footprintCopy the code
- Autonomous systems Integrated logging system?
Advantages: • Customized development and maintenance • Low o&M cost • The ability to monitor the operating status of the system has the lowest overhead compared with the first two disadvantages: • Low maturity compared with the first two, poor scalability • Extra development timeCopy the code
- So why choose a flawed log integration system? There’s no answer, because it’s in operations!