##################################################
# CentOS6.5 #
# initialize the Linux system to deploy lnmp #
# 2016/10/30 22:58 #
# author:kangjie #
# original article #
##################################################
#!/bin/sh
#向自动化运维迈进
#定义文件位置
LOG_PATH=/server/initlog
LOG_FILE=$LOG_PATH/init.log
i=0
#如果文件夹不存在,则创建
[ ! -d /server/tools ] && mkdir -p /server/tools
[ ! -d $LOG_PATH ] && mkdir -p $LOG_PATH
#判断命令执行是否成功
#check status then wirite to log
function check(){
if [ $? != 0 ]
then
echo "××××-operate $1 Failed!!!-×××" >> $LOG_FILE
else
echo "√√√-operate $1 Success-√√√" >> $LOG_FILE
fi
}
#关闭防火墙,禁止开机启动(仅限于没有公网的情况)
#iptables
function iptable(){
/etc/init.d/iptables stop
check iptables
chkconfig iptables off
check chkconfig-iptables
((i++))
}
#关闭selinux,修改配置文件后,同时设置临时生效
#selinux disable the selinux
function selinux(){
status=`grep SELINUX= /etc/selinux/config | tail -1 | awk -F '=' '{print $2}'`
if [ $status != disabled ]
then
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
status=`grep SELINUX= /etc/selinux/config | tail -1 | awk -F '=' '{print $2}'`
if [ $status == disabled ]
then
echo "√√√-Modify selinux config success-√√√-" >> $LOG_FILE
else
echo "××××-Modify selinux config Failed!!!-××××" >> $LOG_FILE
fi
else
echo "Selinx config already Modified" >> $LOG_FILE
fi
setenforce 0 #关闭selinux
check setenfore
((i++))
}
#添加系统用户,修改密码
#add user and change password
function adduser(){
userdel -r kangjie >/dev/null 2>&1
useradd kangjie
check adduser
echo "123456" | passwd --stdin kangjie && history -c
check "change user password"
((i++))
}
#更新yum源为163yum源
#yum update 163
function yumsource(){
cd /etc/yum.repos.d/
/bin/mv CentOS-Base.repo CentOS-Base.repo.ori
/bin/mv CentOS6-Base-163.repo CentOS-Base.repo
check yum-update
((i++))
}
#安装系统监控软件
#software sysstat
function soft(){
yum install sysstat -y
check sysstat
((i++))
}
#精简开机启动项,虚拟机上设置后无法开机,需要在真实环境中测试
#Msconfig something the matter
function Msconfig(){
for a in `chkconfig --list | grep "3:on" | awk '{print $1}' | grep -vE "crond|network|sshd|rsyslog"`;
do
chkconfig $a off;
done
check Msconfig
((i++))
}
#更改ssh登录端口、禁止root用户登录,禁止空密码,禁用DNS登录
#sshd
function changesshd(){
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.ori
sed -i 's%#Port 22%Port 22222%' /etc/ssh/sshd_config
sed -i 's%#PermitRootLogin yes%PermitRootLogin no%' /etc/ssh/sshd_config
sed -i 's%#PermitEmptyPasswords no%PermitEmptyPasswords no%' /etc/ssh/sshd_config
sed -i 's%#UseDNS yes%UseDNS no%' /etc/ssh/sshd_config
egrep "UseDNS|22222|RootLogin|EmptyPass" /etc/ssh/sshd_config >> $LOG_FILE
((i++))
}
#给kangjie用户赋予高的权限
#sudouser
function sudouser(){
cp /etc/sudoers /etc/sudoers.ori
echo "kangjie ALL=(ALL) ALL" >>/etc/sudoers
tail -1 /etc/sudoers >> $LOG_FILE
((i++))
}
#更改字符集,支持国标,鸡肋
#lang something the matter
function lang(){
echo ' LANG="zh_CN.GB18030"' >/etc/sysconfig/i18n
source /etc/sysconfig/i18n
echo $LANG >> $LOG_FILE
((i++))
}
#定时任务校准时间 ,虚拟机无效,需要手动更改时区和时间
#crontab something the matter
function cron(){
echo '*/5 * * * * /usr/sbin/ntpdate time.windows.com >/dev/null 2>&1' >>/var/spool/cron/root
crontab -l >> $LOG_FILE
((i++))
}
#修改系统文件描述符
#limits
function limit(){
echo '* - nofile 65535 ' >>/etc/security/limits.conf
tail -1 /etc/security/limits.conf >> $LOG_FILE
((i++))
}
#修改vim配置,显示行号等内容
#注意:使用EOF时,其后不能跟多余的空格,否则报错
#vimrc
function vimrc(){
cp /etc/vimrc /etc/vimrc.ori
cat >>/etc/vimrc<<EOF
set nu
syntax on
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set showmatch
set cursorline
EOF
check vimrc
((i++))
}
#修改系统内核参数,sysctl -p 使参数生效
#来源:oldboy51cto博客
#sysctl.conf
function sys(){
cp /etc/sysctl.conf /etc/sysctl.conf.`date +"%Y-%m-%d_%H-%M-%S"` #备份
cat>>/etc/sysctl.conf<<EOF
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem=4096 87380 16777216
net.ipv4.tcp_wmem=4096 65536 16777216
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout=1
net.ipv4.tcp_keepalive_time=1200
net.ipv4.tcp_max_syn_backlog = 65536
net.ipv4.ip_local_port_range = 1024 65535
EOF
sysctl -p
check sysctl
((i++))
}
#配置邮件,使用126邮箱发送邮件
#mail
function mailset(){
cat >>/etc/mail.rc<<EOF
set from=13888888888@126.com
set smtp=smtp.126.com
set smtp-auth-user=13888888888@126.com
set smtp-auth-password=888888
set smtp-auth=login
EOF
#取得主机的IP地址
a=`ifconfig | grep 'inet addr:'|grep -v '127.0.0.1'|awk -F '[ :]+' '{print $4}'`
echo "This is a test mail from $a" | mail -s "deploy linux" 88888888@qq.com
}
#发邮件
function Mail(){
mail -s "***Linux Deploy Report***" 888888888@qq.com < $LOG_FILE
}
#主函数
#main
function main(){
echo "Deploy Linux *****`date +"%Y-%m-%d_%H-%M-%S"`*****">>$LOG_FILE
iptable
selinux
adduser
yumsource
soft
mailset
#Msconfig
changesshd
sudouser
#lang
cron
limit
vimrc
sys
#统计执行过的函数的个数
echo "ALL steps=$i" >> $LOG_FILE
Mail
}
main
- 运维与自动化系列③自动化部署基础与shell脚本实现
自动化部署基础与shell脚本实现 关于自动化的基础知识: 1.1:当前代码部署的实现方式: 运维纯手工scp到web服务器纯手工登录git服务器执行git pull或svn服务器执行svn upda ...
- linux服务器批量部署应用系统shell脚本(Tomcat/jetty)
linux服务器批量部署应用系统shell脚本: 1.请更换代码内的服务器地址(Tomcat或jetty服务器) serverRoot=/home/undoner/java_tool/apache-t ...
- win7 cmd终端连接android手机运行adb shell脚本命令
win7 cmd终端连接android手机运行adb shell脚本命令 (2013-03-22 20:13:57) 转载▼ 标签: android it shell 连接 linux 分类: 嵌入式 ...
- 单机部署tomcat的shell脚本
单机部署tomcat的shell脚本,来自网络,自己需要时要根据自己的需求改动. #!/bin/sh # ############################################### ...
- [PY3]——环境配置(1)——pyenv | pip | ipython | jupyter(含安装pyenv环境shell脚本)
1.关于pyenv (1)pyenv是一个开源的.shell脚本编写的工具:Simple Python version management (2)为什么使用pyenv:当多个项目同时在开发与维护时, ...
- 阿里云linux centos 一键部署web环境--图文详解
一.购买阿里云服务器ECS 1,登录阿里云,选择阿里云服务器ECS 2,创建实例 或 3,选好配置 4,完成配置 注:记住用户名和密码 二.一键配置linux环境 1,下载xshell,安装成功后,建 ...
- linux可运行的shell脚本与设置开机服务启动(自己总结)
完整的ln命令参考:http://www.runoob.com/linux/linux-comm-ln.html ln :创建连接文件 - 默认创建的是硬连接,好比复制 ,但是两个文件会同步 命令:l ...
- 每30秒运行一下shell脚本
cd /usr/local/sbin/ //存放shell脚本 目录. vim guoguosql.sh //每30秒运行一个php文件. 文件路径为 vim /home/www ...
- 生产环境Shell脚本Ping监控主机是否存活(多种方法)
在网上针对shell脚本ping监控主机是否存活的文档很多,但大多都是ping一次就决定了状态,误报率会很高,为了精确判断,ping三次不通再发告警,只要一次ping通则正常.于是,今天中午抽出点时间 ...
随机推荐
- linux挂载问题解决
1. 挂载光盘 </pre></p><p><pre name="code" class="plain">[roo ...
- UML统一建模语言
概述 统一建模语言(UML)是一种图形化的语言,用于软件密集系统要素的可视化.制定规范.构建对象和编写文档.UML提供了一种标准的方式来描述系统的设计图,既包括概念方面,例如业务过程和系统功能,也包括 ...
- sensor_HAL分析
http://blog.csdn.net/new_abc/article/details/8971807 http://blog.csdn.net/cs_lht/article/details/817 ...
- git 公共服务器
github 私有项目有限制,多了需要收费 bitbucket 无限的私有项目,项目协作人数多了需要收费,刚好和github相反 gitorious 新发现的,不知道有什么特点
- SRM 514 DIV1 500pt(DP)
题目简述 给定一个H×W大小的矩阵,每个格子要么是1~9中的一个数,要么是".",要求你把“.”填成具体的数字(1~9),并且符合以下两个要求: 对于所有的整数r 和 c( 0 & ...
- Hellow world!
其实一年前开始就有了些许开篇技术博客的想法,一直觉得写这些的人都一定好牛×.现刚毕业,我也是时候朝牛×之路迈进了.当然,我才刚入门不久,前路漫漫,需一步一脚印,先打算把平常遇到的一些问题与关注的东西都 ...
- 【转】Nginx系列(四)--工作原理
原博文出于: http://blog.csdn.net/liutengteng130/article/details/46724081 感谢! 上篇文章介绍了Nginx框架的设计之管理进程以及 ...
- (转)php的扩展和嵌入--php的生命周期与变量详述
本文转自http://blog.csdn.net/cedricliang/article/details/17247749?9435:这是在我想在js的循环中加入一段php,这段php代码会在每次执行 ...
- HDU 5656 CA Loves GCD (数论DP)
CA Loves GCD 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/B Description CA is a fine c ...
- 【Todo】ipcs命令学习
可以先看这一篇 http://www.jb51.net/article/40805.htm