Centos7 新建server的优化脚本--不适用于所有人
#!/bin/bash
#optimization script for Centos7
echo " "
echo "|-------------------------------------------------|"
echo "| *****linux系统优化***** |"
echo "|-------------------------------------------------|"
echo "| 1.配置内网yum源 |"
echo "| 2.服务启动项优化 |"
echo "| 3.SNMP服务配置 |"
echo "| 4.修改网卡为eth0 |"
echo "| 5.单ip配置 |"
echo "| 6.双网卡配置 |"
echo "| 7.登录账户禁用(默认账户) |"
echo "| 8.添加新用户 |"
echo "| 9.更改主机名 |"
echo "| 10.删除virbr0虚拟网卡 |"
echo "| 0.退出 |"
echo "|-------------------------------------------------|"
echo -n "请输入您的选择:"
read thechoice
if [ "$thechoice" == "1" ];thenecho "您的选择是 1.配置内网yum源"echo change yum.conf pleaese waiting..cd /etc/yum.repos.dtest -e baks/ && mv -i -n *.repo bakstest ! -e baks/ && mkdir baks && mv -f *.repo baks/echo [local] > local.repoecho name=local >> local.repoecho baseurl=http://10.244.134.49/centos7/ >> local.repoecho enabled=1 >> local.repoecho gpgcheck=0 >> local.repoyum clean allyum makecacheecho " "echo ok,查看local.repo配置 echo cat local.repoecho " "cat local.repoecho -n "按任意键继续,按n键退出脚本..."read nyif [ "$ny" == "N" ] || [ "$ny" == "n" ];thenecho ok,quit shell scriptelse/root/Desktop/linuxshellsForCentos7/optimization.shfielif [ "$thechoice" == "2" ];thenecho "您的选择是 2.服务启动项优化"Service=(NetworkManager.servicefirewalld.servicebluetooth.service)for i in ${Service[*]}dosystemctl disable $iecho "--------------------show $i status--------------------"echo "systemctl disable $i"systemctl stop $isystemctl status $i | grep Active -B 2echo "systemctl is-enabled $i"systemctl is-enabled $iecho " "doneecho close selinux..cp -i -n /etc/selinux/config /etc/selinux/config.bakcp -f /etc/selinux/config.bak /etc/selinux/configsed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/configsetenforce 0echo show selinux status :getenforceecho " "echo '*/5 * * * * /usr/sbin/ntpdate 10.191.130.130' > /var/spool/cron/rootecho "crontab -l"crontab -lsystemctl restart crond.servicesystemctl enable crond.serviceecho "show crond.service status"systemctl status crond.service | grep Active -B 2echo "systemctl in-enable crond.service"systemctl is-enabled crond.serviceecho " "echo -n "按任意键继续,按n键退出脚本..."read nyif [ "$ny" == "N" ] || [ "$ny" == "n" ];thenecho ok,quit shell scriptelse/root/Desktop/linuxshellsForCentos7/optimization.shfielif [ "$thechoice" == "3" ];thenecho "您的选择是 3.SNMP服务配置"if [ ! -f "/etc/snmp/snmpd.conf" ];thenecho "warning :snmpd.conf not exist,pleaese install snmpd"echo "Input y to install snmp,input n or other cancel instal snmp and exit."read thenyif [ "$theny" == "Y" ] || [ "$theny" == "y" ];thenecho ok install snmp.please waiting...cd /etc/yum.repos.dtest -e baks/ && mv -i -n *.repo bakstest ! -e baks/ && mkdir baks && mv -f *.repo baks/echo [local] > local.repoecho name=local >> local.repoecho baseurl=http://10.244.134.49/centos7/ >> local.repoecho enabled=1 >> local.repoecho gpgcheck=0 >> local.repoyum clean allyum makecacheyum install -y net-snmp net-snmp-utilselseecho ok,quit shell scriptexit 0fielseecho please waiting...echo " "fi#test ! -e /etc/snmp/snmpd.conf && echo "warning :snmpd.conf not exist,pleaese install snmpd" && echo "you can try to yum install -y net-snmp net-snmp-utils" && exit 0cd /etc/snmpcp -i -n snmpd.conf snmpd.conf.bakcp -f snmpd.conf.bak snmpd.confsed -i '56a view all included .1' snmpd.confsed -i 's/access notConfigGroup "" any noauth exact systemview none none/access notConfigGroup "" any noauth exact all none none/g' snmpd.confsed -i 's/#view all included .1 80/view all included .1 80/g' snmpd.confecho ----------------------ok....--------------------------echo ---------------------show file------------------------cat -n snmpd.conf |grep -B2 -A2 "view all included .1"echo ------------------------------------------------------cat -n snmpd.conf |grep -B2 -A2 "any noauth exact all none none"echo ------------------------------------------------------cat -n snmpd.conf |grep -B2 -A2 "view all included .1 80"echo "--------------------show snmpd status--------------------"systemctl restart snmpd.servicesystemctl enable snmpd.serviceecho " "systemctl status snmpd.service | grep Active -B 3echo " "echo "Show the service self-start status"systemctl list-unit-files | grep snmpdecho " "echo -n "按任意键继续,按n键退出脚本..."read nyif [ "$ny" == "N" ] || [ "$ny" == "n" ];thenecho ok,quit shell scriptelse/root/Desktop/linuxshellsForCentos7/optimization.shfielif [ "$thechoice" == "4" ];thenecho "您的选择是 4.修改网卡为eth0"cd /etc/defaultcp -i -n grub grub.baksed -i 's/GRUB_CMDLINE_LINUX/#GRUB_CMDLINE_LINUX/g' grubecho 'GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root net.ifnames=0 biosdevname=0 rd.lvm.lv=centos/swap rhgb quiet"' >> grubgrub2-mkconfig -o /boot/grub2/grub.cfgcd /etc/sysconfig/network-scripts/wangkaname=$(ls|grep ifcfg-en)mv -i -n "$wangkaname" "$wangkaname.bak"#ipdizhi=$(cat $wangkaname | grep IPADDR)#ziwangyanma=$(cat $wangkaname | grep NETMASK)#morenwangguan=$(cat $wangkaname | grep GATEWAY)#cp -i -n ifcfg-eth0 ifcfg-eth0.bakecho 'DEVICE=eth0' > /etc/sysconfig/network-scripts/ifcfg-eth0echo 'TYPE=Ethernet' >> /etc/sysconfig/network-scripts/ifcfg-eth0echo 'ONBOOT=yes' >> /etc/sysconfig/network-scripts/ifcfg-eth0echo 'NM_CONTROLLED=no' >> /etc/sysconfig/network-scripts/ifcfg-eth0echo 'BOOTPROTO=static' >> /etc/sysconfig/network-scripts/ifcfg-eth0(cat $wangkaname.bak | grep IPADDR) >> /etc/sysconfig/network-scripts/ifcfg-eth0(cat $wangkaname.bak | grep NETMASK) >> /etc/sysconfig/network-scripts/ifcfg-eth0(cat $wangkaname.bak | grep GATEWAY) >> /etc/sysconfig/network-scripts/ifcfg-eth0#echo "You must restart to apply these modifications"echo -e "\033[31;40m You must restart to apply the modifications \033[0m"echo " "echo "Press Y to restart the server and press any other key to exit the script"read nyif [ "$ny" == "Y" ] || [ "$ny" == "y" ];thenecho ok,pleaese wait...rebootelseexit 0fiecho " "echo -n "按任意键继续,按n键退出脚本..."read nyif [ "$ny" == "N" ] || [ "$ny" == "n" ];thenecho ok,quit shell scriptelse/root/Desktop/linuxshellsForCentos7/optimization.shfielif [ "$thechoice" == "5" ];thenecho "您的选择是 5.单ip配置"#xianshi yijing changshang wangxian de wangkouecho ----------------xianshi changshang wangxian de wangkouip a|grep "state UP"|awk -F '[: ]+' '{print $2}'echo pleaese choose which port you want to change, eth0-11,input the numberread portnumbercd /etc/sysconfig/network-scriptsif [ "$portnumber" == "0" ]||[ "$portnumber" == "1" ]||[ "$portnumber" == "2" ]||[ "$portnumber" == "3" ]||[ "$portnumber" == "4" ]||[ "$portnumber" == "5" ]||[ "$portnumber" == "6" ]||[ "$portnumber" == "7" ]||[ "$portnumber" == "8" ]||[ "$portnumber" == "9" ]||[ "$portnumber" == "10" ]||[ "$portnumber" == "11" ];thencp -i -n ifcfg-eth$portnumber ifcfg-eth$portnumber.baksed -i 's/ONBOOT=no/ONBOOT=yes/g' ifcfg-eth$portnumbersed -i 's/BOOTPROTO=dhcp/BOOTPROTO=static/g' ifcfg-eth$portnumberecho pleaese write theIPADDRread theipecho pleaese write theNETMASKread thenetmaskecho pleaese write theGATEWAYread thegatewayecho okecho TYPE=Ethernet > /etc/sysconfig/network-scripts/ifcfg-eth$portnumberecho BOOTPROTO=static >> /etc/sysconfig/network-scripts/ifcfg-eth$portnumberecho NAME=eth$portnumber >> /etc/sysconfig/network-scripts/ifcfg-eth$portnumberecho DEVICE=eth0 >> /etc/sysconfig/network-scripts/ifcfg-eth$portnumberecho ONBOOT=yes >> /etc/sysconfig/network-scripts/ifcfg-eth$portnumberecho 'IPADDR='$theip >> /etc/sysconfig/network-scripts/ifcfg-eth$portnumberecho 'NETMASK='$thenetmask >> /etc/sysconfig/network-scripts/ifcfg-eth$portnumberecho 'GATEWAY='$thegateway >> /etc/sysconfig/network-scripts/ifcfg-eth$portnumberecho ------------------------show eth$portnumber-------------------------cat ifcfg-eth$portnumber#yong dangqian shijian zuo beifendatename=$(date +%Y%m%d-%H%M%S)cp ifcfg-eth$portnumber ifcfg-eth$portnumber.$datename.bakelseecho "----------------warning: pleaese input eth(0-11)-----------------"exit 0fiecho ""#panduan shifou xuyao baocun wangguan peizhiecho would you want to restart the network y/nread thenyif [ "$theny" == "Y" ] || [ "$theny" == "y" ];thenecho okservice network restartelif [ "$theny" == "N" ] || [ "$theny" == "n" ];thenecho ok,not restartfiecho " "echo -n "按任意键继续,按n键退出脚本..."read nyif [ "$ny" == "N" ] || [ "$ny" == "n" ];thenecho ok,quit shell scriptelse/root/Desktop/linuxshellsForCentos7/optimization.shfielif [ "$thechoice" == "6" ];thenecho "您的选择是 6.双网卡配置"#change office ip (eth3)echo change eth0 office ipcd /etc/sysconfig/network-scripts/cp -i -n ifcfg-eth0 ifcfg-eth0.bakecho pleaese write officeIPADDRread officeipecho pleaese write officeNETMASKread officenetmaskecho pleaese write officeGATEWAYread officegatewayecho 'DEVICE=eth0' > /etc/sysconfig/network-scripts/ifcfg-eth0echo 'TYPE=Ethernet' >> /etc/sysconfig/network-scripts/ifcfg-eth0echo 'ONBOOT=yes' >> /etc/sysconfig/network-scripts/ifcfg-eth0echo 'NM_CONTROLLED=no' >> /etc/sysconfig/network-scripts/ifcfg-eth0echo 'BOOTPROTO=static' >> /etc/sysconfig/network-scripts/ifcfg-eth0echo 'IPADDR='$officeip >> /etc/sysconfig/network-scripts/ifcfg-eth0echo 'NETMASK='$officenetmask >> /etc/sysconfig/network-scripts/ifcfg-eth0echo 'DNS1=10.191.130.130' >> /etc/sysconfig/network-scripts/ifcfg-eth0echo 'DNS2=10.191.131.131' >> /etc/sysconfig/network-scripts/ifcfg-eth0#echo 'GATEWAY='$officegateway >> /etc/sysconfig/network-scripts/ifcfg-eth3echo eth0 ok echo change eth1 sfc ipecho pleaese write sfcIPADDRread sfcipecho pleaese write sfcNETMASKread sfcnetmaskecho pleaese write sfcGATEWAYread sfcgatewayecho 'DEVICE=eth1' > /etc/sysconfig/network-scripts/ifcfg-eth1echo 'TYPE=Ethernet' >> /etc/sysconfig/network-scripts/ifcfg-eth1echo 'ONBOOT=yes' >> /etc/sysconfig/network-scripts/ifcfg-eth1echo 'NM_CONTROLLED=no' >> /etc/sysconfig/network-scripts/ifcfg-eth1echo 'BOOTPROTO=none' >> /etc/sysconfig/network-scripts/ifcfg-eth1echo 'IPADDR='$sfcip >> /etc/sysconfig/network-scripts/ifcfg-eth1echo 'NETMASK='$sfcnetmask >> /etc/sysconfig/network-scripts/ifcfg-eth1echo 'GATEWAY='$sfcgateway >> /etc/sysconfig/network-scripts/ifcfg-eth1echo eth1 okcd /etc/rc.dcp -i -n rc.local rc.local.bakcp -f rc.local.bak rc.localecho 'route add -net 10.0.0.0 netmask 255.0.0.0 gw '$officegateway >> /etc/rc.d/rc.localecho tianjia jingtai luyou wanchengecho 'any net 10.0.0.0/8 gw '$officegateway > /etc/sysconfig/static-routesecho tianjia moren luyou wancheng #panduan shifou xuyao baocun wangguan peizhiecho would you want to restart the network y/nread thenyif [ "$theny" == "Y" ] || [ "$theny" == "y" ];thenecho okservice network restartelif [ "$theny" == "N" ] || [ "$theny" == "n" ];thenecho ok,not restartfiecho " "echo -n "按任意键继续,按n键退出脚本..."read nyif [ "$ny" == "N" ] || [ "$ny" == "n" ];thenecho ok,quit shell scriptelse/root/Desktop/linuxshellsForCentos7/optimization.shfielif [ "$thechoice" == "7" ];thenecho "您的选择是 7.登录账户禁用(默认账户)"echo " "cat /etc/passwd |grep /bin/bashusermod -s /sbin/nologin mysqlusermod -s /sbin/nologin postgresusermod -s /sbin/nologin amandausermod -s /sbin/nologin pvmecho " "echo "--------------------------- "echo "xiugaihou de zhanghu"echo " "cat /etc/passwd |grep /bin/bashecho " "echo " "echo -n "按任意键继续,按n键退出脚本..."read nyif [ "$ny" == "N" ] || [ "$ny" == "n" ];thenecho ok,quit shell scriptelse/root/Desktop/linuxshellsForCentos7/optimization.shfielif [ "$thechoice" == "8" ];thenecho "您的选择是 8.添加新用户"echo " "echo Please input the user nameread theuseruseradd $theuserif [ "$theuser" == "cdsm" ] ;thenecho $theuser:"passwd2020@"|chpasswdelseecho $theuser:"passwd123.1234"|chpasswdficp -i -n /etc/sudoers /etc/sudoers.bakecho "$theuser ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoersecho " "echo ------Has been created!------echo " "echo user name: $theuserif [ "$theuser" == "cdsm" ] ;thenecho password : passwd2020@elseecho password : passwd123.1234fi echo " "echo -------ok~! Thanks-----------echo " "echo " "echo -n "按任意键继续,按n键退出脚本..."read nyif [ "$ny" == "N" ] || [ "$ny" == "n" ];thenecho ok,quit shell scriptelse/root/Desktop/linuxshellsForCentos7/optimization.shfielif [ "$thechoice" == "9" ];thenecho "您的选择是 9.更改主机名"echo ----------------pleaese input hostname---------------read thehostnamehostname $thehostnameecho $thehostname > /etc/hostnameecho ------------The hostname has been changed------------echo " "echo -n "按任意键继续,按n键退出脚本..."read nyif [ "$ny" == "N" ] || [ "$ny" == "n" ];thenecho ok,quit shell scriptelse/root/Desktop/linuxshellsForCentos7/optimization.shfielif [ "$thechoice" == "10" ];thenecho "您的选择是 10.删除virbr0虚拟网卡"echo "show virbr0 status"virsh net-listvirsh net-destroy defaultvirsh net-undefine defaultsystemctl restart libvirtd.serviceecho "delete virbr0 ok..."echo " "echo "show virbr0 status now"virsh net-listecho " "echo -n "按任意键继续,按n键退出脚本..."read nyif [ "$ny" == "N" ] || [ "$ny" == "n" ];thenecho ok,quit shell scriptelse/root/Desktop/linuxshellsForRedhat7/optimization.shfielif [ "$thechoice" == "0" ];thenecho ok,quit shell script exit 0else echo " "echo -e "\033[31;40m -----------输入有误,请重新输入------------------- \033[0m"echo " "/root/Desktop/linuxshellsForCentos7/optimization.shfi
Centos7 新建server的优化脚本--不适用于所有人相关推荐
- linux内核优化脚本,linux内核高级优化脚本
linux内核高级优化脚本 可以用于hadoop生态圈环境的组件安装 linux内核调优 具体的每一步的解释请参考 03搭建cdh 备注:使用与centos6和centos7两个系统版本执行 [[em ...
- Windows Server 2012 R2 Datacenter ms17-010漏洞出现此更新不适用于你的计算机
Windows Server 2012 R2 Datacenter ms17-010出现此更新不适用于你的计算机 Windows Server 2012 R2 Datacenter ms17-010出 ...
- oracle报数据类型不正确,SQL Server访问Oracle提示[消息 9803 数据不适用于类型 “numeric”]问题...
服务器A,安装的是SQL Server2005,Oracle 10g的客户端,版本10.2.0.1 服务器B,装的是Oracle 11g,版本11.2.0.1 现在是服务器A上建了链接服务器,去访问服 ...
- windows server 2012 r2 打补丁时提示此更新不适用于您的计算机
等保测评二级,有个 MS15-034 HTTP.sys远程执行代码漏洞需要打补丁 打补丁时提示此更新不适用于您的计算机,之后打了几个其他补丁都是提示的这个问题 因为是高危漏洞,必须要处理掉,开始面向百 ...
- 源“ySQL 8.0 Community Server”的GPG密钥已安装,但是不适用于此软件包。请检查源的公钥URL是否配置正确。
源"ySQL 8.0 Community Server"的GPG密钥已安装,但是不适用于此软件包.请检查源的公钥URL是否配置正确. 方法: 将 sudo yum install ...
- Windows Server 2012 R2 此更新不适用于你的计算机 问题解决
Windows Server 2012 R2 此更新不适用于你的计算机 问题解决 问题描述 内网Windows Server 2012 R2(64)系统扫描出"Microsoft Windo ...
- Sql server索引优化
Sql server索引优化 索引优化(1)堆上的非聚集索引 一.索引概述 1.概念 可以把索引理解为一种特殊的目录.就好比<新华字典>为了加快查找的速度,提供了几套目录,分别按拼音.偏旁 ...
- SQL Server数据库优化方案
SQL Server数据库优化方案 查询速度慢的原因很多,常见如下几种: 1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷) 2.I/O吞吐量小,形成了瓶颈效应. 3.没有创建计 ...
- SQL Server 11_编写脚本和批处理
<SQL Server 2012 编程入门经典> [美]Paul Atkinson, Robert Vieira著; 王军, 牛志玲 译 第11章 编写脚本和批处理 本章内容简介: • 如 ...
最新文章
- java随机产生100个大小写字母_Java生成固定长度的随机字符串(以大小写字母和数字)...
- noi 2728 摘花生
- Android属性 android:focusableInTouchMode
- Android vector矢量图应用实例
- mariadb mysql同步_MySQL(Mariadb)主从同步基础
- 我混了大半辈子,忽然成了拆二代
- delphi 通用型参数类型_沈阳环保设备参数表
- 英国科研学术网络Janet遭遇DDoS攻击
- 打算考PMP,需要准备什么材料?
- v中国瓶装水市场营销状况与销售动态分析报告2022-2027年
- 【Android Studio】一款简易appUI界面开发(2)
- Leedcode 875. 爱吃香蕉的珂珂
- linux windows10双系统安装教程,【笔记】windows10安装linux双系统教程(可能是现今最简单方法)...
- 线性代数·关于线性相关和线性组合
- 中文热门开源项目Top100,你知道多少?
- 信托资金将分辨用于向邢台依林山庄食物有限公司、唐山国泰纸业有限公司、唐山蓝猫饮品团体有限公司发放流动资金贷款1亿、1.5亿、1亿
- stata行业变量怎么赋值_动态面板模型估计方法简介以及stata应用
- 4-使用GitHub(Github Issue)及基本概念实战
- R语言互信息和条件互信息
- 一种低成本实用线性稳压电源设计