1.初始化网络配置

1.1.创建工作目录

  • 生产环境下必须有个固定的目录存放一些安装软件和调试工具,
  • 否则每个管理员都随意存放软件工具,服务器的环境可以想而知
mkdir -p /opt/{tools,scripts}
mkdir -p /data/backup
cd /opt/tools/
  • 安装常用软件工具
apt-get update
apt-get install lrzsz vim wget curl lsof telnet net-tools ntpdate tree screen iotop iftop

1.2.设置主机名和hosts解析

  • 修改服务器主机名
hostname demosrv-01
vi /etc/hostname
--------------------------------
demosrv-01
-------------------------------
  • 设置hosts域名解析
vi /etc/hosts
--------------------------------
192.168.1.200 demosrv-01
--------------------------------

1.3.设置固定IP地址和DNS域名解析

1.3.1.修改主机IP

  • 1)为网卡配置静态IP地址
sudo vim /etc/network/interfaces
--------------------------------------------
auto eth0
iface eth0 inet static
address 192.168.1.200
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 223.5.5.5
dns-nameservers 8.8.8.8
--------------------------------------------
# 重启网卡
sudo /etc/init.d/networking restart
  • 2)设定第二个IP地址(虚拟IP地址)
sudo vim /etc/network/interfaces
--------------------------------------------
auto eth0:1
iface eth0:1 inet static
address 192.168.1.201
netmask 255.255.255.0
gateway x.x.x.x
network x.x.x.x
broadcast x.x.x.x
--------------------------------------------
# 重启网卡:
sudo /etc/init.d/networking restart

1.3.2.设置DNS解析

vi /etc/resolv.conf
--------------------------------
nameserver 202.106.0.20
nameserver 8.8.8.8
--------------------------------
ip add
ping www.baidu.com

1.4.配置 apt 源(阿里云)

1.4.1.备份原始 apt 源配置文件

cp /etc/apt/sources.list /etc/apt/sources.list.ori

1.4.2.修改 apt 源配置文件(更换 apt 源)

vim /etc/apt/sources.list
----------------------------------
# aliyun
deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe
----------------------------------

1.4.3.更新源和软件版本

apt-get update
apt-get upgrade

1.4.4.复损坏的软件包

# 尝试卸载出错的包,重新安装正确版本的
sudo apt-get -f install

2.配置系统环境变量

2.1.修改记录的历史命令数量

echo "HISTSIZE=10000" >> /etc/profile
tail -1 /etc/profile

2.2.设置超时自动注销登陆

# 8h=28800s
echo " " >> /etc/profile
echo "# Auto-Logout for 4 hours by zhaoshuai on $(date +%F)." >> /etc/profile
echo "export TMOUT=28800" >> /etc/profile
tail -3 /etc/profile
source /etc/profile
echo $TMOUT

3.配置系统安全选项

3.1.修改 ssh 服务配置

  • 只监听IPv4端口,关闭GSSAPI秘钥认证,关闭DNS解析加速ssh连接

  • 手动修改配置文件

vim /etc/ssh/sshd_config
-----------------------------
ListenAddress 0.0.0.0
PasswordAuthentication no
GSSAPIAuthentication no
UseDNS no
-----------------------------
  • 命令行修改
echo "ListenAddress 0.0.0.0" >> /etc/ssh/sshd_config
echo "GSSAPIAuthentication no" >> /etc/ssh/sshd_config
echo "UseDNS no" >> /etc/ssh/sshd_config grep ListenAddress /etc/ssh/sshd_config
grep GSSAPIAuthentication /etc/ssh/sshd_config
grep UseDNS /etc/ssh/sshd_config
  • 重启sshd服务
/bin/systemctl restart  sshd.service
/bin/systemctl status sshd.service

3.2.关闭 selinux

  • 不需要

3.3.关闭防火墙

  • 内网一般不需要使用防火墙
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld

3.4.关闭其他不用的服务

  • 邮箱服务,CentOS7默认安装postfix,而不是sendmail
systemctl stop  postfix
systemctl disable postfix
systemctl status postfix
netstat -anptl

4.修改内核参数

4.1.修改文件句柄数

vim /etc/security/limits.conf
-----------------------------------
# 系统最大连接数
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
-----------------------------------

4.2.配置 TIME_WAIT 参数

  • 清理 TIME_WAIT 状态的连接
netstat -anptl|grep TIME_WAIT|wc -l
echo " " >> /etc/sysctl.conf
echo "# made by zhaoshuai for kill time_wait on $(date +%F)." >> /etc/sysctl.conf
echo "net.ipv4.tcp_syncookies = 1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_tw_reuse = 1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_tw_recycle = 1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_fin_timeout = 30" >> /etc/sysctl.conf
echo "net.ipv4.tcp_orphan_retries = 2" >> /etc/sysctl.conf
echo "net.ipv4.ip_local_port_range = 1024 65000" >> /etc/sysctl.conf
tail -8 /etc/sysctl.conf
sysctl -p
netstat -anptl|grep TIME_WAIT|wc -l

4.3.让系统自动回收缓存 cache

echo " ">>/etc/sysctl.conf
echo "# Automatic recovery memory on $(date +%F)">>/etc/sysctl.conf
echo "vm.extra_free_kbytes=209196">>/etc/sysctl.conf
sysctl -p

5.配置时间同步

  • 安装ntp服务并配置开机自启动
yum -y install ntp
systemctl enable ntpd
systemctl start ntpd
systemctl status ntpd
  • 手动进行时间同步
date
/usr/sbin/ntpdate ntp1.aliyun.com
  • 配置自动同步时间
echo "# made by zhaoshuai for sync time on $(date +%F)" >> /var/spool/cron/crontabs/root
echo '*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com > /dev/null 2>&1' >> /var/spool/cron/crontabs/root
crontab -l
  • 注意:
时区应该为CST为中部时区,如果是EST则为东部时区
安装CentOS系统时要去掉夏令时的选项,否则在夏令时的那一天会有时间的自动变换,
如果某个服务在时间上有要求就会导致该服务承载的业务出现问题,所以要关闭夏令时

END

ubuntu1604系统初始化的更多相关文章

  1. centos7 系统初始化脚本

    现在自己的本地虚拟机系统,直接安装的是centos7.2 mini版,安装完成发现好多东西都没有安装,所以写了一个简单的系统初始化脚本,让自己可以省一些力气,哈哈 人懒主要是. 下面贴出写的脚本,脚本 ...

  2. ssh下:系统初始化实现ServletContextListener接口时,获取spring中数据层对象无效的问题

    想要实现的功能:SSH环境下,数据层都交由Spring管理:在服务启动时,将数据库中的一些数据加载到ServletContext中缓存起来. 系统初始化类需要实现两个接口: ServletContex ...

  3. 详解linux系统的启动过程及系统初始化

    一.linux系统的启动流程 关于linux系统的启动流程我们可以按步进行划分为如下: POST加电自检 -->BIOS(Boot Sequence)-->加载对应引导上的MBR(boot ...

  4. Ztack学习笔记(2)-系统初始化分析

    main函数先执行初始化工作,包括硬件.网络层.任务等的初始化. 一 系统初始化 系统初始化函数主要完成内存分配.消息队列头.定时器.电源管理.任务系统及内存栈等的初始化,具体如下代码所示: //os ...

  5. Linux安装系统注意事项及系统初始化

      Linux安装系统注意事项 1.分区 学习用途: /boot:200M /swap :内存的1到2倍 /:根据需要分配大小,比如虚拟机下总空间是15G,那么可以分配8——10G跟/分区,如果是生产 ...

  6. ucos系统初始化及启动过程

    之前在ucos多任务切换中漏掉了一个变量, OSCtxSwCtr标识系统任务切换次数 主要应该还是用在调试功能中 Ucos系统初始化函数为OSInit(),主要完成以下功能 全局变量初始化 就绪任务表 ...

  7. centos系统初始化流程及实现系统裁剪

    Linux系统的初始化流程: POST:ROM+RAM BIOS: Boot Sequence MBR: 446:bootloader 64: 分区表 2: 5A kernel文件:基本磁盘分区 /s ...

  8. 【linux】系统初始化的shell脚本

    根据参考网上的一些文章,总结出来一个系统初始化的shell脚本 1.初始化脚本 #!/bin/bash cat << EOF +------------------------------ ...

  9. Saltstack生产案例之系统初始化

    把之前的配置打个包 zip -r salt.zip * 拷贝到/root/tools目录 博客园文件里面也保留一份,删除之前所有的salt配置文件重新开始 想 1,系统初始化 2,功能模块:设置单独的 ...

随机推荐

  1. copy running-config startup-config 与 copy startup-config running-config

    1.copy running-config startup-config 与 copy startup-config running-config 两者有什么不同???ANS:running-conf ...

  2. Redis数据结构及常用命令(草稿)

    通用命令 数据类型 string 字符 list 列表 set 集合 zset 有序集合 hash 散列(字典中的字典) bitmap 位图 hyperloglog

  3. 雪花算法(snowflake)的JAVA实现

    snowflake算法由twitter公司出品,原始版本是scala版,用于生成分布式ID,结构图: 算法描述: 最高位是符号位,始终为0,不可用. 41位的时间序列,精确到毫秒级,41位的长度可以使 ...

  4. 深入理解C语言 - 指针使用的常见错误

    在C语言中,指针的重要性不言而喻,但在很多时候指针又被认为是一把双刃剑.一方面,指针是构建数据结构和操作内存的精确而高效的工具.另一方面,它们又很容易误用,从而产生不可预知的软件bug.下面总结一下指 ...

  5. 33,Leetcode 搜索旋转排序数组-C++ 递归二分法

    题目描述 假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] ). 搜索一个给定的目标值,如果数组中存在这 ...

  6. nginx反向代理配置去除前缀

    (转载)原文链接:https://blog.csdn.net/gongchenyu/article/details/85960027 使用nginx做反向代理的时候,可以简单的直接把请求原封不动的转发 ...

  7. SQL -------- WHERE子句与AND,OR和NOT运算符结合使用。

    AND, OR and NOT  与 运算符中的且或非的意思相同 WHERE子句可以与AND,OR和NOT运算符结合使用. and 表示 查询的语句必须全部包含and 连接的两个或多个条件 or    ...

  8. 解决Docker服务无法正常启动

    重新docker服务报错如下: systemctl restart docker.service Cannot connect to the Docker datemon at tcp://0.0.0 ...

  9. [转帖]ZEROCONF是什么

    ZEROCONF是什么 xjsunjie关注0人评论9867人阅读2014-05-13 16:12:18 https://blog.51cto.com/xjsunjie/1410592 奇怪 两个文档 ...

  10. JS操作摄像头

    <script src="javascript/jquery-1.9.1.min.js"></script> <fieldset> <le ...