案例名称:系统初始化

背景:10台已装有linux系统的服务器

需求:

1.设置时区同步

2.禁用selinux

3.清空防火墙策略

4.历史命令显示操作时间

5.禁止root远程登录

6.禁止定时任务发送邮件

7.设置最大打开文件数

8.减少Swap使用

9.系统内核参数优化

10.安装系统性能工具及其他

脚本具体内容

#!/bin/bash
#Set time zone and together time
if ls /etc/localtime >/dev/null 2>&1;then
rm -f /etc/localtime
fi
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
if ! crontab -l |grep ntp &>/dev/null;then
(echo "* 1 * * * ntpdate time.windows.com" >/var/spool/cron/root;crontab -l)|crontab

fi

#Stop selinux
sed -i '/SELINUX/{s/enforcing/disabled/}' /etc/selinux/config

#Stop firewall
if egrep "7.[0-9]" /etc/redhat-release >/dev/null 2>&1;then
systemctl stop firewalld
systemctl disable firewalld
elif egrep "6.[0-9]" /etc/redhat-release >/dev/null 2>&1;then
service iptables stop
chkconfig iptables off
fi

#Set History time format
if ! grep HISTTIMEFORMAT /etc/bashrc >/dev/null 2>&1;then
echo 'export HISTTIMEFORMAT="%F %T `whoami` "' >>/etc/bashrc
source /etc/bashrc
fi

#Set ssh timeout
if ! grep "TMOUT=600" /etc/profile >/dev/null 2>&1;then
echo "export TMOUT=600" >>/etc/profile
source /etc/profile
fi

#forbidon root connect
#sed -i 's/#PermitRootLogin yes/PermitRootLogin no' /etc/ssh/sshd_config
#systemctl reload sshd

#Forbidon crontab send mail
sed -i 's/MAILTO=root/MAILTO=""/' /etc/crontab

#Set max filenumbers
if ! grep "soft nofile 65535" /etc/security/limits.conf >/dev/null 2>&1;then
cat >>/etc/security/limits.conf<<EOF
* soft nofile 65535
* hard nofile 65535
EOF

fi

#System good
cat >>/etc/sysctl.conf <<EOF
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_tw_buckets = 20480
EOF

#Swap
echo "0" >/proc/sys/vm/swappiness

#Install systems analysis
yum -y install gcc c++ make autoconf vim sysstat net-tools iostat iftop iotp lrzsz >/dev/bull 2>&1

shell脚本——项目1的更多相关文章

  1. 从基于idea的第一个javaweb项目到shell脚本项目自动发布(jdk1.8,mysql5.7,maven3.5,tomcat9,subversion,centos7.3)之一

    首先说一下为什么写这篇文章,因为从正式参加工作就做javaweb开发,一路走来,碰到了很多的问题,每次问题都想从度娘那里得到准确的答案,但是,每个人遇到的问题不尽相同,问题的解决方案有时候也只是仅供参 ...

  2. shell脚本——项目2

    案例名称:发送告警邮件 背景: 外部邮箱的服务器(163等) 安装mailx(yum) 配置邮箱信息 vim /etc/mail.rc #配置自己的邮箱信息 set from=18906534060@ ...

  3. Shell脚本,自动化发布tomcat项目【转载】

    Shell脚本,自动化发布tomcat项目脚本. 1. vko2c_auto_build_by_scp.sh 文件内容: #---------------------start------------ ...

  4. Shell脚本,自动化发布tomcat项目【转】

    Shell脚本,自动化发布tomcat项目脚本. 1. vko2c_auto_build_by_scp.sh 文件内容: #---------------------start------------ ...

  5. 【Shell】使用Shell脚本发布项目

    第一次写Shell脚本,没经验,是直接写呢,还是要走流程( ̄▽ ̄)~* ---------------------------------------------------------------- ...

  6. 编写通用shell脚本启动java项目,适用于多数服务,只需修改服务名即可

    文件名:service-user.sh 文件内容: ##shell脚本的头文件必须有#!/bin/sh ##再次配置java环境变量以防报其他错误## java env#jdk安装目录export J ...

  7. Jenkins结合shell脚本实现(gitLab/gitHub)前端项目自动打包部署服务器

    原始发布部署: 石器时代的我们,先是本地打包好项目,在去服务器上把原来的文件删了,然后回到本地copy到服务器: 这操看起来简单,实际部署的人就知道多烦了,假如来几个项目都要重新发布:那就爽了: 今天 ...

  8. linux下使用shell脚本自动化部署项目

    在Java开发项目时经常要把正在开发的项目发布到测试服务器中去测试,一般的话是要把项目先打成war包,然后把war包发布到服务器中,关闭服务器, 最后重新启动服务器,虽然这过程不是很繁琐,但如果是多个 ...

  9. shell脚本:利用7z备份git项目

    注:无git的方法参见:tar 或 7z 备份项目 首先利用homebrew安装p7zip $ brew install p7zip 然后利用两个shell脚本: backupProject.sh 会 ...

随机推荐

  1. PHP 输出控制

    一.前言 说到PHP输出控制, 在很多框架里面,比如说TP,Yii和Laraval的模版引擎里面都有输出控制函数的阴影,输出控制也叫输出缓冲,说到它的作用有以下几点. 二.内容 1. 输出模版 $va ...

  2. js 判断function是否存在

    function myFunction(){ }//方法一 if(typeof(myFunction) == 'function'){ //function }else{ //undefined }/ ...

  3. Git 基本命令与服务器搭建

    Git教程 一套视频 详细教程 完全命令手册 Git常用命令 git config:配置相关信息 git clone:复制仓库 git init:初始化仓库 git add:添加更新内容到索引中 gi ...

  4. POJ 3608 凸包间最短距离(旋转卡壳)

    Bridge Across Islands Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11539   Accepted: ...

  5. C# 设定弹出窗体位置

    一.C#中弹出窗口位置 加入命名空间 using System.Drawing using System.Windows.Forms 假定窗口名为form1,则 //窗体位置在屏幕中间 form1.S ...

  6. 线性表(List)

    1.什么是线性表(List)? 零个或多个数据元素的有限序列. (1)元素之间是有序的. (2)线性表强调是有限的. 2.线性表有哪些操作? (1)线性表的创建和初始化,InitList (2)判空, ...

  7. java线上编程网站

    自带测试 http://codingbat.com/prob/p145416

  8. 我给女朋友讲编程CSS系列(4) CSS盒子模型

    什么是CSS盒子模型?如何学习CSS的盒子模型? 这篇文章,以 [分享 + 结论]  的方式来写. 1,  看w3school的[CSS 框模型概述] 网址为: http://www.w3school ...

  9. Java 遍历Map集合的方法

    方法一:通过Map.keySet,遍历key和value Map<String, Object> map = new HashMap<>(); for (String key ...

  10. Java EE - JSP 小结

    Table of Contents 前言 JSP 与 Servlet JSP 初始化参数 脚本元素 page 指令 禁用脚本元素 EL 表达式 EL 函数 taglib 指令 标记 TLD 文件的位置 ...