Linux最小化安装后优化

1.配置网卡

#!/bin/bash
#修改网卡名为eth0、eth1形式
sed -i "/linux16.*$/s//& net.ifnames=0 biosdevname=0/g" /boot/grub2/grub.cfg
#删除原网卡名对应配置文件
rm -rf /etc/sysconfig/network-scripts/ifcfg-ens* 

#为eth0配置静态IP
echo -n "Enter the IPaddress:"
read IPaddress
echo -n "Enter the NETMASK:"
read NETMASK
echo -n "Enter the GATEWAY:"
read GATEWAY
echo -n "Enter the DNS1:"
read DNS1
nmcli  connection  add con-name eth0 ifname eth0  connection.autoconnect yes \
ipv4.method  manual ipv4.addresses $IPaddress/$NETMASK \
ipv4.gateway $GATEWAY ipv4.dns $DNS1  type ethernet 

#设置主机名
echo -n "Enter the hostname:"
read hostname
hostnamectl set-hostname $hostname
#把该主机域名写入hosts文件
echo "$IPaddress  $hostname">>/etc/hosts

reboot

2.基础环境

配置网卡并重启后,服务器已能联通公网,进行其他环境设置

#!/bin/bash

#修改普通用户进程数限制(根据需要修改)
sed -i "s/4096/65535/g" /etc/security/limits.d/20-nproc.conf
#修改systemd service进程数限制(根据需要修改)
sed -i "s/#DefaultLimitNPROC=/DefaultLimitNPROC=65535/g" /etc/systemd/system.conf
#系统总句进程数默认足够(有需要可修改)
#echo "kernel.pid_max = 655350" >> /etc/sysctl.conf

#修改单进程句柄数限制
#修改systemd service的单进程句柄数(根据需要修改)
sed -i "s/#DefaultLimitNOFILE=/DefaultLimitNOFILE=65535/g" /etc/systemd/system.conf
#修改普通用户单进程句柄数限制(根据需要修改)
echo "*             soft    nofile          65535">>/etc/security/limits.conf
echo "*             hard    nofile          65535">>/etc/security/limits.conf
#修改系统总句柄数限制(根据需要修改)
echo  655350 > /proc/sys/fs/file-max

#修改每个端口最大监听队列的长度(程序负载越大,需修改该数值越大,默认128)
echo "net.core.somaxconn = 5120">>/etc/sysctl.d/99-sysctl.conf
#最大tcp半链接数,调大可防synflood攻击,默认1024
echo "net.ipv4.tcp_max_syn_backlog = 10240">>/etc/sysctl.d/99-sysctl.conf

#关闭Selinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config


#让历史命令显示时间
echo "export HISTTIMEFORMAT=\"[%Y.%m.%d %H:%M:%S]\"">>/etc/profile
echo "export HISTSIZE=5000">>/etc/profile
echo "export HISTIGNORE=\"ls:ls -lrt:ls -al:clear:pwd\"">>/etc/profile

#设置时区为上海
rm -rf /etc/localtime 
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 

#**********修改yum源**************
yum install -y wget
#添加epel源
yum -y install epel-release
#备份原yum仓库
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
#添加163源
cd /etc/yum.repos.d/
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
#重建缓存
yum clean all
yum makecache

#更新系统
yum -y update

#时间同步
yum -y install ntp  ntpdate
systemctl enable ntpd
systemctl start ntpd


#安装RPM增量包套件,在更新rpm包时,可以只更新增量内容与旧rpm包合成新包使用,可以减少下载量
yum install -y deltarpm
#其他常用RPM包:GCC编译器、perl库、zlib库、OpenSSL开发库、vim编辑器、命令补全工具
yum install -y gcc  gcc-c++  pcre  pcre-devel  zlib zlib-devel  openssl openssl-devel vim bash-completion

reboot

 

你可能感兴趣的:(Linux)