ubuntu1604系统初始化

摘要:
1.初始化网络配置1.1.创建工作目录。在生产环境中,必须有一个固定的目录来存储一些安装软件和调试工具。否则,每个管理员都可以随意存储软件工具。服务器环境可以想象为mkdir-p/opt/{tools,scripts}mkdir-p/data/backupcd/opt/tools/install通用软件工具apt-geupdateapt-geinstalllrzszviimwgetcurlsoftelnet-t

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系统初始化》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇JSP 报错Unterminated --- 标签未关闭,检查<c:if>有没有关闭标签【激活码汇总】各种软件激活码整理 亲测可用下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

linux-基础命令

目录 文件管理 文件查看cat 更改文件权限chmod 改属主属组chown 对比文件diff 文件查看head/tail/more/less实时监控日志 文件移动更名mv 文件删除rm 文件分割split 新建文件touch 文件预设权限umask 文件查找which 文件复制cp 文件查找whereis 远程文件复制scp 文档编辑...

Zabbix安装部署

环境准备 OS:CentOS 7.2 64bit Zabbix版本:3.0.12 MySQL版本:5.6 注意:zabbix3.0相关要求 mysql5.0以上版本、apache1.3以上版本、php5.4以上版本。 版本选择 在版本选择建议选择官方技术支持时间较长(LTS)的稳定版本,从上图我我们可以看到没有最新最稳定的是Zabbix3.0...

Linux之防火墙配置

Centos 7 firewall : 1、firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status firewalld  开机禁用  : systemctl disable firewalld 开机启用  : sys...

修改/etc/profile文件

通常情况下,/etc/profile文件是只读的,直接用vi或gedit打开修改后是无法保存的。要修改profile,需要取得root权限,(使用gedit编辑)应该如下: $sudo gedit /etc/profile 或者 $sudo -s $gedit /etc/profile 这样打开profile文件,修改后就可以保存了。 让修改后的profi...

GitLab 部署及初始化

一、GitLab简介 GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。 二、GitLab 安装配置 (1)下载rpm安装包 wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-14.1.0-ce.0.el7....

高质量C++/C 编程指南一

首先,强烈推荐林锐博士这本《高质量C++/C 编程指南》,请花一两个小时认真阅读这本百页经书,你将会获益匪浅。草草看过,个人收获记录如下。 头文件的作用略作解释:(1)通过头文件来调用库功能。在很多场合,源代码不便(或不准)向用户公布,只要向用户提供头文件和二进制的库即可。用户只需要按照头文件中的接口声明来调用库功能,而不必关心接口怎么实现的。编译器会从库...