简单的linux系统学习笔记——06

主机优化

一、主机名优化

修改主机名 永久修改并当时生效
hostnamectl set-hostname 主机名

vim /etc/hostname   //永久修改,重启生效

临时生效,重启失效
hostname 主机名
--------------------------------------------------------------------------------

hostname命令拓展

hostname   //查看当前主机名称
--------------------------------------------------------------------------------
[root@haha ~]# hostname -i   //显示IPv4和ipv6
fe80::20c:29ff:fe8b:7efb%eth0 10.0.0.215
--------------------------------------------------------------------------------
[root@haha ~]# hostname -I   //只显示ipv4
10.0.0.215  

二、时间同步优化

目的:与用户时间保持统一

中国:东八区+8

1.调整时区

[root@haha ~]# timedatectl   //查看当前时区
      Local time: 三 2024-07-24 09:25:30 CST   //本地时间
  Universal time: 三 2024-07-24 01:25:30 UTC
        RTC time: 三 2024-07-24 01:25:29
       Time zone: Asia/Shanghai (CST, +0800)  //时区:亚洲/上海
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
--------------------------------------------------------------------------------
[root@haha ~]# timedatectl list-timezones  //查看时区列表
 --------------------------------------------------------------------------------
[root@haha ~]# timedatectl set-timezone Asia/Shanghai  //设置时区

2.调整时间=时间同步

1.安装时间同步工具
[root@haha ~]# yum -y install ntpdate
--------------------------------------------------------------------------------
2.与阿里云时间服务器同步
[root@haha ~]# ntpdate ntp.aliyun.com
24 Jul 09:35:19 ntpdate[1760]: adjust time server 203.107.6.88 offset -0.002402 sec

3.定时时间同步

[root@haha ~]# vim /etc/crontab

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# 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
*/1  *  *  *  *  root ntpdate ntp1.aliyun.com &>dev/null      // dev/null相当于黑洞放里面的东西都会被删

--------------------------------------------------------------------------------

查看当前时间是否同步成功
[root@haha ~]# date
2024年 07月 24日 星期三 09:47:12 CST
--------------------------------------------------------------------------------
计算机硬件时间同步
[root@haha ~]# clock
2024年07月24日 星期三 09时52分05秒  -0.179561 秒

三、下载源/yum源优化

就是将国外下载地址换成国内的

#1,前往阿里巴巴开源镜像站https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.59aa1b119TEZaL
--------------------------------------------------------------------------------
#-按照其介绍文档,下载阿里源
[root@haha ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2523  100  2523    0     0   7851      0 --:--:-- --:--:-- --:--:--  7859
--------------------------------------------------------------------------------
#epel源,特殊软件仓库
[root@haha ~]# curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
--------------------------------------------------------------------------------
验证查看下载源是哪里
[root@haha ~]# 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
--------------------------------------------------------------------------------
安装常用的软件
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 //编辑文件
bash-completion bash-completion-extras  //命令补全工具,重启,重连生效
wget  //下载
tree  //显示目录结构
lrzsz  //Windows和linux两个主机传输文件使用
nmap  //端口扫描工具
uzip  //压缩解压缩zip文件使用
dos2unix //Windows和linux文件转换

四、关闭安全软件

1.selinux关闭

1.查看selinux服务是否关闭还是开启
[root@haha ~]# getenforce
Enforcing   //开启状态


临时关闭
[root@haha ~]# setenforce 0
[root@haha ~]# getenforce
Permissive


永久关闭
[root@haha ~]# vim /etc/selinux/config 
.....
SELINUX=disabled
.....
重启系统,验证重启后依旧关闭selinux
[root@haha ~]# getenforce 
Disabled

2.firewalld 防火墙关闭

查看firewalld防火墙启动状态
[root@haha ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 三 2024-07-24 10:33:19 CST; 2min 52s ago


临时关闭
****[root@haha ~]# systemctl stop firewalld****
[root@haha ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since 三 2024-07-24 10:36:53 CST; 3s ago


永久关闭
[root@haha ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.


命令拓展
systemctl disable 服务名  //禁止开机自启动
systemctl enable  服务名  //设置开机自启动
systemctl stop    服务名  //停止服务
systemctl start   服务名  //开启服务
systemctl restart 服务名  //重启服务
systemctl status  服务名  //查看服务状态

五、字符集优化

目的:避免中文出现乱码

查看当前系统的字符集编码
[root@haha ~]# localectl
   System Locale: LANG=zh_CN.UTF-8
       VC Keymap: cn
      X11 Layout: cn
查看系统字符集列表
[root@haha ~]# localectl list-locales

设置系统字符集为中文utf8
[root@haha ~]# localectl set-locale LANG=zh_CN.UTF-8

****拓展****
utf-8mb4:多了好多表情符号
utf-8:没有表情符号

六、ssh远程连接

[root@haha ~]# vim /etc/ssh/sshd_config 
.....
79 GSSAPIAuthentication no   //关闭gssapi验证方式
.....
115 UseDNS no  //关闭远程连接的反向解析

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

06-完

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值