系统初始化设置

# 设置主机名,永久修改,再次登陆生效
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

最新文章

  1. 委托 与 Lambda
  2. Linux下LDAPSearch的例子
  3. IOCP 浅析
  4. 使用itunes同步ios时丢失照片恢复
  5. ZOJ 3810 Pretty Poem 分类: ACM 2015-05-17 14:40 83人阅读 评论(0) 收藏
  6. c#基础语言编程-程序集和反射
  7. CocoaPod安装
  8. 【转】VS2010中文注释带红色下划线的解决方法
  9. 解析spring循环依赖策略
  10. 201521123061 《Java程序设计》第九周学习总结
  11. word中表格第一列序号的设置
  12. mysql 多列索引的生效规则
  13. Java - Spring MVC 实现跨域资源 CORS 请求
  14. 利用django信号实现计数功能
  15. NLog使用
  16. String类型转json 转JSONObject 转 JSONArray 以及 遍历
  17. ASP.NET Core 与 .NET Core 演变与基础概述
  18. 人的一生为什么要努力 &amp;1
  19. ubuntu中pycharm配置opencv2环境
  20. WebGL编程指南案例解析之平移和旋转的矩阵实现

热门文章

  1. MySQL TIMESTAMP(时间戳)详细解释
  2. 【C#/WPF】调节图像的HSL(色相、饱和度、明亮度)
  3. XF相对控件布局
  4. 【WPF】右下角弹出自定义通知样式(Notification)——简单教程
  5. js如何通过变量调用函数,函数名在变量里面
  6. QML中实现setTimeout和setInterval
  7. Interactive Data Display如何显示菜单?
  8. 处理 Windows Phone 应用中的“后退”按钮 (XAML)
  9. List&lt;T&gt;多字段排序的一个通用类
  10. hadoop(三)