Centos7 初始化脚本
- #!bin/bash
- #author chenkan
- #this script for Centos7
- #Check the OS
- echo "Check the OS is right?"
- yum install redhat-lsb -y #基于最小化安装的centos 需安装lsb 下面要用到
- os=`uname -r | awk -F "." '{print $4}'`
- platform=`uname -i` #-i, 显示硬件平台名称
- if [ $os != el7 || $platform != x86-64]; then
- echo -e "\e[1;31m this script is only for 64bit el7 operation system! \e[0m"
- exit -1
- fi
- echo -e "\e[1;31m platform is ok! \e[0m"
- cat << EOF
- +==============================+
- | your system is Centos x86_64 |
- +==============================+
- EOF
- echo -e "\e[1;31m Check the OS FINSHED! \e[0m"
- sleep 1
- #version=`lsb_release -r -s|awk -F "." '{print $1}'` #此处可以判断版本号是不是7(利用-r -s进行筛选)
- :<<!
- version=`lsb_release -i -s | grep CentOS` #此处可显示系统名称,比上边好用一点
- if [ $version != "CentOS" ]; then
- echo -e "\e[1;31m this script is only for CentOS \e[0m!"
- exit 1
- fi
- echo -e "\e[1;31m system is right! \e[0m" #为了测试功能实现情况,用转义字符输出红色字符串
- !
- #Set the installation source of the system to 163.com
- #先将CentOS-Base.repo进行备份(备份到CentOS-Base.repo.backup)中,以后需要可以很快的改回来
- echo "Replace the yum source"
- mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
- cd /etc/yum.repos.d/
- wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
- #阿里源
- #wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
- yum makecache
- echo -e "\e[1;31m 2.Set the installation source of the system to 163.com FINSHED! \e[0m"
- sleep 1
- #Install EPEL source and RPMforge source
- #对于安装epel可以选择网易的源,我这边用的是阿里的源.而RPMforge,现在改名为RepoForge,用清华的源。
- echo "Install EPEL source and RPMforge source"
- rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
- rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
- rpm --import https://mirrors.tuna.tsinghua.edu.cn/repoforge/RPM-GPG-KEY.dag.txt
- cat >> /etc/yum.repos.d/rpmforge.repo << EOF #configuration file
- [rpmforge]
- name = RHEL $releasever - RPMforge.net - dag
- baseurl = https://mirrors.tuna.tsinghua.edu.cn/repoforge/redhat/el7/en/$basearch/rpmforge
- mirrorlist = http://mirrorlist.repoforge.org/el7/mirrors-rpmforge
- enabled = 1
- protect = 0
- gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
- gpgcheck = 1
- [rpmforge-extras]
- name = RHEL $releasever - RPMforge.net - extras
- baseurl = https://mirrors.tuna.tsinghua.edu.cn/repoforge/redhat/el7/en/$basearch/extras
- mirrorlist = http://mirrorlist.repoforge.org/el7/mirrors-rpmforge-extras
- enabled = 0
- protect = 0
- gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
- gpgcheck = 1
- [rpmforge-testing]
- name = RHEL $releasever - RPMforge.net - testing
- baseurl = https://mirrors.tuna.tsinghua.edu.cn/repoforge/redhat/el7/en/$basearch/testing
- mirrorlist = http://mirrorlist.repoforge.org/el7/mirrors-rpmforge-testing
- enabled = 0
- protect = 0
- gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
- gpgcheck = 1
- EOF
- yum repolist enabled #check the enabled
- echo -e "\e[1;31m Install EPEL source and RPMforge source FINSHED! \e[0m"
- sleep 1
- #Update software
- echo "update software"
- yum clean all #清除yum的缓存,yum安装的东西会储存在cache中,不清除很浪费。
- yum install kernel-devel kernel-headers && echo exclude=kernel* >> /etc/yum.conf #安装kernel-devel和kernel-headers,并且在更新系统时,禁止更新kernel 并将其重定向到 yum.conf
- yum -y update glibc\* #更新C语言库
- yum -y update yum\* rpm\* python\*
- echo -e "\e[1;31m Update software FINSHED! \e[0m"
- sleep 1
- #Set time to be synchronized
- yum -y install ntp # Network Time Protocol
- echo "*10*** /usr/sbin/ntpdate s1a.time.edu.cn > /dev/null 2>&1" >> /var/spool/cron/root #将同步时间设置为北邮,2->stderr,1->stdout,0->stdin,意思就是执行每天上午10点进行时间同步,如果出现错误就输出。
- service crond restart #重启crond。crond是crontab的守护进程。
- echo -e "\e[1;31m Set time to be synchronized FINSHED! \e[0m"
- sleep 1
- #这边提一下">"和">>"区别,">"定向输出到文件,如果文件不存在,就创建文件;如果文件存在,就将其清空再添加;">>"是将输出内容追加到目标文件中。如果文件不存在,就创建文件;如果文件存在,则将新的内容追加到那个文件的末尾,该文件中的原有内容不受影响
- #increase the number of files
- echo "ulimit -SHn 102400" >> /etc/rc.local #ulimit -a cat /etc/security/limits.conf 可查看
- cat >> /etc/security/limits.conf <<EOF
- * soft nofile 102400
- * hard nofile 102400
- * soft nproc 102400
- * hard nproc 102400
- EOF
- echo -e "\e[1;31m increase the number of files FINSHED! \e[0m"
- sleep 1
- #closed SELinux
- echo "close selinux"
- sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config #sed -i替换命令,前者替换后者。具体使用参考:http://man.linuxde.net/sed
- echo -e "\e[1;31m closed SELinux FINSHED! \e[0m"
- sleep 1
- #disable the GSSAPI disable DNS speed up the SSH
- sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
- sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config #禁止dns的反向解析
- service sshd restart
- echo -e "\e[1;31m disable the GSSAPI disable DNS speed up the SSH FINSHED! \e[0m"
- sleep 1
- #optimize kernel parameters
- echo "optimize kernel parameters"
- echo "#----optimize kernel parameters------" >> /etc/sysctl.conf
- echo "net.core.netdev_max_backlog = 32768" >> /etc/sysctl.conf
- echo "net.core.rmem_default = 8388608" >> /etc/sysctl.conf
- echo "net.core.rmem_max = 16777216" >> /etc/sysctl.conf
- echo "net.core.somaxconn = 32768" >> /etc/sysctl.conf
- echo "net.core.wmem_default = 8388608" >> /etc/sysctl.conf
- echo "net.core.wmem_max = 16777216" >> /etc/sysctl.conf
- echo "net.ipv4.ip_local_port_range = 5000 65000" >> /etc/sysctl.conf
- echo "net.ipv4.tcp_fin_timeout = 30" >> /etc/sysctl.conf
- echo "net.ipv4.tcp_keepalive_time = 300" >> /etc/sysctl.conf
- echo "net.ipv4.tcp_max_orphans = 3276800" >> /etc/sysctl.conf
- echo "net.ipv4.tcp_max_syn_backlog = 65536" >> /etc/sysctl.conf
- echo "net.ipv4.tcp_max_tw_buckets = 5000" >> /etc/sysctl.conf
- echo "net.ipv4.tcp_mem = 94500000 915000000 927000000" >> /etc/sysctl.conf
- echo "net.ipv4.tcp_syn_retries = 2" >> /etc/sysctl.conf
- echo "net.ipv4.tcp_synack_retries = 2" >> /etc/sysctl.conf
- echo "net.ipv4.tcp_syncookies = 1" >> /etc/sysctl.conf
- echo "net.ipv4.tcp_timestamps = 0" >> /etc/sysctl.conf
- echo "net.ipv4.tcp_tw_recycle = 1" >> /etc/sysctl.conf
- echo "net.ipv4.tcp_tw_reuse = 1" >> /etc/sysctl.conf
- /sbin/sysctl -p
- echo -e "\e[1;31m optimize kernel parameters FINSHED! \e[0m"
- sleep 1
- #adjust the key of the deleted character to backspace
- echo "adjust the key of the deleted character to backspace"
- echo 'stty erase ^H'>> /etc/profile #默认^?
- echo 'syntax on'>> /root/.vimrc
- echo -e "\e[1;31m adjust the key of the deleted character to backspace FINSHED! \e[0m"
- sleep 1
- #cancel database
- echo "cancel database"
- if [[ -e /etc/cron.daily.bak
- ]]; then
- rm -rf /etc/cron.daily.bak
- fi
- mkdir /etc/cron.daily.bak
- mv /etc/cron.daily/mlocate /etc/cron.daily.bak
- echo -e "\e[1;31m cancel database FINSHED! \e[0m"
- sleep 1
- #shut down unused services
- echo "shut down unused services"
- systemctl stop firewalld
- systemctl disable cups
- systemctl disable firewalld
- systemctl disable auditd.service
- systemctl disable irqbalance.service
- systemctl disable lvm2-monitor.service
- echo -e "\e[1;31m shut down unused services FINSHED! \e[0m"
- sleep 1
- #disable the ipv6
- echo "disable the ipv6"
- cat >> /etc/modprobe.d/ipv6.conf <<EOFI
- alias net-pf-10 off
- options ipv6 disable=1
- EOFI
- echo "NETWORKING_IPV6=off" >> /etc/sysconfig/network
- echo -e "\e[1;31m disable the ipv6 FINSHED! \e[0m"
- sleep 1

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Centos7最小化安装后 配置静态IP 和 主机名
Centos7最小化安装后 配置静态IP 和 主机名 (一) [root@masternetwork-scripts]#cd/etc/sysconfig/network-scripts [root@masternetwork-scripts]# [root@masternetwork-scripts]#dir ifcfg-ens160ifdown-bnepifdown-ipv6ifdown-pppifdown-Teamifupifup-ethifup-isdnifup-postifup-sitifup-tunnelnetwork-functions ifcfg-loifdown-ethifdown-isdnifdown-routesifdown-TeamPortifup-aliasesifup-ipppifup-plipifup-pppifup-Teamifup-wirelessnetwork-functions-ipv6 ifdownifdown-ipppifdown-postifdown-sitifdown-tunnelifup-bnepifup-ipv6ifup-plusbifu...
- 下一篇
linux下sar命令详解
sar(System Activity Reporter系统活动情况报告)是目前Linux上最为全面的系统性能分析工具之一,可以从多方面对系统的活动进行报告,包括:文件的读写情况、系统调用的使用情况、磁盘I/O、CPU效率、内存使用状况、进程活动及IPC有关的活动等。本文主要以CentOS6.3 x64系统为例,介绍sar命令。 sar命令常用格式 sar [options] [-A] [-o file] t [n] 其中: t为采样间隔,n为采样次数,默认值是1; -o file表示将命令结果以二进制格式存放在文件中,file 是文件名。 options 为命令行选项,sar命令常用选项如下: -A:所有报告的总和 -u:输出CPU使用情况的统计信息 -v:输出inode、文件和其他内核表的统计信息 -d:输出每一个块设备的活动信息 -r:输出内存和交换空间的统计信息 -b:显示I/O和传送速率的统计信息 -a:文件读写情况 -c:输出进程统计信息,每秒创建的进程数 -R:输出内存页面的统计信息 -y:终端设备活动情况 -w:输出系统交换活动信息 1. CPU资源监控 例如,每10秒...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- CentOS7设置SWAP分区,小内存服务器的救世主
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
- CentOS8编译安装MySQL8.0.19
- Hadoop3单机部署,实现最简伪集群
- SpringBoot2整合Redis,开启缓存,提高访问速度
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程
- Eclipse初始化配置,告别卡顿、闪退、编译时间过长
- CentOS7安装Docker,走上虚拟化容器引擎之路