基于Linux虚拟镜像主机优化

一、主机名称

(一)查看当前主机名称

[root@harbor ~]# hostname
harbor
[root@harbor ~]# cat /etc/hostname 
harbor
[root@harbor ~]# 

(二)永久修改主机名称

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

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

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

vim /etc/hostname

(三)临时修改主机名称

hostname  harbor

二、字符集修改

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

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

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

[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:没有表情符号

[root@harbor ~]# localectl set-locale LANG=zh_CN.UTF-8
[root@harbor ~]# 

三、下载源优化

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

- 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

(二)验证查看下载源

[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 ~]# 

(三)安装常用的软件

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服务状态

[root@harbor ~]# getenforce
Enforcing
[root@harbor ~]# 

2.临时关闭selinux

[root@harbor ~]# setenforce 0
[root@harbor ~]# getenforce 
Permissive

3.永久关闭selinux

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

(二)关闭firewalld

1.查看防火墙运行状态

[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.临时关闭防火墙

[root@harbor~]# systemctl stop firewalld

3.永久关闭防火墙

[root@harbor~]# systemctl disable firewalld


systemctl disable 服务名    #禁止开机自动启动
systemctl enable  服务名    #设置开机自动启动
systemctl stop    服务名    #关闭服务
systemctl start   服务名    #开启服务
systemctl restart 服务名    #重启服务
systemctl status  服务名    #查看服务状态

 五、sshd远程连接优化

(一)关闭GSSapi 和 反向解析

#有两处需要修改: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服务


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

六、时间同步

(一)调整时区

1.查看当前时区

[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.查看时区列表

[root@harbor ~]# timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
。。。。。。

3.设置时区

[root@harbor ~]#  timedatectl set-timezone Asia/Shanghai
[root@harbor ~]# 

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

1.安装时间同步工具

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

2.手动同步时间

#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.定时同步时间

#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.查看当前时间

##查看当前时间
[root@harbor ~]# date
2024年 08月 08日 星期四 21:01:18 CST
##计算机硬件时间
[root@harbor ~]# clock  
2024年08月08日 星期四 21时01分21秒  -0.099902 秒
[root@harbor ~]# 

  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值