Memory – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Wed, 21 Dec 2022 01:38:10 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 How to Change Redis Max Memory https://tecadmin.net/limit-redis-max-memory/ https://tecadmin.net/limit-redis-max-memory/#respond Wed, 21 Dec 2022 01:38:10 +0000 https://tecadmin.net/?p=22957 To configure the maximum amount of memory that Redis will use, you can use the `maxmemory` directive in the Redis configuration file (`redis.conf`). This directive takes an integer value, representing the maximum number of bytes that Redis will use to store data in memory. For example, to set the maximum memory to `1GB`, (or 1024*1024*1024 [...]

The post How to Change Redis Max Memory appeared first on TecAdmin.

]]>
To configure the maximum amount of memory that Redis will use, you can use the `maxmemory` directive in the Redis configuration file (`redis.conf`). This directive takes an integer value, representing the maximum number of bytes that Redis will use to store data in memory.

For example, to set the maximum memory to `1GB`, (or 1024*1024*1024 bytes) you can use the following configuration:

maxmemory 1073741824

You can also specify a policy for how Redis should handle the situation when the maximum memory limit is reached. This is done using the `maxmemory-policy` directive, which can take one of the following values:

  • noeviction: Redis will return an error when the maximum memory limit is reached and a new key needs to be added.
  • allkeys-lru: Redis will remove the least recently used keys in order to make space for new keys.
  • volatile-lru: Redis will remove the least recently used keys among keys with an expire set in order to make space for new keys.
  • allkeys-random: Redis will randomly select keys to remove in order to make space for new keys.
  • volatile-random: Redis will randomly select keys with an expire set to remove in order to make space for new keys.
  • volatile-ttl: Redis will remove keys with the shortest time to live in order to make space for new keys.

For example, to set the `maxmemory-policy` to `allkeys-lru`, you can use the following configuration:

maxmemory-policy allkeys-lru

Note that the maxmemory and maxmemory-policy directives must be set in the Redis configuration file (redis.conf) and cannot be set using the CONFIG SET command at runtime. You will need to restart Redis for the changes to take effect.

It’s also worth noting that Redis will automatically try to free memory when it is running out of available memory, by releasing memory used by the least recently used keys. However, this process is limited by the maxmemory-samples directive, which determines the number of keys that Redis will sample in order to determine the keys to be removed. By default, this value is set to 3, so Redis will only sample 3 keys in order to determine the keys to be removed. You can adjust this value if needed by using the maxmemory-samples directive in the Redis configuration file.

The post How to Change Redis Max Memory appeared first on TecAdmin.

]]>
https://tecadmin.net/limit-redis-max-memory/feed/ 0
How To Add Swap Space on Debian 11 https://tecadmin.net/how-to-add-swap-space-on-debian-11/ https://tecadmin.net/how-to-add-swap-space-on-debian-11/#respond Sat, 11 Sep 2021 05:16:47 +0000 https://tecadmin.net/?p=27715 Swap memory is a location on hard disk to be used as Memory by the operating system. When the operating systems detects that main memory is low and required more RAM to run applications properly it check for swap space and transfer files there. In general terms, swap is a part of the hard disk [...]

The post How To Add Swap Space on Debian 11 appeared first on TecAdmin.

]]>
Swap memory is a location on hard disk to be used as Memory by the operating system. When the operating systems detects that main memory is low and required more RAM to run applications properly it check for swap space and transfer files there. In general terms, swap is a part of the hard disk used as RAM on the system.

This tutorial will help you to Add Swap on Debian 11 Bullseye Linux system.

How to Create Swap in Debian 11

Use the below steps to create and enable Swap memory on your Debian 11 system via command line.

  1. First of all, Check that no Swap memory is enabled on your system. You can see the swap memory details by running the following commands.
    sudo swapon -s 
    free -m 
    

    Check Available Swap Memory
    Check Available Swap Memory
  2. Now, create a file to use as swap in your system system. Make sure you have enough free disk available to create new file. Also keep the swap just up to 2x of the memory on your system.

    My Debian system have 2GB of main memory. So we will create a swapfile of 4GB in size.

    sudo fallocate -l 4G /swapfile 
    chmod 600 /swapfile 
    
  3. Now use the mkswap command to convert file to use for swap memory.
    sudo mkswap /swapfile 
    
  4. Then activate the swap memory on your system.
    sudo swapon /swapfile 
    
  5. You have successfully added swap memory to your system. Execute one of the below commands to view current active swap memory on your system:
    sudo swapon -s 
    free -m 
    

    add swap on ubuntu
    Swap is Added to your System

Make Swap Permanent

After running above commands, Swap memory is added to your system and operating system can use when required. But after reboot of system swap will deactivate again.

You can make it permanent by appending the following entry in /etc/fstab file. Edit fstab file in editor:

vim /etc/fstab 

and add below entry to end of file:

/swapfile   none    swap    sw    0   0

Add swap in fatab

Save file and close. Now Swap memory will remain activate after system reboots.

Configure Swappiness

Now change the swappiness kernel parameter as per your requirement. It tells the system how often system utilize this swap area.

Edit /etc/sysctl.conf file:

sudo vim /etc/sysctl.conf 

append following configuration to end of file

vm.swappiness=10

Now reload the sysctl configuration file

sudo sysctl -p 

Conclusion

Now the operating system can use swap memory in case of low physical memory. In this tutorial, you have learned to create and enable Swap memory on Debian 11 Linux system.

The post How To Add Swap Space on Debian 11 appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-add-swap-space-on-debian-11/feed/ 0
How to Add Swap Space In Ubuntu 22.04, 20.04 https://tecadmin.net/how-to-add-swap-memory-on-ubuntu-20-04/ https://tecadmin.net/how-to-add-swap-memory-on-ubuntu-20-04/#respond Fri, 29 May 2020 15:22:01 +0000 https://tecadmin.net/?p=21715 Virtual memory is physical memory that has been marked as available for new data. This is used to increase the amount of data that can be stored in a computer system by temporarily storing data on a storage device, such as a hard drive, rather than in physical memory. For example, if a computer has [...]

The post How to Add Swap Space In Ubuntu 22.04, 20.04 appeared first on TecAdmin.

]]>
Virtual memory is physical memory that has been marked as available for new data. This is used to increase the amount of data that can be stored in a computer system by temporarily storing data on a storage device, such as a hard drive, rather than in physical memory. For example, if a computer has 4 GB of physical memory and the computer is running three applications that each require 2 GB of memory, the computer will not be able to run all three applications at the same time. However, if the computer has 8 GB of virtual memory, it can divide the 8 GB of virtual memory into 4 GB for each application and 2 GB will remain as free physical memory. There is just one very good reason to add a swap on CentOS. And that’s when you’ve run out of physical memory and can’t service any new requests. When this happens, the OS swaps out the least recently used (LRU) processes and pages their data to the disk. With enough swap space, you can avoid reaching this situation.

This article will help you to create swap space on your ubuntu system after installation.

How to Add Swap in Ubuntu

Follow the below steps to create and enable Swap memory on your Ubuntu system.

1. Check Current Swap

Before working make sure that the system has already swap enabled. If there is no swap, you will get the output header only.

sudo swapon -s 

check swap ubuntu

2. Create Swap File

Let’s create a file to use for swapping in the system of the required size. Before making a file make sure you have enough free space on the disk. Generally, it recommends that the swap should be equal to double of installed physical memory.

My Digital Ocean droplet has 2GB of memory. So creating the swapfile of 4GB in size.

sudo fallocate -l 4G /swapfile 
chmod 600 /swapfile 

Then, make it to swap format and activate it on your system by running the following commands:

sudo mkswap /swapfile 
sudo swapon /swapfile 

3. Make Swap Permanent

After running the above commands, Swap memory is added to your system and the operating system can use it when required. But after a reboot of the system swap will deactivate again.

You can make it permanent by appending the following entry in /etc/fstab file. Edit /etc/fstab file in the editor:

sudo vim /etc/fstab 

Append the below entry to the end of the file:

/swapfile   none    swap    sw    0   0

Add swap in fatab

Save the file and close. Now Swap memory will remain activated after the system reboots.

4. Check System Swap Memory

You have successfully added swap memory to your system. Execute one of the below commands to view the current active swap memory on your system:

sudo swapon -s 
free -m 

add swap on ubuntu

5. Update Swappiness Parameter

Now change the swappiness kernel parameter as per your requirement. It tells the system how often the system utilizes this swap area.

Edit /etc/sysctl.conf file:

sudo vim /etc/sysctl.conf 

Append the following configuration to the end of the file

vm.swappiness=10

Now reload the sysctl configuration file

sudo sysctl -p 

Conclusion

When a system runs out of memory, the operating system will begin to swap or page out memory pages to persistent storage such as a disk drive. When you have more free disk space, you can add additional swap space so your OS has an additional location to store temporary data when necessary. In this tutorial, you have learned to add Swap space on the Ubuntu systems.

The post How to Add Swap Space In Ubuntu 22.04, 20.04 appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-add-swap-memory-on-ubuntu-20-04/feed/ 0
How To Add Swap Space on Debian 10 https://tecadmin.net/create-swap-in-debian-10/ https://tecadmin.net/create-swap-in-debian-10/#comments Fri, 29 May 2020 15:20:09 +0000 https://tecadmin.net/?p=21724 Swap memory is a location on harddisk is used as Memory by the operating system. When the operating systems detects that main memory is getting full and required more RAM to run applications properly it check for swap space and transfer files there. In general terms, swap is a part of the hard disk used [...]

The post How To Add Swap Space on Debian 10 appeared first on TecAdmin.

]]>
Swap memory is a location on harddisk is used as Memory by the operating system. When the operating systems detects that main memory is getting full and required more RAM to run applications properly it check for swap space and transfer files there. In general terms, swap is a part of the hard disk used as RAM on the system.

This tutorial will help you to ADD Swap memory on Debian 10 Buster Linux system.

Add Swap in Debian 10

Use the below steps to create and enable Swap memory on your Debian system via command line.

1. Check Current Swap

First of all, Make sure your system have no Swap memory configured on your system. You can check if by running one of the below commands.

sudo swapon -s
free -m

check swap Debian 10

2. Create Swap file on Debian

Lets create a file to use for swap in system of required size. Before making file make sure you have enough free space on disk. Generally, it recommends that swap should be equal to double of installed physical memory.

My Debian system have 2GB of main memory. So we will create a swapfile of 4GB in size.

sudo fallocate -l 4G /swapfile
chmod 600 /swapfile

The, make it to swap format and activate on your system by running following commands:

sudo mkswap /swapfile
sudo swapon /swapfile

3. Make Swap Permanent

After running above commands, Swap memory is added to your system and operating system can use when required. But after reboot of system swap will deactivate again.

You can make it permanent by appending the following entry in /etc/fstab file. Edit fstab file in editor:

vim /etc/fstab

and add below entry to end of file:

/swapfile   none    swap    sw    0   0

Add swap in fatab

Save file and close. Now Swap memory will remain activate after system reboots.

4. Verify Swap Memory

You have successfully added swap memory to your system. Execute one of the below commands to view current active swap memory on your system:

sudo swapon -s
free -m

add swap on Debian

5. Update Swappiness Parameter

Now change the swappiness kernel parameter as per your requirement. It tells the system how often system utilize this swap area.

Edit /etc/sysctl.conf file:

sudo vim /etc/sysctl.conf

append following configuration to end of file

vm.swappiness=10

Now reload the sysctl configuration file

sudo sysctl -p

Conclusion

In this tutorial, you have learned to create and enable Swap memory on Debian system.

The post How To Add Swap Space on Debian 10 appeared first on TecAdmin.

]]>
https://tecadmin.net/create-swap-in-debian-10/feed/ 2
How to Monitor Memory and Disk Metrics for Amazon EC2 Linux Instance https://tecadmin.net/monitor-memory-disk-metrics-ec2-linux/ https://tecadmin.net/monitor-memory-disk-metrics-ec2-linux/#comments Mon, 31 Jul 2017 11:12:09 +0000 https://tecadmin.net/?p=13300 Introduction AWS CloudWatch provides most of the monitoring Metrics by default. But it doesn’t have any metrics for memory utilization details and Disk space uses. So if you want to monitor the memory on your system or monitor free disk space using CloudWatch. Then first you need to add these metrics to your account using [...]

The post How to Monitor Memory and Disk Metrics for Amazon EC2 Linux Instance appeared first on TecAdmin.

]]>
Introduction

AWS CloudWatch provides most of the monitoring Metrics by default. But it doesn’t have any metrics for memory utilization details and Disk space uses. So if you want to monitor the memory on your system or monitor free disk space using CloudWatch. Then first you need to add these metrics to your account using custom scripts.

This article will help you to monitor EC2 Linux instance memory and disk metrics with AWS CloudWatch. Remember this will not work on any Linux machine outside the EC2 network.

Prerequsiteis

For this tutorial, you will use the Perl scripts provided by AWS team, These scripts have some dependencies. You can use the following commands to install these dependencies as per your operating systems.

Redhat Based Systems:

sudo yum install perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA
sudo yum install zip unzip

Debian Based Systems:

sudo apt-get update
sudo apt-get install unzip libwww-perl libdatetime-perl

SUSE Linux Enterprise Server

sudo zypper install perl-Switch perl-DateTime
sudo zypper install –y "perl(LWP::Protocol::https)"

Download and Configure Script

The AWS official team provides CloudWatch monitoring scripts. You can simply download the scripts and configure on your system. Use the following command to download scripts and extract on your system.

cd /opt
wget  http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip
unzip CloudWatchMonitoringScripts-1.2.1.zip

Now create credentails file with coping template file.

cd /opt/aws-scripts-mon
cp awscreds.template awscreds.conf

Now, You need to add AWSAccessKeyId and AWSSecretKey of your AWS account. This will verify account ownership for the script. If you don’t have, you can create keys in your account under Users >> Security credentials section.

Test and Schedule Scripts

At this point, your setup is complete. Let’s use the following command to verify the connectivity between script and your AWS account.

./mon-put-instance-data.pl --mem-util --verify --verbose

The output will be something like below on successful verification.

Verification completed successfully. No actual metrics sent to CloudWatch.

As verification has been successfully completed. You can add the script to crontab to run on a regular interval to send data to your ec2 account. Edit crontab and add the following command to run on every 5 minutes.

*/5 * * * * /opt/aws-scripts-mon/mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --disk-space-util --disk-path=/ --from-cron

View Metrics in CloudWatch

You should wait for some time after adding crontab. So it can collect some data to view in metrics graph. After some time

>> Login AWS Dashboard
>> Go to CloudWatch Service
>> Click on Browse Metrics button
>> Select Linux System under Custom Namespaces.

Now, select any metrics to view data in Graph as shown in below screenshot.

Monitor Memory and Disk Metrics EC2

Find Utilization Report Command Line

You can also find the resouces utilization statistics for the last 24 hours. Use the following command to get details.

./mon-get-instance-stats.pl --recent-hours=24

The output will be something like below:

Instance i-xxxxxxxxxxxxxx statistics for the last 12 hours.

CPU Utilization
    Average: 0.05%, Minimum: 0.03%, Maximum: 1.56%

Memory Utilization
    Average: 10.63%, Minimum: 10.62%, Maximum: 10.63%

Swap Utilization
    Average: N/A, Minimum: N/A, Maximum: N/A

Disk Space Utilization for /dev/xvda1 mounted on /
    Average: 6.65%, Minimum: 6.65%, Maximum: 6.65%

The post How to Monitor Memory and Disk Metrics for Amazon EC2 Linux Instance appeared first on TecAdmin.

]]>
https://tecadmin.net/monitor-memory-disk-metrics-ec2-linux/feed/ 4