Showing posts with label Operating System. Show all posts
Showing posts with label Operating System. Show all posts

Monday, August 18, 2025

ERROR with "Failed to set locale, defaulting to C" on Centos at the docker environment (yum install)

ERROR with "Failed to set locale, defaulting to C" on Centos at the docker environment (yum install)


Fix:

As root user, then do steps:

sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

yum update -y

Saturday, May 25, 2024

The Ultimate SCP Command Guide: Pushing and Pulling Files with Ease

The Ultimate SCP Command Guide: Pushing and Pulling Files with Ease

The scp (secure copy) command is used to securely transfer files between hosts on a network. It uses SSH for data transfer and provides the same authentication and security as SSH. Below are explanations and examples for using scp to "pull" files (download) and "push" files (upload).

SCP Pull Command (Download Files)

Syntax:

scp [options] username@source_host:file_path destination_folder

Example: Suppose you want to download a file named example.txt from a remote server 192.168.1.5 where your username is john. You want to save this file to the local directory /home/john/documents.

scp john@192.168.1.5:/path/to/example.txt /home/john/documents

In this command:

  • john@192.168.1.5: specifies the username and the host from which the file will be downloaded.
  • /path/to/example.txt is the full path to the file on the remote host.
  • /home/john/documents is the local directory where the file will be saved.

SCP Push Command (Upload Files)

Syntax:

scp [options] file_path username@destination_host:destination_folder

Example: If you want to upload a file named report.pdf from your local directory to a remote server 192.168.1.10 where your username is john, and you want to place this file in the remote directory /home/john/reports.

scp /path/to/local/report.pdf john@192.168.1.10:/home/john/reports

In this command:

  • /path/to/local/report.pdf is the path to the file on your local machine.
  • john@192.168.1.10: specifies the username and the host to which the file will be uploaded.
  • /home/john/reports is the directory on the remote host where the file will be placed.

Useful Options

  • -r: Recursively copy entire directories.
  • -p: Preserves modification times, access times, and modes from the original file.
  • -q: Use this option to operate in quiet mode, which suppresses the progress meter as well as warning and diagnostic messages.
  • -C: Enables compression. This can speed up transfers, particularly over slower connections.

These commands demonstrate basic scp usage for transferring files between local and remote machines securely.

Tuesday, May 7, 2024

How to Simulate High CPU and RAM Load on CentOS for Performance Testing

How to Simulate High CPU and RAM Load on CentOS for Performance Testing


ncreasing CPU and RAM utilization on a CentOS system programmatically can be useful for testing purposes, such as evaluating the performance under different load conditions. Here, I'll provide you with a couple of ways to simulate high CPU and RAM usage using shell commands.

Increasing CPU Usage

To increase CPU usage, you can use the stress tool, which is designed to impose certain types of compute stress on your system.

Install the stress tool:

sudo yum install epel-release
sudo yum install stress

Simulate high CPU load: You can start a number of workers that will fully load a number of CPUs.

stress --cpu 8 --timeout 300

This command will start 8 workers that stress the CPU for 300 seconds.

Increasing RAM Usage

To increase RAM usage, you can use a simple shell script that allocates a certain amount of memory and holds it for a period of time.

Create a bash script to increase memory usage:

  1. Here’s a simple script that allocates memory in increments.

#!/bin/bash # Usage: ./increase_memory.sh <memory_in_mb> <duration_in_seconds> if [ $# -ne 2 ]; then echo "Usage: $0 <Memory in MB> <Duration in seconds>" exit 1 fi echo "Allocating $1 MB of memory for $2 seconds." /usr/bin/perl -e "\$|=1; \$a='a' x ($1*1024*1024); sleep $2;"

Save this script as increase_memory.sh and make it executable:

chmod +x increase_memory.sh

Run the script:

./increase_memory.sh 1024 300

This command will allocate 1024 MB of RAM for 300 seconds.

Automating and Looping the Stress Tests

If you want to continuously or repeatedly apply these loads in a loop for testing over a longer period, you can wrap these commands in a shell loop.

#!/bin/bash while true; do echo "Starting CPU and Memory stress test" stress --cpu 4 --io 2 --vm 2 --vm-bytes 128M --timeout 600 & ./increase_memory.sh 1024 600 sleep 60 # Rest for 60 seconds before repeating the test done

This script runs both CPU and memory stress tests in parallel, waits for 60 seconds after the stress period, and then repeats the tests. Adjust the parameters according to your testing requirements.

Important Notes

  • Monitoring: While running these tests, keep an eye on system monitoring tools to ensure that you are not causing damage or excessive wear on hardware components, especially in production environments.
  • Permissions: Ensure that you have the necessary permissions to install and run these tools on your system.
  • Resource Allocation: Be cautious with the amount of stress you apply, especially on production systems, as this could lead to system crashes or slowdowns for other processes.

These tools and scripts should help you simulate high CPU and RAM usage on a CentOS system, which can be crucial for performance tuning, capacity planning, and reliability testing.



Sunday, April 21, 2024

Mastering System Performance: Top 10 Commands Every Veteran Linux Admin Should Know

Mastering System Performance: Top 10 Commands Every Veteran Linux Admin Should Know


  1. top - Provides a dynamic real-time view of a running system, showing system summary information and a list of processes or threads currently being managed by the Linux kernel.

  2. htop - An interactive system-monitor process-viewer that provides a more user-friendly and visually appealing alternative to top.

  3. vmstat - Reports information about processes, memory, paging, block IO, traps, and CPU activity, helping to monitor system performance by various metrics.

  4. iostat - Generates CPU, I/O statistics for devices, and partitions, offering insight into system input/output device loading which helps in diagnosing bottleneck issues in the system.

  5. mpstat - Displays statistics about CPU usage on a per-processor basis, allowing for detailed analysis of balance and performance in multi-core systems.

  6. dstat - A versatile tool that provides system resource statistics, including network behavior, system load, and process activity.

  7. sar - Collects, reports, and saves system activity information, useful for historical analysis of performance metrics across various system resources.

  8. perf - A powerful performance analyzing tool used for detailed performance monitoring and debugging, supporting complex queries about system activity.

  9. nmon - Monitors and benchmarks performance across a wide variety of parameters; it provides a rich set of features to view data related to CPU, memory, disks, network, and NFS.

  10. bpftrace - A high-level tracing language for Linux enhanced BPF, ideal for advanced performance monitoring, networking, and security purposes.

100 Essential Commands Every Expert Linux Administrator Should Know

100 Essential Commands Every Expert Linux Administrator Should Know



  1. awk: Text processing and pattern matching.

    • awk '/pattern/ {action}' filename
  2. sed: Stream editing for transforming text.

    • sed -i 's/old/new/g' filename
  3. grep: Searches for patterns in text.

    • grep -P '^a.*z$' filename
  4. tcpdump: Captures and analyzes network packets.

    • tcpdump -i eth0 'port 80'
  5. netstat: Displays network connections, routing tables, and statistics.

    • netstat -tulpn
  6. iptables: Manages Linux firewall rules.

    • iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  7. systemctl: Controls the systemd system and service manager.

    • systemctl status nginx
  8. strace: Traces system calls and signals.

    • strace -c ls
  9. lsof: Lists open files and the processes that opened them.

    • lsof -i :22
  10. rsync: Efficient file copying and synchronization.

    • rsync -avz /src/ /dest/
  11. perf: Performance analyzing tool.

    • perf stat -B dd if=/dev/zero of=/dev/null count=1000000
  12. vmstat: Reports virtual memory statistics.

    • vmstat 1
  13. sar: System activity reporter.

    • sar -u 1 3
  14. ss: Investigates sockets.

    • ss -tulwn
  15. find: Searches for files in a directory hierarchy.

    • find / -type f -name 'config.php' -exec chmod 644 {} \;
  16. nmap: Network exploration and security auditing.

    • nmap -A -T4 target_ip
  17. htop: Interactive process viewer.

    • htop
  18. iostat: Monitors system input/output device loading.

    • iostat -mx 2
  19. dstat: Versatile tool for generating system resource statistics.

    • dstat -cdngy 5 20
  20. iftop: Displays bandwidth usage on an interface.

    • iftop -i eth0
  21. ip: Shows and manipulates routing, devices, policy routing, and tunnels.

    • ip addr show
  22. dig: DNS lookup.

    • dig +trace yourdomain.com
  23. watch: Executes a program periodically, showing output.

    • watch -n 2 'df -h'
  24. crontab: Manages a cron table for scheduling tasks.

    • crontab -e
  25. mdadm: Manages MD (multi-disk) devices for RAID arrays.

    • mdadm --detail /dev/md0
  26. chroot: Changes the root directory.

    • chroot /path/to/new/root
  27. GnuPG: Encrypts and signs data.

    • gpg --encrypt --recipient name@example.com file.txt
  28. traceroute: Traces the route packets take to a network host.

    • traceroute google.com
  29. journalctl: Queries the systemd journal.

    • journalctl -u nginx.service --since yesterday
  30. nmcli: NetworkManager command-line tool.

    • nmcli dev status
  31. firewall-cmd: Manages firewalld settings.

    • firewall-cmd --list-all
  32. bpftrace: Traces Linux kernel using BPF.

    • bpftrace -e 'tracepoint:syscalls:sys_enter_* { @[probe] = count(); }'
  33. fail2ban: IP banning to protect against brute-force attacks.

    • fail2ban-client status sshd
  34. ipset: Creates IP collections for use with iptables.

    • ipset create test hash:ip
  35. iotop: Monitors I/O usage by processes.

    • iotop -o
  36. mtr: Network diagnostic tool.

    • mtr myserver.com
  37. glances: System monitoring tool.

    • glances
  38. ncdu: Disk usage analyzer with an ncurses interface.

    • ncdu /path/to/directory
  39. dd: Convert and copy a file.

    • dd if=/dev/zero of=/dev/sda bs=1M count=1024
  40. fuser: Identify processes using files or sockets.

    • fuser -uv /path/to/file
  41. kdump: Kernel crash dumping mechanism.

    • systemctl status kdump
  42. parted: Disk partitioning and resizing tool.

    • parted -l
  43. lsblk: List information about block devices.

    • lsblk
  44. pv: Monitor the progress of data through a pipeline.

    • pv data.file | gzip > data.file.gz
  45. mount: Mount a filesystem.

    • mount /dev/sda1 /mnt
  46. umount: Unmount file systems.

    • umount /mnt
  47. renice: Alter priority of running processes.

    • renice +10 -p 1234
  48. at: Schedule commands to be executed at a particular time.

    • echo "echo hello" | at now + 1 minute
  49. scp: Secure copy of files over the network.

    • scp localfile user@remote:/path
  50. tar: Archive files into a tape archive (tar) format.

    • tar -czvf archive.tar.gz /path/to/directory
  51. curl: Tool to transfer data from or to a server.

    • curl -O http://example.com/file.zip
  52. wget: Non-interactive network downloader.

    • wget http://example.com/file.zip
  53. ssh: Secure Shell, a protocol for secure remote login and other secure network services.

    • ssh user@host
  54. scp: Secure copy (remote file copy program).

    • scp file.txt user@host:/path
  55. rsnapshot: Local and remote filesystem snapshot utility.

    • rsnapshot daily
  56. vim: Highly configurable text editor.

    • vim filename
  57. nano: Easy-to-use text editor.

    • nano filename
  58. git: Distributed version control system.

    • git clone https://github.com/user/project.git
  59. screen: Full-screen window manager that multiplexes a physical terminal.

    • screen -S session_name
  60. tmux: Terminal multiplexer, lets you switch easily between several programs in one terminal.

    • tmux new -s session_name
  61. ansible: Automation tool for software provisioning, configuration management, and application deployment.

    • ansible all -m ping
  62. terraform: Tool for building, changing, and versioning infrastructure safely and efficiently.

    • terraform apply
  63. docker: Platform for developers and sysadmins to develop, deploy, and run applications with containers.

    • docker run --name web -p 8080:80 nginx
  64. kubectl: Command line tool for controlling Kubernetes clusters.

    • kubectl get pods
  65. helm: Kubernetes package manager.

    • helm install my-release mychart
  66. ufw: Uncomplicated Firewall, frontend for iptables.

    • ufw allow from 192.168.1.1 to any port 22
  67. fail2ban-client: Interface to Fail2Ban.

    • fail2ban-client status
  68. apachectl: Control interface for Apache HTTP server.

    • apachectl status
  69. mysql: Command-line tool for managing MySQL databases.

    • mysql -u root -p
  70. pg_dump: Backup database utility for PostgreSQL.

    • pg_dump -U user dbname > outfile
  71. top: Displays Linux processes.

    • top
  72. ps: Reports a snapshot of the current processes.

    • ps aux
  73. kill: Send a signal to a process.

    • kill -9 1234
  74. killall: Kill processes by name.

    • killall nginx
  75. nohup: Run a command immune to hangups, with output to a non-tty.

    • nohup command &
  76. du: Disk usage statistics.

    • du -sh /path/to/directory
  77. df: Report file system disk space usage.

    • df -h
  78. free: Display amount of free and used memory in the system.

    • free -m
  79. ln: Make links between files.

    • ln -s target link_name
  80. chmod: Change file mode bits.

    • chmod +x script.sh
  81. chown: Change file owner and group.

    • chown user:group file
  82. useradd: Create a new user or update default new user information.

    • useradd -m username
  83. usermod: Modify a user account.

    • usermod -aG sudo username
  84. userdel: Delete a user account and related files.

    • userdel username
  85. groupadd: Create a new group.

    • groupadd groupname
  86. groupdel: Delete a group.

    • groupdel groupname
  87. hostnamectl: Control the system hostname.

    • hostnamectl set-hostname newname
  88. locale: Get or set system locale and related settings.

    • locale -a
  89. date: Display or set system date and time.

    • date
  90. uptime: Tell how long the system has been running.

    • uptime
  91. who: Show who is logged on.

    • who
  92. w: Show who is logged on and what they are doing.

    • w
  93. last: Show listing of last logged in users.

    • last
  94. mount: Mount a filesystem.

    • mount /dev/sda1 /mnt
  95. umount: Unmount file systems.

    • umount /mnt
  96. reboot: Reboot the system.

    • reboot
  97. shutdown: Bring the system down.

    • shutdown -h now
  98. history: Show command history.

    • history
  99. alias: Create or remove aliases.

    • alias ll='ls -l'
  100. unalias: Remove alias definitions. - unalias ll