案例名称:系统初始化

背景: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. LNMP+HAProxy+Keepalived负载均衡 - 基础服务准备

    日志服务 修改日志服务配置并重启日志服务: ``` vim /etc/rsyslog.conf ``` 编辑系统日志配置,指定包含的配置文件路径和规则: ``` $IncludeConfig /etc ...

  2. 11.VUE学习之提交表单时拿到input里的值

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  3. PHP表单安全过滤和防注入 htmlspecialchars() 和test_input()

    什么是 htmlspecialchars() 函数? htmlspecialchars() 函数把特殊字符转换为 HTML 实体.这意味着 < 和 > 之类的 HTML 字符会被替换为 & ...

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

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

  5. Codeforces Round #462 (Div. 2) C DP

    C. A Twisty Movement time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. Lighting System Design UVA - 11400 动态规划

    题目:题目链接 思路:简单的动态规划问题,先把灯泡按照电压从小到大排序.设s[i]为前i种灯泡的总数量(即L值之和),d[i]为灯 泡1-i的最小开销,则d[i] = min{d[j] + (s[i] ...

  7. Java实现Avl树

    Avl树即左右子树的深度[高度]相差不可超过1,所以在插入key的时候,就会出现需要旋转[更改根节点]的操作 下面是源代码: /* the define of avltree's node */ cl ...

  8. 15.9,python操作redis集群

      上代码 .对redis的单实例进行连接操作 python3 >>>import redis >>>r = redis.StrictRedis(host=, db ...

  9. 理解Queue队列中join()与task_done()的关系

    在网上大多关于join()与task_done()的结束原话是这样的: Queue.task_done() 在完成一项工作之后,Queue.task_done()函数向任务已经完成的队列发送一个信号 ...

  10. startActivityForResult 请求码不正确

    今天遇到一个坑,就是 startActivityForResult 接收不到正确的请求码. 比如,我startActivityForResult的时候,设置的请求码是4,但是接收到的时候是100032 ...