案例名称:系统初始化

背景: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. python--随笔一

    1.format函数--根据关键字和位置选择性插入数据 In [11]: '{mingzi}jintian{dongzuo}'.format(mingzi='duzi',dongzuo='i love ...

  2. PLC状态机编程第六篇-优化PLC程序生成

    还记得第一篇博客中,我们在状态机中手写上升沿来处理有别于传统的一键启停程序,那个手写的上升沿就是优化手段.stateflow状态机是带事件的,事件本身支持上升沿和下降沿等事件,在这里,如果我们选择用事 ...

  3. 数据分析处理库Pandas——groupby

    DataFrame结构 指定列中相同元素求和 备注:指定列"key"中相同元素的"data"值求和. 备注:指定列"A"和"B&q ...

  4. mysql 安装常用命令,卸载不干净等

    安装mysql apt-get install mysql-server apt-get install mysql-client sudo apt-get install libmysqlclien ...

  5. opencv中对图像的像素操作

    1.对灰度图像的像素操作: #include<iostream> #include<opencv2/opencv.hpp> using namespace std; using ...

  6. Postgres常用命令之增、删、改、查

    增.删.改.查: postgres=# \password postgres 为postgres进行密码设置: postgres=# CREATE USER test WITH PASSWORD '1 ...

  7. 29-自己动手构建RequestDelegate管道

    1-使用vsCode新建个项目 2-新建RequestDelegate和Context public delegate Task RequestDelegate(Context context); p ...

  8. Kali2017 Metasploit连接postgresql数据库

    msfdb:msf数据库管理命令 1.查看msf数据库连接状态 msf > db_status [*] postgresql selected, no connection //未连接 2.ms ...

  9. eclipse、myeclipse 反编译插件 轻松查看源代码

    java反编译插件:Eclipse Class Decompiler,能够很方便的使用本插件查看类库源码,以及采用本插件进行Debug调试. eclipse中安装Eclipse Class Decom ...

  10. 使用Eclipse把java文件打包成jar

    本例仅限于要打包的文件没有使用第三方的jar包 在要打包的包或者文件上右键-Export 这里有一些选项: Export generated class files and resources 表示只 ...