西维蜀黍

【Linux】查看 Log

Log Files

  • /var/log/syslog or /var/log/messages: general messages, as well as system-related information. Essentially, this log stores all activity data across the global system.

  • /var/log/auth.log or /var/log/secure: store authentication logs, including both successful and failed logins and authentication methods. Again, the system type dictates where authentication logs are stored; Debian/Ubuntu information is stored in /var/log/auth.log, while Redhat/CentrOS is stored in /var/log/secure.

  • /var/log/boot.log: a repository of all information related to booting and any messages logged during startup.

  • /var/log/maillog or var/log/mail.log: stores all logs related to mail servers, useful when you need information about postfix, smtpd, or any email-related services running on your server.

  • /var/log/kern: stores Kernel logs and warning data. This log is valuable for troubleshooting custom kernels as well.

  • /var/log/dmesg: messages relating to device drivers. The command dmesg can be used to view messages in this file.

  • /var/log/faillog: contains information all failed login attempts, which is useful for gaining insights on attempted security breaches, such as those attempting to hack login credentials as well as brute-force attacks.

  • /var/log/cron: stores all Crond-related messages (cron jobs), such as when the cron daemon initiated a job, related failure messages, etc.

  • /var/log/messages : General message and system related stuff

  • /var/log/auth.log : Authenication logs

  • /var/log/kern.log : Kernel logs

  • /var/log/cron.log : Crond logs (cron job)

  ...


【Lock】锁(Lock)/ Mutex

Lock / Mutex

In computer science, a lock or mutex (from mutual exclusion) is a synchronization primitive: a mechanism that enforces limits on access to a resource when there are many threads of execution. A lock is designed to enforce a mutual exclusion concurrency control policy, and with a variety of possible methods there exists multiple unique implementations for different applications.

  ...


【Operating System】进程 - 进程通讯 - Monitor

Monitor

Definition1

由于信号量和互斥锁可能会导致**死锁(deadlock)**问题,因此,在实际生产中使用信号量和互斥锁必须非常小心。

为此,Brinch Hansen 和 Hoare 提出了一个更高层(higher-level)的同步原语(primitive),以实现互斥(mutual exclusion),称为管程(Monitor)。管程(Monitor) 从本质来说是一个程序集、变量和数据结构集合。

管程要求:在任一时刻只有一个进程能在管程中处于活跃状态(active)。

具体来说,当一个进程调用管程程序时, 管程程序会首先检查当前是否有其他进程在监视器中处于活跃状态。如果有,这个进程会进入阻塞状态直到其他进程离开了监视器;如果没有其他进程正在使用监视器,这个进程就可以使用监视器。

编译器会具体负责管程机制如何具体实现(虽然通常的方法是通过互斥锁)。因此,对程序员而言,我们只需要知道管程机制能够保证互斥访问(mutual exclusion),即任一时刻只会有一个进程进入临界区。

Definition2

In concurrent programming (also known as parallel programming), a monitor is a synchronization construct that allows threads to have both mutual exclusion and the ability to wait (block) for a certain condition to become false.

Monitors also have a mechanism for signaling other threads that their condition has been met. A monitor consists of a mutex (lock) object and condition variables. A condition variable essentially is a container of threads that are waiting for a certain condition. Monitors provide a mechanism for threads to temporarily give up exclusive access in order to wait for some condition to be met, before regaining exclusive access and resuming their task.

Another definition of monitor is a thread-safe class, object, or module that wraps around a mutex in order to safely allow access to a method or variable by more than one thread.

The defining characteristic of a monitor is that its methods are executed with mutual exclusion: At each point in time, at most one thread may be executing any of its methods. By using one or more condition variables it can also provide the ability for threads to wait on a certain condition (thus using the above definition of a “monitor”). For the rest of this article, this sense of “monitor” will be referred to as a “thread-safe object/class/module”.

  ...


【Design Pattern】Concurrency - Active Object Pattern

ACTIVE OBJECT

Active Object is a concurrency pattern in which we try to separate the invocation of a method from its execution. Typically, an active object provides synchronous methods and executes the method calls in an asynchronous way. An active object usually has its own thread of control.

This pattern is useful in refactoring legacy projects by introducing concurrency capability.

The following class diagram shows the basic structure of this pattern.

The key elements in active object pattern are:

  • Proxy (or Client Interface) - A public method provided by active object to clients.
  • Dispatch Queue - A list of pending requests from clients.
  • Scheduler - Determines the order to execute the requests.
  • Result Handle (or Callback) - This allows the result to be obtained by proxy after a request is executed.
  ...


【Design Pattern】Concurrency - Monitor Object Pattern

MONITOR OBJECT

Generally, Monitor Object is a pattern that controls the concurrent access of a method in an object. If there are some concurrent threads calling a method at the same time, only one thread can execute this method.

  ...


【Design Pattern】Concurrency - Double-checked Locking Pattern

Introduction

This pattern reduces the number of lock acquisitions by simply checking the locking condition beforehand. As a result of this, there’s usually a performance boost.

  ...


【Design Pattern】Concurrency Pattern

  ...


【Design Pattern】Microservices - Health Check Pattern

Context

Sometimes a service instance can be incapable of handling requests yet still be running. For example, it might have ran out of database connections. When this occurs, the monitoring system should generate a alert. Also, the load balancer or service registry should not route requests to the failed service instance.

  ...


【Design Pattern】Microservices - Circuit Breaker Pattern

Background

In Electrical or Electornics domain, a circuit breaker is an automatically operated electrical switch designed to protect an electrical circuit. Its basic function is to interrupt current flow after a fault is detected. It can then be reset to resume normal operation after the fault is solved.

Similarly to protect our microservices from an excess of requests, it’s better to interrupt communication between the front-end and the back-end as soon as a recurring fault has been detected in the back-end.

In his excellent book Release It, Michael Nygard popularized the Circuit Breaker pattern to prevent this kind of catastrophic cascade.

  ...


【Golang】内存管理

  ...