본문 바로가기

Tech/Linux

CentOS 센트OS - 파라미터 최적화 스크립트

네이버 공유하기
728x90

CentOS 센트OS - 파라미터 최적화 스크립트


첨부파일 참조하여 주세요 ~ 

check.centos.sh


root 루트로 실행해야 합니다.


스왑이 0 일때 (스왑 파일이 없는 경우) echo 로 출력되는 부분을 그대로 한줄씩 실행하면 됩니다.


대신 메모리가 1기가라면

dd if=/dev/zero of=/data/swapfile bs=1M count=1024


8기가라면

dd if=/dev/zero of=/data/swapfile bs=1M count=8192


이렇게 실행하시면 됩니다.


#!/bin/bash

#echo -e "32768\t61000" > /proc/sys/net/ipv4/ip_local_port_range
#$ sysctl -w net.ipv4.tcp_wmem="253952 253952 16777216"
#$ sysctl fs.file-max
#$ sysctl fs.file-nr 

echo "----------------------------------"
check_value=`getenforce`
echo "GetEnforce : ${check_value}"
echo "----------------------------------"
echo -e "Parameter\tNow\tRecommand"
echo "----------------------------------"

# Recommand value = 0
recom_value="0"
for check_param in net.ipv4.tcp_timestamps net.ipv4.conf.all.accept_source_route net.ipv4.ip_forward net.ipv4.conf.all.accept_redirects net.ipv4.tcp_tw_reuse
do
        check_param2=${check_param%*.*}
        check_param3=`echo ${check_param} | sed -e "s/${check_param2}//" | cut -c 2-`
        check_value=`sysctl -n ${check_param}`

        if [ "$check_value" -eq "${recom_value}" ]
        then 
                echo -e "${check_param3}\t${check_value}\t${recom_value}\t OK"
        else
                echo -e "${check_param3}\t${check_value}\t${recom_value}"
                read -s -n1 -p "    ${check_param3} ${check_value}->${recom_value} : Submit Now? (y/n) : " submit_yn
                if [ "$submit_yn" == "y" ]
                then
                        echo -e "\tsysctl -w ${check_param}=${recom_value}"
                        echo "$check_param = \"${recom_value}\"" >> /etc/sysctl.conf 
                fi
                echo ${submit_yn}
        fi
done

# Recommand value = 1
recom_value="1"
for check_param in net.ipv4.icmp_echo_ignore_broadcasts net.ipv4.conf.all.log_martians net.ipv4.tcp_syncookies net.ipv4.tcp_window_scaling 
do
        check_param2=${check_param%*.*}
        check_param3=`echo ${check_param} | sed -e "s/${check_param2}//" | cut -c 2-`
        check_value=`sysctl -n ${check_param}`

        if [ "$check_value" -eq "${recom_value}" ]
        then 
                echo -e "${check_param3}\t${check_value}\t${recom_value}\t OK"
        else
                echo -e "${check_param3}\t${check_value}\t${recom_value}"
                read -s -n1 -p "    ${check_param3} ${check_value}->${recom_value} : Submit Now? (y/n) : " submit_yn
                if [ "$submit_yn" == "y" ]
                then
                        echo -e "\tsysctl -w ${check_param}=${recom_value}"
                        echo "$check_param = \"${recom_value}\"" >> /etc/sysctl.conf 
                fi
                echo ${submit_yn}
        fi
done


check_value=`sysctl -n .net.ipv4.ip_local_port_range`
echo -e "Port.Range\t${check_value}\t1024\t65535"
check_value=`sysctl -n .net.ipv4.tcp_max_syn_backlog`
echo -e "MAX.BackLog\t${check_value}\t1024"

check_value=`sysctl -n net.ipv4.tcp_max_tw_buckets`
echo -e "TcpTW.Buckets\t${check_value}\t65536"

# check : ulimit -a / sysctl -n fs.file-nr
check_value=`sysctl -n fs.file-max`
echo -e "FS.FileMax\t${check_value}\t77052"
check_value=`sysctl -n net.core.netdev_max_backlog`
echo -e "NetdevMxBackLog\t${check_value}\t30000"
check_value=`sysctl -n net.core.somaxconn`
echo -e "MaxConnections\t${check_value}\t1024"

echo "----------------------------------------------------------------------------"
free -m
echo "----------------------------------------------------------------------------"
swap_size=`free -m | grep -i swap | awk '{print $2}'`
if [ "$swap_size" -eq "0" ]
then
        echo -e "----------------------------------------------------------------------------"
        echo -e "\tdd if=/dev/zero of=/data/swapfile bs=1M count=[1024|2048|8192]"
        echo -e "\tmkswap /data/swapfile"
        echo -e "\tswapon /data/swapfile"
        echo -e "\tchmod 600 swapfile"
        echo -e "\t/data/swapfile swap swap defaults 0 0 >> /etc/fstab"
        echo -e "----------------------------------------------------------------------------"
fi

ulimit -a
echo "----------------------------------------------------------------------------"

echo "sysctl -p"
sysctl -p


sysctl 이라는 명령어로 수정합니다.

수정할때에는 sysctl -w [파라미터] 로 수정하고, 적용은 sysctl -p 하면 됩니다.


반응형
네이버 공유하기


* 쿠팡 파트너스 활동을 통해 일정액의 수수료를 제공받을 수 있습니다.