linux系统初始化步骤--新机器配置(踩坑)

linux系统初始化

1.关闭所有防火墙

#临时关闭selinux
[root@chenjian ~]# setenforce 0
setenforce: SELinux is disabled
[root@chenjian ~]# getenforce
Disabled
#永久关闭selinux
[root@chenjian ~]# grep '^SELINUX' /etc/selinux/config 
SELINUX=disabled
SELINUXTYPE=targeted
# 更改Linux主机名
[root@chenjian ~]# hostnamectl set-hostname 主机名
# 需要reboot重启
[root@chenjian ~]# reboot
# 关闭防火墙firewalld,以及清空当前所有的 防火墙规则
[root@chenjian ~]# iptables -F
[root@chenjian ~]# systemctl stop firewalld
[root@chenjian ~]# systemctl disable firewalld

2.加速ssh连接(根据需求是否加速?我这里选择不操作此步,有可能把22端口搞崩了)

默认ssh连接的时候,可能比较慢,因为它默认进行了dns解析,关闭这个功能

# 编辑/etc/ssh/sshd_config,如下所示
[root@chenjian ~]# grep -Ei 'gssapiauth|usedns|pidfile' /etc/ssh/sshd_config 
GSSAPIAuthentication no
UseDNS no
#PidFile /var/run/sshd.pid
UseDNS no

改了配置文件,务必要重启
此时发现sshd服务挂了,无法远程连接了
找到它的物理服务器,想办法登录服务器本身,重新开启sshd服务

[root@chenjian ~]# systemctl restart sshd

3.优化PS1变量

让命令提示符显示的更有好些,每一个用户,登录该机器,都可以使用这个PS1变量

[root@chenjian ~]# echo  'export PS1="[\[\e[34;1m\]\u@\[\e[0m\]\[\e[32;1m\]\H\[\e[0m\] \[\e[31;1m\]\w\[\e[0m\]]\\$"'   >> /etc/profile

在这里插入图片描述

4.yum源优化

一个新机器,无法安装各种软件,因此配置阿里云的默认仓库,以及epel仓库
可以安装绝大多数软件

# 1.备份旧的默认repo
[root@chenjian ~]#cd /etc/yum.repos.d/
[root@chenjian /etc/yum.repos.d]#mkdir bakrepo ;mv *.repo bakrepo/
# 2.生成新的repo文件,wget在线下载资源
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
yum clean all # 清空原有的yum缓存
yum makecache # 生成新的yum源,便于加速软件下载

5.安装基础软件

因为你是最小化安装的系统,缺少很多基础软件依赖,安装即可

yum install -y tree wget bash-completion bash-completion-extras lrzsz net-tools sysstat iotop iftop htop unzip telnet ntpdate lsof    

6.关闭邮件告警

你所有的操作,都会被linux内置的邮件服务器记录,不断的写入 /var/log下的日志文件 可能会占用无用的磁盘

echo 'unset mailcheck' >> /etc/profile
source /etc/profile

7.配置时间同步定时任务,确保时间机器正确

你刚装好的机器,时间是错的

# 1.检查crontab服务是否运行
[root@chenjian ~]#systemctl status crond

# 2.写入定时任务语句
root@chenjian ~]#crontab -e 
* * * * * /usr/sbin/ntpdate time1.aliyun.com > /dev/null 2>&1

# 3.查看定时任务
[root@chenjian ~]#crontab -l
# 4.检查书写的定时任务
[root@chenjian ~]#cat /var/spool/cron/root 
* * * * * /usr/sbin/ntpdate time1.aliyun.com > /dev/null 2>&1

8.关闭swap分区

取消swap的功能,不适用这个从磁盘获取而来的部分内存容量,因为效率太差,企业里的服务器内存都巨大,有钱

swapoff -a
# 需要关闭swap的文件系统开机挂载,注释掉关于swap的信息即可
[root@chenjian ~]#vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Apr 18 12:41:32 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=4b434f73-2809-489d-ac02-8a5e7803abd9 /boot                   xfs     defaults        0 0
#/dev/mapper/centos-swap swap                    swap    defaults        0 0

好了,完成上面的8步后,这台新的Linux机器的初始化操作就全部完成了,可以部署和使用任何的应用和软件,基本不会出现什么大的问题。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值