系统初始化设置

# 设置主机名,永久修改,再次登陆生效
hostnamectl set-hostname xxxxx # 安装eprl源,常用命令
yum install -y wget && \
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo && \
yum -y install bash-completion telnet nmap tree net-tools ntpdate && \ # 查看时区,同步时间
timedatectl set-timezone Asia/Shanghai 修改时区命令
ntpdate hk.ntp.org.cn 同步时间 # 优化文件描述符
cat >>/etc/security/limits.conf<<EOF
root soft nofile
root hard nofile
* soft nofile
* hard nofile
EOF
ulimit -n # 查看 # 防火墙设置
添加允许访问的端口
firewall-cmd --zone=public --add-port=/tcp --permanent 添加允许访问的服务
firewall-cmd --permanent --add-service https 对指定IP或某个网段开放端口,允许192.168.142.166和192.168.224./24访问5432端口
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.224.0/" port protocol="tcp" port="" accept" 重新加载防火墙,防火墙规则生效
firewall-cmd --reload # 关闭防火墙,如果需要
systemctl stop firewalld.service && systemctl disable firewalld.service # 关闭selinux
setenforce && sed '7s#enforcing#disabled#g' /etc/selinux/config -i # 关闭ssh解析
sed -i.bak 's@#UseDNS yes@UseDNS no@g;s@^GSSAPIAuthentication yes@GSSAPIAuthentication no@g' /etc/ssh/sshd_config
systemctl restart sshd # 目录规划
/server/scripts/ 脚本存放目录
/server/tools/ 安装包存放目录
/usr/local/ 服务安装目录
/backup/ 备份目录 # ssh 白名单规则
在 /etc/hosts.allow 设置,允许连接的IP
sshd:167.179.49.12
sshd:192.168.224.0/ 在/etc/hosts.deny 设置,拒绝所有的连接
echo "sshd:all" >> /etc/hosts.deny

Centos7 系统初试化脚本

#!/bin/bash
yum install -y wget && \
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo && \
yum -y install vim wget bash-completion lrzsz nmap tree nc net-tools htop iotop iftop psmisc ntpdate && \
systemctl stop firewalld.service && systemctl disable firewalld.service
#setenforce 0 && sed '7s#enforcing#disabled#g' /etc/selinux/config -i
#优化文件描述符

echo -e "* soft nofile 65535\n* hard nofile 65535" >> /etc/security/limits.conf

ulimit -n 65535

#内核优化
cat >>/etc/sysctl.conf<<EOF
net.ipv4.tcp_fin_timeout = 2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_keepalive_time = 600
net.ipv4.ip_local_port_range = 4000 65000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.route.gc_timeout = 100
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.core.somaxconn = 16384
net.core.netdev_max_backlog = 16384
net.ipv4.tcp_max_orphans = 16384
EOF
sysctl -p
sed -i.bak 's@#UseDNS yes@UseDNS no@g;s@^GSSAPIAuthentication yes@GSSAPIAuthentication no@g' /etc/ssh/sshd_config
systemctl restart sshd
echo '* * * * * root /usr/sbin/ntpdate ntp1.aliyun.com' >>/etc/crontab

Centos7 系统初试化脚本的更多相关文章

  1. CentOS7.5 系统最小化安装与初始化配置

    CentOS7.5 系统最小化安装与初始化配置 1.安装标准化的系统 1.1.系统安装期间的语言 选择:中文-简体中文,安装完成也会默认支持中文输出,便于管理 1.2.时区选择 亚洲上海,CST时区( ...

  2. 基于CentOS7系统添加自定义脚本服务及参数说明【转】

    概述 centos6如果要添加自定义脚本服务只需要把脚本放到/etc/init.d然后授权后用chkconfig添加后就可以管理了,那么centos7又是怎么添加自定义脚本服务呢? CentOS7添加 ...

  3. CentOS7 系统服务器初始化配置、安全加固、内核升级优化常用软件安装的Shell脚本分享

    转载自:https://www.bilibili.com/read/cv13875630?spm_id_from=333.999.0.0 描述: 适用于企业内部 CentOS7 系列操作服务器初始化. ...

  4. centos7系统下nginx安装并配置开机自启动操作

    准备工作 我的centos7系统是最小化安装的, 缺很多库, 首先安装必须的运行库 ? 1 2 3 4 5 6 7 8 9 10 11 yum install wget gcc gcc-c++ pcr ...

  5. 使用Xshell5连接虚拟机VMware中安装的CentOS7系统

    使用Xshell5连接VMware中安装的CentOS7系统 准备材料 Xshell 下载地址 VMware Workstation 12 Pro 下载地址 CentOS 7 64位系统 下载地址 安 ...

  6. CentOS7系统 ansible自动化部署多台服务器部署

    CentOS7系统 ansible自动化部署多台服务器部署   Ansible工作机制  从图中可以看出ansible分为以下几个部份: 1> Control Node:控制机器2> In ...

  7. Centos7系统特性之systemd

    1.centos系列的系统启动流程(内核级别的启动流程): POST(加电自检)---> Boot Sequence(BIOS)---> Boot loader (MBR)---> ...

  8. centos7最小安装初始化脚本

    #!/bin/bash #zhangsen #lovexlzs@qq.com if [[ "$(whoami)" != "root" ]]; then exit ...

  9. 基于CentOS7系统一键配置Aria2 实现服务器离线下载工具

    我们有些网友购买的海外VPS主机并不是用来做网站的,而是用来作为下载资源工具使用的.确实用这样的工具搭建之后是比本地下载速度快,因为有些资源.软件等是海外资源,而且挂载在服务器上不占用本地的资源.在这 ...

随机推荐

  1. 微信小程序知识集锦

    1.自定义属性/获取属性值 自定义属性: <view bindtap='shopPost' data-myid='item.goods_id' ></view> 获取属性: s ...

  2. Get and Post(Unity3D六个发展)

    猴子原创,欢迎转载. 转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢! 原文地址: http://www.cocos2dev.com/?p=565 unity3d中的www ...

  3. .net reactor 学习系列(一)---.net reactor介绍

    原文:.net reactor 学习系列(一)---.net reactor介绍       学习.net已经一年多了,从语言的编写到框架类库的运用再到.net三大解决方案的了解(WF,WCF,WPF ...

  4. Android Ant 和 Gradle 包装工艺和效率控制

    一个.Ant 包:(下载ant.配置环境变量不说) 1.进入命令行模式,并切换到项目文件夹,运行例如以下命令为ADT创建的项目加入ant build支持: android update project ...

  5. node.js学习笔记之json数据转string

    Node.js中的JSON问题   var str = '{"dir":"kunhony","param":"archive&qu ...

  6. MVC CRUD 的两种方法

    //Index.cshtml @model IQueryable<MvcExam2.Models.Product>@{    Layout = null;}<!DOCTYPE htm ...

  7. Wpf发送接收 win32消息

    #region WPF发送和接收win32消息 public const int WM_GETTEXT = 0x0D; public const int WM_SETTEXT = 0x0C; publ ...

  8. Win8Metro(C#)数字图像处理--2.21二值图像腐蚀

    原文:Win8Metro(C#)数字图像处理--2.21二值图像腐蚀  [函数名称] 二值图像腐蚀函数CorrosionProcess(WriteableBitmap src) [算法说明] 二值 ...

  9. 编译时MSIL注入--实践Mono Cecil(1)

    原文:编译时MSIL注入--实践Mono Cecil(1) 紧接上两篇浅谈.NET编译时注入(C#-->IL)和浅谈VS编译自定义编译任务—MSBuild Task(csproject),在第一 ...

  10. Docker笔记03-docker 网络模式

    docker网络模式分为5种 Nat (Network Address Translation) Host other container none overlay 第一种 Nat模式 docker的 ...