#/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系统配置初始化的更多相关文章

  1. 跟我一起Django - 01 安装和初始化

    跟我一起Django - 01 安装和初始化 python环境 C:\Python27\Lib\site-packages>python --versionPython 2.7.5 安装setu ...

  2. Linux网络服务01——Linux网络基础设置

    Linux网络服务01--Linux网络基础设置 一.查看及测试网络 1.使用ifconfig命令查看网络接口 (1)查看活动的网络接口 ifconfig命令 [root@crushlinux ~]# ...

  3. LINUX系统配置

    LINUX系统配置 Linux 安装jdk方法; Linux Tomcat 安装与配置 Linux redis 安装与配置 (例1) Linux redis安装配置(例2) NGINX 安装 Linu ...

  4. linux文件系统 - 初始化(二)

    加载initrd(上) 一.目的 本文主要讲述linux3.10文件系统初始化过程的第二阶段:加载initrd. initrd是一个临时文件系统,由bootload负责加载到内存中,里面包含了基本的可 ...

  5. linux文件系统 - 初始化(一)

    术语表: struct task:进程 struct mnt_namespace:命名空间 struct mount:挂载点 struct vfsmount:挂载项 struct file:文件 st ...

  6. linux文件系统初始化过程(5)---加载initrd(下)

    一.目的 linux把文件分为常规文件.目录文件.软链接文件.硬链接文件.特殊文件(设备文件.管道文件.socket文件等)几种类型,分别对应不同的新建函数sys_open().sys_mkdir() ...

  7. linux文件系统初始化过程(2)---挂载rootfs文件系统

    一.目的 本文主要讲述linux3.10文件系统初始化过程的第一阶段:挂载rootfs文件系统. rootfs是基于内存的文件系统,所有操作都在内存中完成:也没有实际的存储设备,所以不需要设备驱动程序 ...

  8. linux文件系统初始化过程(1)---概述

    术语表: struct task:进程 struct mnt_namespace:命名空间 struct mount:挂载点 struct vfsmount:挂载项 struct file:文件 st ...

  9. Linux系统配置VSFTP软件详解

    Linux系统配置VSFTP软件详解 出处 http://www.sudu.cn/service/detail.php?id=11656 vsftpd.conf 是vsftpd的配置文件,用来控制vs ...

随机推荐

  1. ArrayList方法源码分析

    本文将从ArrayList类的存储结构.初始化.增删数据.扩容处理以及元素迭代等几个方面,分析该类常用方法的源码. 数据存储设计 该类用一个Object类型的数组存储容器的元素.对于容量为空的情况,提 ...

  2. CentOS 7配置静态IP地址的两种方法 来自:互联网

    CentOS 7配置静态IP地址的两种方法 来自:互联网 时间:2021-01-12 阅读:4 如果你想要为CentOS 7中的某个网络接口设置静态IP地址,有几种不同的方法,这取决于你是否想要使用网 ...

  3. MyBatis 各种参数传递方式

    MyBatis参数传递方式 情况一:Mapper映射器接口方法参数只有一个且为基本类型 接口方法: public List<UserEntity> selectUserByAge(int ...

  4. x轴滚动

    #region 设置x轴滚动      XYDiagram diagram = (XYDiagram)chartRoomUserAnalysisHis.Diagram;      diagram.Ax ...

  5. JMeter36个内置函数及11个新增函数介绍

    JMeter内置了36个函数,这些函数可以通过函数助手进行编辑和测试.了解这些函数,不仅能提高JMeter的使用熟练度,也有助于知晓测试工具或测试框架通用的函数有哪些,在自主设计时,作为参考借鉴. J ...

  6. [论文阅读笔记] Structural Deep Network Embedding

    [论文阅读笔记] Structural Deep Network Embedding 本文结构 解决问题 主要贡献 算法原理 参考文献 (1) 解决问题 现有的表示学习方法大多采用浅层模型,这可能不能 ...

  7. Supervisor 开始

    Supervisor 是 Linux/Unix 操作系统上的进程管理工具.本文介绍了于 Ubuntu 18 上如何使用 Supervisor 开机启动.保活守护自己的服务进程. 安装 建议系统方式安装 ...

  8. Linux 2 的 Windows 子系统上发布 CUDA

    Linux 2 的 Windows 子系统上发布 CUDA 为响应大众需求,微软 宣布 在 2020 年 5 月的 建造 大会上推出了 建造 ( WSL 2 ) – GPU 加速功能.这一特性为许多计 ...

  9. 开源电路分享のFalling Star Board

    设计初衷 想自己做个能连网的时钟,结合RT-thread,显示个天气预报什么的,想想就挺有趣的.考虑到当前的芯片价格,和后续的设计,万一还有个啥奇妙的想法呢,就把这个做成了核心板. 一开始就只做了最小 ...

  10. Floyd最短路及路径输出

    引例 下图表示城市之间的交通路网,线段上的数字表示费用.如图,求$V_{1}$→$V_{n}$最短路径长度及路径 样例数据 输入 10 0 2 5 1 0 0 0 0 0 0 0 0 0 0 12 1 ...