Linux: firewall-cmd command options

firewall-cmd is a command-line utility for managing firewalld, the dynamic firewall manager available on many Linux distributions. It allows you to configure various aspects of your firewall settings. To display the available options for firewall-cmd, you can use the --help option or explore specific subcommands and their options. Here are the general options:

  1. To display the general help and a list of available options for firewall-cmd:firewall-cmd --help
  2. To display the version of firewall-cmd:cssCopy codefirewall-cmd --version
  3. To display help for a specific subcommand, you can use:firewall-cmd --<subcommand> --help Replace <subcommand> with the specific operation you want to learn more about, such as --add-service, --add-port, --list-services, --list-ports, etc.

Here are some common firewall-cmd subcommands and their options:

  • --add-service: Add a service to the firewall configuration.
    • --permanent: Make the change permanent (will survive reboots).

Example:

firewall-cmd --add-service=http firewall-cmd --add-service=http --permanent

  • --add-port: Add a port to the firewall configuration.
    • --permanent: Make the change permanent (will survive reboots).

Example:

firewall-cmd --add-port=80/tcp firewall-cmd --add-port=80/tcp --permanent

  • --remove-service: Remove a service from the firewall configuration.
    • --permanent: Make the change permanent (will survive reboots).

Example:

firewall-cmd --remove-service=http firewall-cmd --remove-service=http --permanent

  • --remove-port: Remove a port from the firewall configuration.
    • --permanent: Make the change permanent (will survive reboots).

Example:

firewall-cmd --remove-port=80/tcp firewall-cmd --remove-port=80/tcp --permanent

  • --list-all: Show all configured rules, including services, ports, and other settings.
    • --permanent: List only the permanent rules.

Example:

firewall-cmd --list-all firewall-cmd --list-all --permanent

  • --reload: Reload the firewall configuration. Useful when you make changes to the configuration.

Example:

firewall-cmd --reload

These are just a few of the many options and subcommands available with firewall-cmd. For detailed information on specific options, you can refer to the firewall-cmd manual page or use the --help option for specific subcommands, as shown earlier.

Kanban: Core principles of Kanban

Kanban is a popular agile methodology and a lean approach to managing work and processes. Its core principles revolve around visualizing work, limiting work in progress (WIP), and managing flow efficiently. Here are the core principles of Kanban:

  1. Visualize the Work: Kanban emphasizes the use of visual boards to represent work items and their status. Typically, this involves using cards or sticky notes on a physical board or digital tools to create a visual representation of tasks, projects, or work items. The visual board should provide a clear and real-time view of what work is in progress, what is queued, and what is completed.
  2. Limit Work in Progress (WIP): One of the key principles of Kanban is to set explicit limits on the number of work items that can be in progress at any given time. By doing so, teams ensure that they do not overburden themselves and maintain a steady and sustainable pace of work. WIP limits help prevent bottlenecks and encourage the completion of tasks before taking on new ones.
  3. Manage Flow: Kanban is all about optimizing the flow of work through the system. This involves continuously monitoring and managing the movement of work items from one stage to the next. Teams aim to minimize delays, reduce cycle times, and ensure a smooth, efficient flow from request to delivery.
  4. Make Process Policies Explicit: Kanban encourages teams to define and make explicit the policies and rules that govern the flow of work. This includes defining what constitutes “done” for each work item, how work items are prioritized, and what criteria trigger the movement of items between stages. This clarity helps in maintaining consistency and improving communication within the team.
  5. Feedback Loops and Continuous Improvement: Kanban promotes a culture of continuous improvement. Teams regularly review their Kanban board and process to identify bottlenecks, inefficiencies, and areas for improvement. These insights are used to make incremental changes and refine the process over time.
  6. Focus on Customer Value: Kanban emphasizes delivering value to the customer as efficiently as possible. Teams should prioritize work based on customer needs and expectations, ensuring that the most valuable items are completed first.
  7. Collaborative and Evolutionary Approach: Kanban encourages collaboration among team members and stakeholders. It also acknowledges that processes can evolve and improve over time based on data and feedback, rather than requiring a complete overhaul.
  8. Respect Existing Roles and Responsibilities: Unlike some other agile methodologies, Kanban often respects existing roles and responsibilities within an organization. It doesn’t prescribe specific team structures or roles but rather focuses on improving the existing workflow and processes.

These core principles of Kanban help teams and organizations achieve greater efficiency, transparency, and flexibility in their work processes while continuously improving their ability to deliver value to customers. Kanban’s adaptability makes it applicable in various industries and contexts.

Application Monitoring – Golden Signals

Golden signals in application monitoring are a set of key performance indicators (KPIs) that provide a comprehensive view of an application’s health and performance. These signals are crucial for ensuring that an application meets its service level objectives (SLOs) and delivers a satisfactory user experience. Golden signals help teams quickly identify and respond to issues, ultimately improving system reliability and user satisfaction. The four primary golden signals are:

  1. Latency: Latency measures the time it takes for a request to travel from the user’s device to the application and back. It’s a critical metric because users expect applications to respond quickly. High latency can indicate bottlenecks or performance problems within the application, its dependencies, or the network. Monitoring latency helps identify and address performance issues before they impact the user experience.
  2. Error Rate: Error rate measures the percentage of requests that result in errors or failures. This includes HTTP 5xx status codes, database query failures, or any other unexpected errors. A high error rate can indicate issues with application code, infrastructure, or third-party services. Monitoring error rates helps teams identify and fix bugs or infrastructure problems promptly.
  3. Traffic: Traffic refers to the volume of requests or transactions processed by the application. Monitoring traffic helps teams understand how the application’s load varies over time. Sudden spikes in traffic can lead to performance problems or outages if the application isn’t scaled appropriately. Additionally, understanding traffic patterns can inform capacity planning and resource allocation.
  4. Saturation: Saturation measures the resource utilization of the application and its underlying infrastructure. It includes metrics like CPU usage, memory usage, and disk I/O. Monitoring saturation helps teams ensure that the application and its dependencies have enough resources to handle the current load. High saturation levels can lead to performance degradation or outages if resources become exhausted.

Docker: Docker main commands

Docker is a powerful platform for developing, shipping, and running applications inside containers. Here are some of the main Docker commands that you’ll frequently use:

1. Docker Version:

  • Check the installed Docker version.

docker --version

2. Docker Help:

  • Get help and see a list of Docker commands and their descriptions.

docker --help

3. Docker Images:

  • List all locally available Docker images.

docker images

4. Docker Pull:

  • Download a Docker image from a registry (e.g., Docker Hub).

docker pull image_name:tag

5. Docker Run:

  • Create and start a new container from an image.

docker run [options] image_name [command]

6. Docker PS:

  • List running containers.

docker ps

7. Docker PS (All Containers):

  • List all containers, including stopped ones.

docker ps -a

8. Docker Stop:

  • Stop a running container gracefully.

docker stop container_id_or_name

9. Docker Kill:

  • Forcefully stop a running container.

docker kill container_id_or_name

10. Docker Start:

  • Start a stopped container.

docker start container_id_or_name

11. Docker Remove:

  • Remove a stopped container.

docker rm container_id_or_name

12. Docker Logs:

  • View the logs of a container.

docker logs container_id_or_name

13. Docker Exec:

  • Run a command inside a running container.

docker exec [options] container_id_or_name command

14. Docker Network:

  • List and manage Docker networks.

docker network ls

15. Docker Volume:

  • List and manage Docker volumes.

docker volume ls

16. Docker Build:

  • Build a Docker image from a Dockerfile.

docker build -t image_name:tag path_to_Dockerfile_directory

17. Docker Compose:

  • Manage multi-container Docker applications using a Compose file.

docker-compose [options] command

18. Docker Save and Load:

  • Save an image as a tarball and load it from a tarball.

docker save -o image_name.tar image_name:tag docker load -i image_name.tar

19. Docker Push:

  • Push a locally built image to a Docker registry.

docker push image_name:tag

20. Docker Search:

  • Search for Docker images on Docker Hub.

docker search search_term

These are some of the essential Docker commands to get you started. Docker provides many more commands and options for more advanced use cases and customization. You can always refer to the official Docker documentation or use the docker --help command to explore more options and details for each command.

SSH: How to copy my SSH key to a remote host

To copy your SSH key to a remote host, you can use the ssh-copy-id command, which is a convenient way to install your public key on a remote server. Here are the steps to do this:

  1. Generate SSH Key (if you haven’t already): If you don’t have an SSH key pair (public and private keys) already, you can generate one using the ssh-keygen command. Open a terminal on your local machine and run: ssh-keygen -t rsa -b 4096 -C "your_email@example.com" Replace "your_email@example.com" with your actual email address. This command will generate a new SSH key pair and store it in the default location (~/.ssh/id_rsa for the private key and ~/.ssh/id_rsa.pub for the public key).
  2. Copy the Public Key to the Remote Host: Use the ssh-copy-id command to copy your public key to the remote host. Replace your_username and remote_host with the appropriate values:bashCopy codessh-copy-id your_username@remote_host You’ll be prompted to enter your password on the remote host for authentication.Note: If you’re using a custom SSH port, you can specify it with the -p option, like this: ssh-copy-id -p custom_port your_username@remote_host
  3. Authenticate with Your SSH Key: After successfully copying the SSH key to the remote host, you can now log in without entering a password. The SSH key authentication will be used instead.Test this by trying to SSH into the remote host: ssh your_username@remote_host You should be logged in without being prompted for a password.

By following these steps, you’ve securely copied your SSH key to the remote host, allowing you to log in without needing to enter a password each time. This is a more secure and convenient way to access remote servers.

PostgreSQL: How to display block I/O metrics (input/output) on a PostgreSQL server

To display block I/O metrics (input/output) on a PostgreSQL server, you can use various methods and tools. Here are some options:

  1. pg_stat_statements:
    • PostgreSQL’s pg_stat_statements extension can provide insight into the number of blocks read and written by specific queries. To use it, you need to enable the extension and monitor the pg_stat_statements view.
    First, enable the extension by adding or uncommenting the following line in your postgresql.conf file and then restarting PostgreSQL:shared_preload_libraries = 'pg_stat_statements' After that, you can query the pg_stat_statements view to see I/O statistics for specific queries:SELECT query, total_time, rows, shared_blks_read, shared_blks_hit, local_blks_read, local_blks_hit, temp_blks_read, temp_blks_written FROM pg_stat_statements; This query will display I/O metrics for the recorded statements.
  2. pg_stat_activity:
    • You can also use the pg_stat_activity view to monitor ongoing queries and check their I/O activity. This view includes information about the current query being executed, such as the number of blocks read and written.SELECT pid, query, pg_size_pretty(pg_stat_get_blocks_fetched(pid)) AS blocks_fetched, pg_size_pretty(pg_stat_get_blocks_hit(pid)) AS blocks_hit FROM pg_stat_activity; This query shows the process ID (pid), the query being executed (query), the number of blocks fetched, and the number of blocks hit in the shared buffer cache.
  3. pg_stat_bgwriter:
    • The pg_stat_bgwriter view provides statistics about the background writer process, which manages PostgreSQL’s background I/O operations. It includes information about buffers written and other I/O-related metrics.SELECT checkpoints_timed, buffers_heckpoint, buffers_clean, buffers_backend, buffers_alloc FROM pg_stat_bgwriter; This query will show various I/O-related metrics related to background writing.
  4. Operating System Tools:
    • You can also use operating system-level monitoring tools to track I/O metrics for the PostgreSQL process. Common tools include iostat on Linux and Task Manager on Windows. These tools can provide system-wide I/O metrics, including disk reads and writes by the PostgreSQL process.
    For example, on Linux, you can run the following command to monitor disk I/O for the PostgreSQL process: iostat -xk 1 | grep postgres This command will display real-time I/O metrics for the PostgreSQL process.

Remember that monitoring I/O metrics can help identify performance bottlenecks and optimize your PostgreSQL database for better performance. Consider using a combination of these methods to gain a comprehensive understanding of your system’s I/O activity.

PotgreSQL: How to display PostgreSQL Server sessions

You can display the active sessions (connections) on a PostgreSQL server by querying the pg_stat_activity view. This view provides information about the currently active connections and their associated queries. Here’s how you can use it:

  1. Connect to PostgreSQL: Start by connecting to your PostgreSQL server using the psql command-line client or another PostgreSQL client of your choice. You may need to provide the appropriate username and password or other authentication details.bashCopy codepsql -U your_username -d your_database_name
  2. Query pg_stat_activity: Once connected, you can query the pg_stat_activity view to see the active sessions. You can run the following SQL query: SELECT * FROM pg_stat_activity; This query will return a list of all active sessions, including information such as the process ID (pid), username (usename), database (datname), client address (client_addr), and the SQL query being executed (query). The state column provides the current state of each session, which can be helpful for diagnosing issues.
  3. Filter and Format the Output: If you want to filter the results or display specific columns, you can modify the query accordingly. For example, to see only the username, database, and query being executed, you can use the following query:SELECT usename, datname, query FROM pg_stat_activity; You can also use WHERE clauses to filter the results based on specific criteria. For instance, to see only sessions with a specific application name, you can do: SELECT * FROM pg_stat_activity WHERE application_name = 'your_application_name';
  4. Exit psql: After viewing the active sessions, you can exit the PostgreSQL client by typing: \q

This will return you to the command line.

Keep in mind that pg_stat_activity provides a snapshot of active sessions at the time you run the query. If you want to continuously monitor sessions in real-time, you may want to use monitoring tools or automate queries to periodically check the pg_stat_activity view.