侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

个人安装RHEL7需要做的事情

2023-11-04 星期六 / 0 评论 / 0 点赞 / 28 阅读 / 14083 字

安装系统后必做的几件事: 1、检查和调整时区、时间、主机名 date -Rclockhwclock[root@localhost ~]# timedatectl Local time: S

安装系统后必做的几件事:

1、检查和调整时区、时间、主机名
 

date -Rclockhwclock[root@localhost ~]# timedatectl      Local time: Sat 2017-06-24 17:42:53 CST  Universal time: Sat 2017-06-24 09:42:53 UTC        RTC time: Sat 2017-06-24 09:42:53       Time zone: Asia/Shanghai (CST, +0800)     NTP enabled: yesNTP synchronized: no RTC in local TZ: no      DST active: n/a[root@localhost ~]# timedatectl list-timezones|grep -i shanghaiAsia/Shanghai[root@localhost ~]# timedatectl set-timezone  Asia/Shanghai[root@localhost ~]# timedatectl set-time YYYY-MM-DD hh:mm:ss[root@localhost ~]# timedatectl set-time YYYY-MM-DD[root@localhost ~]# timedatectl set-time hh:mm:ss

 


在RHEL或CentOS中,有三种定义的主机名: 静态的(static),瞬态的(transient),灵活的(pretty)。
The hostname command displays or temporarily modifies the system's fully qualified host name.

.

fully qualified host name=fully qualified domain name
FQDN (fully qualified domain name,完全限定域名)

.

## A static host name may be specified in the /etc/hostname file. The hostnamectl command is used to modify this file and may be used to view the status of the system's fully qualified host name.

## 注意:静态主机名保存在/etc/hostname文件.以前版本的Red Hat Enterprise Linux作为一个变量保存在/etc/sysconfig/network 文件中。

 

## 命令hostname,显示或临时更改系统的fully qualified主机名。 ## 命令hostname,对应系统的瞬态的(transient)主机名[root@localhost ~]# hostnamelocalhost[root@localhost ~]# hostname rhel7.example.com[root@localhost ~]# hostnamerhel7.example.com## 文件/etc/hostname,对应系统的静态的(static)主机名[root@localhost ~]# cat /etc/hostnamelocalhost## static主机名在/etc/hostname文件中指定.命令hostnamectl,可以修改此文件,显示系统的fully qualified主机名。## 注意:RHEL7静态主机名保存在/etc/hostname文件.##      在以前版本的RHEL,主机名作为一个变量保存在/etc/sysconfig/network 文件中。## 原始3个主机名情况:[root@localhost ~]# hostnamectl status --pretty  ”默认为空”[root@localhost ~]# hostnamectl status --staticlocalhost[root@localhost ~]# hostnamectl status --transientlocalhost[root@localhost ~]# cat /etc/hostnamelocalhost[root@localhost ~]# hostnamelocalhost## 使用hostname命令更改主机名:[root@localhost ~]# hostname centos2[root@localhost ~]# hostnamecentos2[root@localhost ~]# cat /etc/hostnamelocalhost[root@localhost ~]# hostnamectl status --pretty[root@localhost ~]# hostnamectl status --staticlocalhost[root@localhost ~]# hostnamectl status --transientcentos2## 结论:通过命令hostname,只能更改瞬态(transient)主机名,reboot后就会恢复到更改之前的主机名。## 使用hostnamectl更改灵活的(pretty)主机名[root@localhost ~]# hostnamectl --pretty set-hostname "James Computer"[root@localhost ~]# hostnamectl status --prettyJames Computer[root@localhost ~]# hostnamectl status --staticlocalhost[root@localhost ~]# hostnamectl status --transientcentos2## 结论:命令hostnamectl --[pretty| static| transient] set-hostname NEWNAME,更改特定的主机名,其他类型主机名不会受到影响。[root@localhost ~]# hostnamectl set-hostname rhel7.example.com[root@localhost ~]# hostnamerhel7.example.com[root@localhost ~]# cat /etc/hostnamerhel7.example.com[root@localhost ~]# hostnamectl status --pretty[root@localhost ~]# hostnamectl status --staticrhel7.example.com[root@localhost ~]# hostnamectl status --transientrhel7.example.com## 结论:命令hostnamectl set-hostname NEWNAME,(不指定设置哪一个主机名),三个名字都会受到影响:## static和transient会更改为当前值;pretty会恢复到默认值(本例中默认值为空)

有关主机名方面总结:
1、RHEL/Centos有三个与主机相关的名字:静态的(static),瞬态的(transient),灵活的(pretty)。
3个不同的主机名: 
pretty ,主机名可以用所用种类字符。(e.g. "Lennart's Laptop")
static ,在内核启动初始化时的主机名(e.g."lennarts-laptop") ,主机名要遵从作为互联网域名同样的字符限制规则。
transient ,默认是从网络配置中收到的主机名,主机名要遵从作为互联网域名同样的字符限制规则。
另外,如果static设置并生效,基本就没有transient啥事了。 
2、使用命令hostname查看的主机名,在重启后可能会发生变化。要么看一下/etc/hostname,要么直接用hostnamectl直接查看静态主机名。这是个坑......,比如你要重启一个系统或调整一个重要的参数,hostname查到的仅仅是临时的名字,你将会弄错需要调整的对象(shutdown一个错误的系统,那是事故,也是工程师的耻辱呀)。
3、命令hostnamectl不会自动更新/etc/hosts,如果使用这个文件作为本地解析,修改主机名一定要更新这个文件。(linux有些是有些土鳖,更改主机名和系统IP的工具(包括图形化的)都不会自动更新/etc/hosts。
4、在实际使用中,建议静态的(static),瞬态的(transient)都使用一个名字。
5、将hostnamectl别名处理,可以同时显示三个名字,确保没有问题。

 

2、配置网络和默认解析(/etc/hosts)

一般安装时,建议安装server GUI,所以默认就启动到图形化界面。对于网络的配置,如果不那么熟悉的话,直接用图形化方式。
有些童鞋认为用图形化方式太low,其实不然,RHEL7调整了很多内容,比如使用NetworkManager管理网络,但是与原有的network还是有一点点兼容和接管方面的问题,比如更改配置文件/etc/sysconfig/network-script/ifcfg-xxx的配置,NetworkManager是无法自动获知的,需要通知该守护进程,而且需要网络重连才能生效使用,期待后面的版本会有改善吧。

其实大家想开些,层出不穷的软件发布,不是比谁更复杂,是比谁更贴近应用贴近用户,也就是说设置的易用性很重要,所以iptables终将被firewalld取代的原因就在于此。

.

在这里顺便吐槽一下,下面设置要点3,如果更改网络,特别配置的是静态(Manual方式)的地址,系统应该自动添加或更新/etc/hosts,如果更改系统IP导致解析有问题,影响应用使用,岂不是更low,难道不是吗?

.

主要有三个要点:

  1. 在RHEL桌面的顶栏(可以理解为windows的任务栏)选择wired-->wired settings,先将网络打开(右上角设置为on),默认是dhcp,顺便记录一下网管和DNS。之前就想当然的认为就是该虚拟网段最后一位为1的地址,结果是192.168.xx.2。然后右下角setting(⚙️)该界面ipv4处进行Manual方式的设定


  2. 在Identity页面,将connect automatically ☑️,其实就是ONBOOT=yes
  3. 将主机名和IP更新至 /etc/hosts
    echo '192.168.85.139     rhel7.example.com' >>/etc/hosts

     

3、配置autofs,并配置光盘镜像的yum源
 

光盘yum源配置脚本:#!/bin/bash#df -T|grep iso9660 >/dev/nullif [ $? != 0 ];then   echo "No CD-ROM found, please insert it. try again !"   exitfimkdir -p /media/cdromdf -T|awk '/iso9660/ {print $1}'|xargs -ti mount {} /media/cdromyum-config-manager --add-repo="file:///media/cdrom" echo 'gpgcheck=0' >>/etc/yum.repos.d/media_cdrom.repoyum repolist############################################################################################## 安装autofs软件,并实现使用时自动mount光盘到/media/cdrom## 由于上面的yum repo配置文件已经写好,可以直接使用,所以下面的配置仍用/media/cdrom挂载点。## 以下配置使用indirect mount point mapping方式,目录的创建和删除的动作都由autofs完成,无需人工干预。############################################################################################automount配置脚本:(indirect mount point mapping方式)#!/bin/bash#yum install autofs -yecho '/media /etc/auto.cdrom' >/etc/auto.master.d/cdrom.autofsecho 'cdrom -fstype=iso9660,ro :/dev/cdrom' >/etc/auto.cdromsystemctl start autofssystemctl enable autofs##此项操作可选,删除cdrom目录。autofs在使用时会自动创建的# rm -rf /media/cdrom   

4、对于现在高分屏幕优化设置

以下操作专治瞎眼症,现在电脑配置越来越高,屏幕分辨率动辄2560x1600,字体显示太小,根本看不清楚,完全是瞎眼的节奏。要么,默认分辨率,那个模糊呀,对不起高分屏的电脑。

如果是虚拟机安全,开启Retina显示,然后设置一下命令,类似调整windows HiDPI

gsettings set org.gnome.desktop.interface scaling-factor 2 ##默认是1startx or reboot ##建议系统重启启动一下gsettings get org.gnome.desktop.interface scaling-factor ##查看设置

5、关闭SElinux

谁都承认selinux有用,但是用linux做生产的企业,那都不是10台8台,数以百计,太多了真的没有功夫帮业务或事研发处理selinux相关的安全问题,所以一概关闭。

注意:如果有童鞋需要考红帽的相关认证,一定不要关闭,考试这个部分还是要考的,但是在中国实际使用环境确实用的不多。

## 临时关闭selinux方案[root@rhel7 ~]# getenforceEnforcing[root@rhel7 ~]# setenforce 0[root@rhel7 ~]# getenforcePermissive## 彻底关闭方案[root@rhel7 /]# cat /etc/selinux/config # This file controls the state of SELinux on the system.# SELINUX= can take one of these three values:#     enforcing - SELinux security policy is enforced.#     permissive - SELinux prints warnings instead of enforcing.#     disabled - No SELinux policy is loaded.SELINUX=enforcing# SELINUXTYPE= can take one of three two values:#     targeted - Targeted processes are protected,#     minimum - Modification of targeted policy. Only selected processes are protected. #     mls - Multi Level Security protection.SELINUXTYPE=targeted 将SELINUX=enforcing,更改为SELINUX=disabled注意:此项更改,需要重启系统

6、关闭防火墙

原因同上,这个没有啥道理可言。作为系统维护部门,与网络安全部门搞好协调沟通,确保业务使用端口与网络安全设置相匹配已经不易了,如果还涉及与其他兄弟地区机房的设备连接,整个是一个耗时费力的过程。所以一般作为业务的发起端,一般都不在设置防火墙方面的设置限制了。

比如,曾经有一个生产事故,就是因为维护人员不小心开启了SUSE防火墙,导致所有连接中断,默认防火墙规则拒绝一切,也是ssh也无法连接,导致无法登录,无从检查,导致无故影响业务数小时。这里面有两个问题值得考虑:1、SUSE防火墙命令行设计问题,命令行开启一个应用,起码要加上enable 或 on之类的选项。避免误操作带来的灭顶之灾。2、默认防火墙规则,连比较安全的ssh也停了,对于现在大都没有console的主机,ssh不能登录,让管理人员怎么进行排查。到机房,接上显示器和键盘,太费时间了。3、开启本机防火墙的必要性,因为安全规范的要求,企业网络一定设置了重重堡垒,主要靠硬件防火墙,系统内部再设置一层,除了延缓对外通信速度,还能其他好处吗?(如果小企业或是没有外围硬件防火墙,而且还要连入外网的,还是老老实实打开防火墙吧)

firewalld相关的操作命令:systemctl start firewalldsystemctl enable firewalldsystemctl stop firewalldsystemctl disable firewalldfirewall-cmd --add-service=ftp --permanentfirewall-cmd --remove-service=ftp --permanentfirewall-cmd --add-port=3128/tcpsystemctl restart firewalldfirewall-cmd --state个人安装环境,主要用于测试开发与学习,还是关了吧systemctl stop firewalldsystemctl disable firewalld

7、kdump测试

/etc/kdump.conf (select where you want the dump to go) ## to crash the systemecho "c" > /proc/sysrq-trigger 

作为将来可能成为生产环境的系统,需要测试一下kdump是否能够生产,避免突发情况无法生产dump日志,导致无从下手。

kdump,除了设置合适的内存空间大小,还是进行测试数据存盘。因为当前server为了确保根盘的可靠性,都设置有raid卡,进行raid后再安装系统,在kdump产生后,可能存在kdump无法写入raid磁盘的问题,所以需要测试。而且想过主机硬件固件升级后,一定要测试kdump情况。

8、如果是虚拟机,做一个快照

9、想到后再增加吧,好久没有重新安装了

 

广告 广告

评论区