01 Linux系统配置初始化
#/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin # 更改主机名
# hostnamectl set-hostname <hostname> # 隐藏服务器版本
> /etc/issue # 修改字符集
localectl set-locale LANG=en_US.UTF-8 # 解决ssh连接速度慢的问题
sed -i '/GSSAPIAuthentication/{s/yes/no/}' /etc/ssh/sshd_config
sed -i 's/\#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
# sed -i '134i GSSAPIAuthentication no\nUseDNS no' /etc/ssh/sshd_config # 更新yum源
if egrep "7.[0-9]" /etc/redhat-release &>/dev/null; then
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
elif egrep "6.[0-9]" /etc/redhat-release &>/dev/null; then
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
fi
yum clean all # 设置时区并同步时间
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
if ! crontab -l | grep "ntpdate" &>/dev/null; then
(echo "*/5 * * * * /usr/sbin/ntpdate ntp.aliyun.com >/dev/null 2>&1"; crontab -l) | crontab
fi # 禁用selinux
sed -i '/SELINUX/{s/enforcing/disabled/}' /etc/selinux/config # 关闭防火墙
if egrep "7.[0-9]" /etc/redhat-release &>/dev/null; then
systemctl stop firewalld.service
systemctl disable firewalld.service
elif egrep "6.[0-9]" /etc/redhat-release &>/dev/null; then
service iptables stop
chkconfig iptables off
fi # 关闭postfix服务
if egrep "7.[0-9]" /etc/redhat-release &>/dev/null; then
systemctl stop postfix.service
systemctl disable postfix.service
elif egrep "6.[0-9]" /etc/redhat-release &>/dev/null; then
service postfix stop
chkconfig postfix off
fi # 历史命令显示操作时间;命令行历史数;忽略所有以空格开头的命令。
if ! grep "HISTTIMEFORMAT" /etc/profile &>/dev/null; then
echo 'export HISTTIMEFORMAT="%F %T `whoami` "' >> /etc/profile
echo "export HISTSIZE=50" >>/etc/profile
echo "export HISTFILESIZE=50" >> /etc/profile
echo "export HISTCONTROL=ignorespace" >>/etc/profile
fi # SSH超时时间,改变umask
if ! grep "TMOUT=3600" /etc/profile &>/dev/null; then
echo "export TMOUT=3600" >> /etc/profile
echo "umask 022" >> /etc/profile
fi # 禁止root远程登录
# sed -i 's/\#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config # 禁止定时任务向发送邮件
sed -i 's/^MAILTO=root/MAILTO=""/' /etc/crontab # 设置最大打开文件数
if ! grep "* soft nofile 65535" /etc/security/limits.conf &>/dev/null; then
cat >> /etc/security/limits.conf << EOF
* soft nofile 65535
* hard nofile 65535
EOF
fi # 系统内核优化
if ! grep "net.ipv4" /etc/sysctl.conf &>/dev/null; then
cat >> /etc/sysctl.conf << EOF
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_tw_buckets = 20480
net.ipv4.tcp_max_syn_backlog = 20480
net.core.netdev_max_backlog = 262144
net.ipv4.tcp_fin_timeout = 20
EOF
fi # 减少SWAP使用
if ! grep "vm.swappiness" /etc/sysctl.conf &>/dev/null; then
cat >> /etc/sysctl.conf << EOF
vm.swappiness = 0
EOF
fi
# echo "0" > /proc/sys/vm/swappiness
# 临时生效 # 安装系统性能分析工具及其他
yum install gcc make autoconf vim sysstat net-tools iostat iftop iotop lrzsz -y # 重启服务器
reboot
01 Linux系统配置初始化的更多相关文章
- 跟我一起Django - 01 安装和初始化
跟我一起Django - 01 安装和初始化 python环境 C:\Python27\Lib\site-packages>python --versionPython 2.7.5 安装setu ...
- Linux网络服务01——Linux网络基础设置
Linux网络服务01--Linux网络基础设置 一.查看及测试网络 1.使用ifconfig命令查看网络接口 (1)查看活动的网络接口 ifconfig命令 [root@crushlinux ~]# ...
- LINUX系统配置
LINUX系统配置 Linux 安装jdk方法; Linux Tomcat 安装与配置 Linux redis 安装与配置 (例1) Linux redis安装配置(例2) NGINX 安装 Linu ...
- linux文件系统 - 初始化(二)
加载initrd(上) 一.目的 本文主要讲述linux3.10文件系统初始化过程的第二阶段:加载initrd. initrd是一个临时文件系统,由bootload负责加载到内存中,里面包含了基本的可 ...
- linux文件系统 - 初始化(一)
术语表: struct task:进程 struct mnt_namespace:命名空间 struct mount:挂载点 struct vfsmount:挂载项 struct file:文件 st ...
- linux文件系统初始化过程(5)---加载initrd(下)
一.目的 linux把文件分为常规文件.目录文件.软链接文件.硬链接文件.特殊文件(设备文件.管道文件.socket文件等)几种类型,分别对应不同的新建函数sys_open().sys_mkdir() ...
- linux文件系统初始化过程(2)---挂载rootfs文件系统
一.目的 本文主要讲述linux3.10文件系统初始化过程的第一阶段:挂载rootfs文件系统. rootfs是基于内存的文件系统,所有操作都在内存中完成:也没有实际的存储设备,所以不需要设备驱动程序 ...
- linux文件系统初始化过程(1)---概述
术语表: struct task:进程 struct mnt_namespace:命名空间 struct mount:挂载点 struct vfsmount:挂载项 struct file:文件 st ...
- Linux系统配置VSFTP软件详解
Linux系统配置VSFTP软件详解 出处 http://www.sudu.cn/service/detail.php?id=11656 vsftpd.conf 是vsftpd的配置文件,用来控制vs ...
随机推荐
- [bug] Authentication failed for token submission (认证失败)异常
原因 gitee上下的项目,启动后能访问首页,但登录报错.原因是根据用户名上数据库查密码没有得到结果,中间任何环节有问题都可能导致,我的是因为mapper.xml中的<mapper namesp ...
- [bug] java.sql.SQLSyntaxErrorException: Table 'mysql.tb_item' doesn't exist
参考 https://zhidao.baidu.com/question/146817103.html
- [刷题] PTA 7-32 说反话-加强版
题目描述: 给定一个英语句子,各个单词之间用空格分隔.要求编写程序,将所有单词倒序输出 输入示例: Hello World Here I Come 输出示例: Come I Here World He ...
- EasyUI系列—点击按钮加载tabs_day26
我们先来看下效果图 1.为div添加点击事件(也可使用jQuery绑定事件) 1 <div id="mm2" style="width:100px;"&g ...
- Assignment Problem的若干思考
最近受到南京一个同学的push,又开始了博客园写作之旅.欢迎大家联系我做代码实现工作,QQ:1198552514.权当赚点生活费~ 我的研究也经常用的Assignment problem,而且很多 ...
- go输出九九乘法表和金字塔
用go语言实现输出九九乘法表和金字塔: 1.输出九九乘法表: 代码示例: package main import ( "fmt" "time" ) //实现99 ...
- IDEA2021.1 安装教程
工欲善其事必先利其器. 一.下载 IDEA 官方下载地址: https://www.jetbrains.com/zh-cn/idea/download/ 二.安装 IDEA 注:安装IDEA之前需要我 ...
- GO学习-(37) 使用Air实现Go程序实时热重载
使用Air实现Go程序实时热重载 今天我们要介绍一个神器--Air能够实时监听项目的代码文件,在代码发生变更之后自动重新编译并执行,大大提高gin框架项目的开发效率. 为什么需要实时加载? 之前使用P ...
- java中存储mysql数据库时间类型【date、time、datetime、timestamp】
在MySQL中对于时间的存储自己见表的时候都是设置的varchar类型的,感觉挺方便的. 昨天拿别人建好的表写代码,发现这张表中时间类型为datetime的,凭感觉试了一下不行,网上查了刚开始试了好几 ...
- DDD中聚合、聚合根的含义以及作用
聚合与聚合根的含义 聚合: 聚合往往是一些实体为了某项业务而聚类在一起形成的集合 , 举个例子, 社会是由一个个的个体组成的,象征着我们每一个人.随着社会的发展,慢慢出现了社团.机构.部门等组织,我们 ...