#!/bin/bash

#检测是否为root用户
if [ $UID -ne ];then
echo "Must be root can do this."
exit
fi #检测网络
echo "检测网络中......"
/bin/ping www.baidu.com -c &>/dev/null
if [ $? -ne ];then
echo "现在网络无法通信,准备设置网络"
read -p 'pls enter your ip: ' IP
read -p 'pls enter your gateway: ' GW
read -p 'pls enter your netmask: ' NM
read -p 'pls enter your netcard: ' NC
echo "IPADDR=$IP" >> /etc/sysconfig/network-scripts/ifcfg-$NC
echo "NETMASK=$NM" >> /etc/sysconfig/network-scripts/ifcfg-$NC
echo "GATEWAY=$GW" >> /etc/sysconfig/network-scripts/ifcfg-$NC
echo "DNS1=114.114.114.114" >> /etc/sysconfig/network-scripts/ifcfg-$NC
echo "DNS2=8.8.8.8" >> /etc/sysconfig/network-scripts/ifcfg-$NC
sed -i 's/dhcp/static/g' /etc/sysconfig/network-scripts/ifcfg-$NC
sed -i 's/ONBOOT=no/ONBOOT=yes/g' /etc/sysconfig/network-scripts/ifcfg-$NC
/etc/init.d/network restart
echo -e "\033[031m network is configure ok.\033[0m"
else
echo -e "\033[031m network is ok.\033[0m"
fi #关闭 ctrl + alt + del
echo "关闭 ctrl + alt + del ......."
sed -i "s/ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/" /etc/inittab
sed -i 's/^id:5:initdefault:/id:3:initdefault:/' /etc/inittab #关闭ipv6
echo "关闭IPv6....."
echo "alias net-pf-10 off" >> /etc/modprobe.conf
echo "alias ipv6 off" >> /etc/modprobe.conf
/sbin/chkconfig --level ip6tables off
echo -e "\033[031m ipv6 is disabled.\033[0m" #关闭selinux
echo "关闭SElinux......"
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
echo -e "\033[31m selinux is disabled,if you need,you must reboot.\033[0m" #更新yum源
echo "备份yum源......"
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
sys_ver=`cat /etc/redhat-release |awk '{print $3}' | awk -F '.' '{print $1}'`
if [ $sys_ver -eq ];then
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum clean all
yum makecache
elif [ $sys_ver -eq ];then
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
elif [ $sys_ver -eq ];then
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
yum clean all
yum makecache
fi #安装基础库
echo "安装基础环境和库......"
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel nss_ldap openldap openldap-devel openldap-clients openldap-servers libxslt-devel libevent-devel ntp libtool-ltdl bison libtool vim-enhanced #设置时钟同步
echo "设置时钟同步......"
echo "*/5 * * * * root /usr/sbin/ntpdate time7.aliyun.com &>/dev/null" >> /etc/crontab #修改Bash提示符字符串
echo "改Bash提示符字符串......"
echo 'PS1="\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[36;40m\]\w\[\e[0m\]]\\$ "' >> ~/.bashrc
source .bashrc #修改文件打开数
echo "修改文件打开数......"
cat >> /etc/security/limits.conf <<EOF
* soft nproc
* hard nproc
* soft nofile
* hard nofile
EOF
echo "ulimit -SH 65535" >> /etc/rc.local #优化内核参数
echo "优化内核参数....."
sed -i 's/net.ipv4.tcp_syncookies.*$/net.ipv4.tcp_syncookies = 1/g' /etc/sysctl.conf
cat >> /etc/sysctl.conf << ENDF
net.ipv4.tcp_max_syn_backlog =
net.core.netdev_max_backlog =
net.core.somaxconn =
net.core.wmem_default =
net.core.rmem_default =
net.core.rmem_max =
net.core.wmem_max =
net.ipv4.tcp_timestamps =
net.ipv4.tcp_synack_retries =
net.ipv4.tcp_syn_retries =
net.ipv4.tcp_tw_recycle =
#net.ipv4.tcp_tw_len =
net.ipv4.tcp_tw_reuse =
net.ipv4.tcp_mem =
net.ipv4.tcp_max_orphans =
net.ipv4.ip_local_port_range =
ENDF
sysctl -p #优化ssh参数
echo "优化ssh....."
sed -i '/^#UseDNS/s/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
#sed -i 's/#PermitEmptyPasswords no/PermitEmptyPasswords no/g' /etc/ssh/sshd_config
/etc/init.d/sshd restart

如果复制过去后出现格式错误等,可以使用vim编辑,输入  :set fileformat=unix

centos系统初始化脚本的更多相关文章

  1. centos系统初始化流程及实现系统裁剪

    Linux系统的初始化流程: POST:ROM+RAM BIOS: Boot Sequence MBR: 446:bootloader 64: 分区表 2: 5A kernel文件:基本磁盘分区 /s ...

  2. centos 7 初始化脚本

    #!/bin/bash # 时间: 2018-11-21 # 作者: HuYuan # 描述: CentOS 7 初始化脚本 # 加载配置文件 if [ -n "${1}" ];t ...

  3. centos7 系统初始化脚本

    现在自己的本地虚拟机系统,直接安装的是centos7.2 mini版,安装完成发现好多东西都没有安装,所以写了一个简单的系统初始化脚本,让自己可以省一些力气,哈哈 人懒主要是. 下面贴出写的脚本,脚本 ...

  4. centos 系统初始化

    centos 系统初始化 #!/bin/bash # author cfwl create date of 2012-10-21 # blog http://cfwlxf.blog.51cto.com ...

  5. Centos7系统初始化脚本

    前言: 因公司业务增加,陆续新增服务器,时不时的来几台,手动地一台台对服务器初始化操作感觉太麻烦. 于是乎,根据初始化需求整合了一个初始化脚本,实现批量脚本初始化操作. 说明: 本脚本根据自身需求编写 ...

  6. centos6、7系统初始化脚本

    #!/bin/bash # #******************************************************************** #encoding -*-utf ...

  7. centos系统初始化配置

    .改主机名: sed -i 's#HOSTNAME=.*#HOSTNAME=u05mix06.yaya.corp#g' /etc/sysconfig/network && hostna ...

  8. centos虚拟机初始化脚本

    功能 修改主机名为node. 网卡开机启动并设置ip为静态18.8 更新yum源为国内yum源,并安装vim lrzsz wget man ntpdate软件. 关闭iptables selinux, ...

  9. CentOS系统初始化---不断更新中

    注意EOF不能有空格tab键 #get os version release=$(rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides ...

随机推荐

  1. Windows Boot Manager改成中文菜单

    用管理员身份运行"命令提示符",依次执行以下命令 bcdedit /deletevalue {bootmgr} device bcdedit /deletevalue {bootm ...

  2. A1083. List Grades

    Given a list of N student records with name, ID and grade. You are supposed to sort the records with ...

  3. mysql自定义函数与过程中写法的注意事项

    BEGIN #Routine body goes here... /* update szzx_goods_common set gc_id=i where gc_name=(SELECT gc_na ...

  4. 求解100以内的所有素数(问题来自PythonTip)

    求解100以内的所有素数 (AC/Submit)Ratio(4615|22542)20.47% 描述: 输出100以内的所有素数,素数之间以一个空格区分(注意,最后一个数字之后不能有空格). a=[2 ...

  5. jQuery层级选择器

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. WCF开发实战系列五:创建WCF客户端程序

    WCF开发实战系列五:创建WCF客户端程序 (原创:灰灰虫的家http://hi.baidu.com/grayworm) 在前面的三篇文章中我们分别介绍了WCF服务的三种载体:IIS.Self-Hos ...

  7. XMind 入门教程

    选自:http://www.xmindchina.net/ XMind 是一款非常实用的商业思维导图软件,应用全球最先进的Eclipse RCP 软件架构,全力打造易用.高效的可视化思维软件.对于新手 ...

  8. 编写前程贷投标loadrunner脚本及总结

    1.完成前程贷的(登录,投标) 2.所有的返回信息都用关联函数(web_reg_save_param_ex)进行关联 3.对返回信息用(strcmp)函数进行if判断 4.总结(web_reg_sav ...

  9. GO语言的进阶之路-go的程序结构以及包简介

    GO语言的进阶之路-go的程序结构以及包简介 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.编辑,编译和运行 A,编辑 Go程序使用UTF-8编码的纯Unicode文本编写.大 ...

  10. python自动化运维之路~DAY7

    python自动化运维之路~DAY7 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.客户端/服务器架构 C/S 架构是一种典型的两层架构,其全称是Client/Server,即 ...