基于Linux虚拟镜像主机优化

一、主机名称

(一)查看当前主机名称

bash 复制代码
[root@harbor ~]# hostname
harbor
[root@harbor ~]# cat /etc/hostname 
harbor
[root@harbor ~]# 

(二)永久修改主机名称

1.永久修改主机名称,并立即生效,无需重启

bash 复制代码
#1,修改主机名:永久修改,并当时生效;
hostnamectl set-hostname harbor 

2.永久修改,重启生效;

bash 复制代码
vim /etc/hostname

(三)临时修改主机名称

bash 复制代码
hostname  harbor

二、字符集修改

(一)查看当前系统字符集

bash 复制代码
[root@harbor ~]# localectl 
   System Locale: LANG=zh_CN.UTF-8
       VC Keymap: cn
      X11 Layout: cn
[root@harbor ~]# 

(二)查看当前系统匹配字符集列表

bash 复制代码
[root@harbor ~]# localectl list-locales
aa_DJ
aa_DJ.iso88591
aa_DJ.utf8
aa_ER
aa_ER.utf8
aa_ER.utf8@saaho
aa_ER@saaho
aa_ET
aa_ET.utf8
。。。。。
。。。。。

(三)设置系统字符集

utf-8mb4:多了一些表情符号;utf-8:没有表情符号

bash 复制代码
[root@harbor ~]# localectl set-locale LANG=zh_CN.UTF-8
[root@harbor ~]# 

三、下载源优化

(一)配置阿里巴巴开源镜像

bash 复制代码
- BASE源优化
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

- epel源优化
curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

(二)验证查看下载源

bash 复制代码
[root@harbor ~]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
源标识                      源名称                                                     状态
base/7/x86_64               CentOS-7 - Base - mirrors.aliyun.com                       10,072
epel/x86_64                 Extra Packages for Enterprise Linux 7 - x86_64             13,791
extras/7/x86_64             CentOS-7 - Extras - mirrors.aliyun.com                        526
updates/7/x86_64            CentOS-7 - Updates - mirrors.aliyun.com                     6,173
repolist: 30,562
[root@harbor ~]# 

(三)安装常用的软件

bash 复制代码
yum -y install tree vim wget bash-completion bash-completion-extras lrzsz net-tools sysstat iotop iftop htop unzip nc nmap telnet bc psmisc httpd-tools bind-utils methogs expect dos2unix

#简单了解一下即可

vim #编辑文件

tree #显示目录结构

wget #下载

bash-completion bash-completion-extras #命令补全工具,重启、重连生效;

lrzsz #widows和linux两个主机传输文件使用的

sz 文件 #将虚拟机系统中的文件传输到宿主机上了

rz -E #将宿主机文件传输到虚拟机中;

unzip #压缩解压缩zip文件使用

nmap #端口扫描工具

dos2unix #windows文件的换行符:\r\n

#linux文件的换行符:\n

四、关闭安全软件

(一)关闭selinux

1.查看selinux服务状态

bash 复制代码
[root@harbor ~]# getenforce
Enforcing
[root@harbor ~]# 

2.临时关闭selinux

bash 复制代码
[root@harbor ~]# setenforce 0
[root@harbor ~]# getenforce 
Permissive

3.永久关闭selinux

bash 复制代码
#3,永久关闭selinux
[root@harbor~]# vim /etc/selinux/config 
........
7 SELINUX=disabled
........

(二)关闭firewalld

1.查看防火墙运行状态

bash 复制代码
[root@harbor ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

8月 08 19:55:18 harbor systemd[1]: Starting firewalld - dynamic firewall daemon...
8月 08 19:55:19 harbor systemd[1]: Started firewalld - dynamic firewall daemon.
8月 08 19:55:20 harbor firewalld[910]: WARNING: AllowZoneDrifting is enabled. This is ...ow.
8月 08 20:04:56 harbor systemd[1]: Stopping firewalld - dynamic firewall daemon...
8月 08 20:04:56 harbor systemd[1]: Stopped firewalld - dynamic firewall daemon.
Hint: Some lines were ellipsized, use -l to show in full.
[root@harbor ~]# 

2.临时关闭防火墙

bash 复制代码
[root@harbor~]# systemctl stop firewalld

3.永久关闭防火墙

bash 复制代码
[root@harbor~]# systemctl disable firewalld

systemctl disable 服务名 #禁止开机自动启动

systemctl enable 服务名 #设置开机自动启动

systemctl stop 服务名 #关闭服务

systemctl start 服务名 #开启服务

systemctl restart 服务名 #重启服务

systemctl status 服务名 #查看服务状态

五、sshd远程连接优化

(一)关闭GSSapi 和 反向解析

bash 复制代码
#有两处需要修改:1,关闭GSSapi验证方式;2,关闭远程连接的反向解析;(名称==>IP);
[root@harbor~]# vim /etc/ssh/sshd_config
 77 
 78 # GSSAPI options
 79 GSSAPIAuthentication no  #关闭GSSapi验证方式;
......
114 #ShowPatchLevel no
115 UseDNS no #关闭远程连接的反向解析;(名称==>IP);
116 #PidFile /var/run/sshd.pid

(二)重启sshd服务

bash 复制代码
#每次修改一个服务的配置文件之后,都需要重启这个服务,你修改的内容才会生效;
[root@harbor~]# systemctl restart sshd

六、时间同步

(一)调整时区

1.查看当前时区

bash 复制代码
[root@harbor ~]# timedatectl 
      Local time: 四 2024-08-08 20:57:21 CST
  Universal time: 四 2024-08-08 12:57:21 UTC
        RTC time: 四 2024-08-08 12:57:22
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
[root@harbor ~]# 

2.查看时区列表

bash 复制代码
[root@harbor ~]# timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
。。。。。。

3.设置时区

bash 复制代码
[root@harbor ~]#  timedatectl set-timezone Asia/Shanghai
[root@harbor ~]# 

(二)手动和定时同步时间

1.安装时间同步工具

bash 复制代码
#1,安装时间同步工具
[root@harbor~]# yum -y install ntpdate

2.手动同步时间

bash 复制代码
#2,与阿里云时间服务器进行同步
[root@harbor~]# ntpdate ntp.aliyun.com
[root@harbor~]# ntpdate ntp1.aliyun.com
24 Jul 09:35:08 ntpdate[1661]: adjust time server 203.107.6.88 offset 0.000770 sec

3.定时同步时间

bash 复制代码
#linux的定时任务文件
[root@harbor~]# crontab  -e
[root@harbor~]# vim /etc/crontab 
.....
# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
# 分 时 日 月 周 
*/5  *  *  *  *   ntpdate ntp1.aliyun.com &>/dev/null

4.查看当前时间

bash 复制代码
##查看当前时间
[root@harbor ~]# date
2024年 08月 08日 星期四 21:01:18 CST
##计算机硬件时间
[root@harbor ~]# clock  
2024年08月08日 星期四 21时01分21秒  -0.099902 秒
[root@harbor ~]# 
相关推荐
AI科技星3 小时前
从ZUFT光速螺旋运动求导推出自然常数e
服务器·人工智能·线性代数·算法·矩阵
迎仔3 小时前
A-总览:GPU驱动运维系列总览
linux·运维
tiantangzhixia3 小时前
Master PDF Linux 平台的 5.9.35 版本安装与自用
linux·pdf·master pdf
choke2333 小时前
软件测试任务测试
服务器·数据库·sqlserver
yyy的学习记录3 小时前
Ubuntu下urdf模型转换成proto模型
linux·运维·ubuntu
礼拜天没时间.3 小时前
自定义镜像制作——从Dockerfile到镜像
linux·docker·容器·centos·bash
xixingzhe23 小时前
ubuntu安装gitlab
linux·ubuntu·gitlab
临水逸3 小时前
一次路径穿越漏洞引发的NAS安全危机:飞牛fnOS漏洞深度剖析与用户自救指南
网络·安全·web安全
强风7943 小时前
Linux-传输层协议TCP
linux·网络·tcp/ip
狮驼岭的小钻风3 小时前
汽车V模型开发流程、ASPICE、汽车功能安全的基石是国际标准 ISO 26262
网络·安全·汽车