Centos 7 시스템 초기 화 스 크 립 트
앞에서 말 했 듯 이 회사 업무 가 증가 하여 서버 가 계속 추 가 됩 니 다. 가끔 몇 대 씩 오 면 수 동 으로 한 대 씩 서버 초기 화 작업 에 너무 번 거 롭 습 니 다.따라서 초기 화 수요 에 따라 초기 화 스 크 립 트 를 통합 하여 대량 스 크 립 트 초기 화 작업 을 실현 합 니 다.
설명: 이 스 크 립 트 는 자신의 요구 에 따라 작성 되 었 으 며, Centos 7 서버 의 기본 초기 화 절 차 를 통합 하 였 습 니 다.
그 중 에는 다음 과 같은 기초 최적화 내용 이 포함 되 어 있다. 1) SELinux 종료;2) Firewalld 종료;3) Bash 환경 수정;4) Openfile 시스템 의 최대 파일 수 설정 열기;5) 시스템 커 널 파라미터 최적화 설정;6) 호스트 이름 변경;7) 역사 기록 설정;8) 개성 화 된 설정 등.메모: A) 스 크 립 트 가 실행 되면 서버 를 자동 으로 다시 시작 합 니 다.B) 스 크 립 트 를 실행 하기 전에/etc/hosts 에 대응 하 는 해석 을 설정 해 야 합 니 다. 예 를 들 어 10.10.10 kazihuo 내용 을 hosts 파일 에 추가 하고 스 크 립 트 를 실행 한 후 서버 10.10.10.10.10 은 자동 으로 Hostname 호스트 이름 을 "jmpserver"로 설정 합 니 다.C)/tmp/sysctl. conf 파일 이 존재 하 는 지 확인 합 니 다. 설 정 된 Kernel 커 널 최적화 매개 변수 파일 을/tmp 디 렉 터 리 에 배치 하고 스 크 립 트 를 실행 하면 최적화 매개 변 수 는 서버 에 자동 으로 설 정 됩 니 다.최적화 파일 이 없 으 면 마지막 함수 에 Kernel 을 주석 하면 됩 니 다.
내용: 스 크 립 트 내용 은 다음 과 같 습 니 다: [root@jumpserver ~]# cat/shell/init.sh
在这里插入代码片
```#!/bin/bash
#====================================================
# Author: Mr.song
# Blog: https://blog.csdn.net/qq_46229380/article/details/108982089
# Create Date: 2020-10-9
# Description: It works for system initalization.
#====================================================
#State:Plese confirm the files of /etc/hosts and /tmp/sysctl.conf before using the script
[ -f /etc/init.d/functions ] && source /etc/init.d/functions
# Defined result function
function Msg(){
if [ $? -eq 0 ];then
action "$1" /bin/true
else
action "$1" /bin/false
fi
}
# Defined close selinux function
function Selinux(){
[ -f /etc/selinux/config ] && {
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
Msg "Close selinux"
}
}
# Defined close firewalld function
function Firewalld(){
systemctl stop firewalld.service
systemctl disable firewalld.service >/dev/null 2>&1
Msg "Close firewalld"
}
# Defined bashrc function
function Bashrc(){
sed -i 's/\\h \\W/\\h \\w/g' /etc/bashrc
Msg "Bashrc"
}
# Defined open files function for Centos6.
function Openfile6(){
if [ `egrep "^\*" /etc/security/limits.conf|wc -l` -eq 0 ];then
echo '* - nofile 65535' >> /etc/security/limits.conf
ulimit -SHn 65535
Msg "Open files"
fi
}
# Defined open files function for Centos7.
function Openfile7(){
if [ `egrep "^De" /etc/systemd/system.conf|wc -l` -eq 0 ];then
echo 'DefaultLimitCORE=infinity' >> /etc/systemd/system.conf
echo 'DefaultLimitNOFILE=100000' >> /etc/systemd/system.conf
echo 'DefaultLimitNPROC=100000' >> /etc/systemd/system.conf
ulimit -SHn 100000
Msg "Open files"
fi
}
# Defined kernel paramters function
function Kernel(){
if [ -f /tmp/sysctl.conf ];then
/usr/bin/\cp /etc/sysctl.conf /etc/sysctl.conf.$RANDOM
/usr/bin/\cp /tmp/sysctl.conf /etc/
sysctl -p >/dev/null 2>&1
Msg "kernel paramters"
else
echo "/tmp/sysctl.conf is not exist"
fi
}
# Defined hostname function
function Hostname(){
ip=`/usr/sbin/ip addr|grep brd|awk 'NR==3{print $2}'|awk -F "/" '{print $1}'`
name=`grep -w "$ip" /etc/hosts|awk '{print $2}'`
if [ -z $name ];then
sleep 1
else
echo $name > /etc/hostname
hostnamectl set-hostname $name
Msg "Hostname"
fi
}
# Defined device function
function Device(){
/usr/sbin/ip addr|grep ens192 >/dev/null
RETVAL=$?
if [ $RETVAL -ne 0 ];then
/usr/bin/mv /etc/sysconfig/network-scripts/ifcfg-e* /etc/sysconfig/network-scripts/ifcfg-ens192 >/dev/null 2>&1
sed -i 's/quiet/quiet net.ifnames=0 biosdevname=0/g' /etc/default/grub
sed -i 's/^DEVICE/#DEVICE/g' /etc/sysconfig/network-scripts/ifcfg-e*
sed -i '1i DEVICE=ens192' /etc/sysconfig/network-scripts/ifcfg-e*
/usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg >/dev/null 2>&1
Msg "Device--[WARNING]effecting after reboot~~~"
else
echo "the name of eths is exist"
fi
}
# History collect
function History(){
cat >>/etc/profile.d/history.sh <<EOF
#history
USER=\`whoami\`
USER_IP=\`who -u am i 2>/dev/null|egrep -o "([0-9]{1,3}\\.){3}[0-9]{1,3}"\`
if [ "\$USER_IP" = "" ]; then
USER_IP=\`hostname\`
fi
if [ ! -d /var/log/history ]; then
mkdir /var/log/history
chmod 777 /var/log/history
fi
if [ ! -d /var/log/history/\${
LOGNAME} ]; then
mkdir /var/log/history/\${
LOGNAME}
chmod 300 /var/log/history/\${
LOGNAME}
fi
export HISTSIZE=4096
DT=\`date +"%Y%m%d_%H:%M:%S"\`
export HISTFILE="/var/log/history/\${LOGNAME}/\${USER}@\${USER_IP}_\$DT"
chmod 600 /var/log/history/\${LOGNAME}/*history* 2>/dev/null
EOF
Msg "History collect"
}
# Defined the hobby.
function Hobby(){
mkdir -p /{
luomurui,luomurui-bak}/{
scr,pkg,test,info}
}
# Defined wait function
function Wait(){
echo ""
echo -n -e "\033[31mTHE SYSTEM IS REBOOTING\033[0m"
for ((i=0;i<3;i++))
do
echo -n "~~ "
sleep 1
done
echo
}
# Defined main function
function main(){
Selinux
Firewalld
Bashrc
#Openfile6
Openfile7
Kernel
Hostname
Device
History
Hobby
Wait
reboot
}
main
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
용감한 바로 가기 및 우분투 응용 프로그램안녕하세요 여러분, 이 기사에서는 모든 사이트에서 pwa를 생성하고 실행기 응용 프로그램으로 추가하는 방법을 설명하고 싶습니다. 일부 웹사이트는 PWA로 설치를 허용하지 않지만 유사한 애플리케이션을 원합니다. 1. ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.