个人安装RHEL7需要做的事情

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

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

date -R
clock
hwclock
[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: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
[root@localhost ~]# timedatectl list-timezones|grep -i shanghai
Asia/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 ~]# hostname
localhost
[root@localhost ~]# hostname rhel7.example.com
[root@localhost ~]# hostname
rhel7.example.com
## 文件/etc/hostname,对应系统的静态的(static)主机名
[root@localhost ~]# cat /etc/hostname
localhost

## static主机名在/etc/hostname文件中指定.命令hostnamectl,可以修改此文件,显示系统的fully qualified主机名。
## 注意:RHEL7静态主机名保存在/etc/hostname文件.
##      在以前版本的RHEL,主机名作为一个变量保存在/etc/sysconfig/network 文件中。


## 原始3个主机名情况:
[root@localhost ~]# hostnamectl status --pretty  ”默认为空”

[root@localhost ~]# hostnamectl status --static
localhost
[root@localhost ~]# hostnamectl status --transient
localhost
[root@localhost ~]# cat /etc/hostname
localhost
[root@localhost ~]# hostname
localhost

## 使用hostname命令更改主机名:
[root@localhost ~]# hostname centos2
[root@localhost ~]# hostname
centos2
[root@localhost ~]# cat /etc/hostname
localhost
[root@localhost ~]# hostnamectl status --pretty

[root@localhost ~]# hostnamectl status --static
localhost
[root@localhost ~]# hostnamectl status --transient
centos2
## 结论:通过命令hostname,只能更改瞬态(transient)主机名,reboot后就会恢复到更改之前的主机名。

## 使用hostnamectl更改灵活的(pretty)主机名
[root@localhost ~]# hostnamectl --pretty set-hostname "James Computer"
[root@localhost ~]# hostnamectl status --pretty
James Computer
[root@localhost ~]# hostnamectl status --static
localhost
[root@localhost ~]# hostnamectl status --transient
centos2
## 结论:命令hostnamectl --[pretty| static| transient] set-hostname NEWNAME,更改特定的主机名,其他类型主机名不会受到影响。

[root@localhost ~]# hostnamectl set-hostname rhel7.example.com
[root@localhost ~]# hostname
rhel7.example.com
[root@localhost ~]# cat /etc/hostname
rhel7.example.com
[root@localhost ~]# hostnamectl status --pretty

[root@localhost ~]# hostnamectl status --static
rhel7.example.com
[root@localhost ~]# hostnamectl status --transient
rhel7.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/null
if [ $? != 0 ];then
   echo "No CD-ROM found, please insert it. try again !"
   exit
fi
mkdir -p /media/cdrom
df -T|awk '/iso9660/ {print $1}'|xargs -ti mount {} /media/cdrom
yum-config-manager --add-repo="file:///media/cdrom" 
echo 'gpgcheck=0' >>/etc/yum.repos.d/media_cdrom.repo
yum repolist

############################################################################################
## 安装autofs软件,并实现使用时自动mount光盘到/media/cdrom
## 由于上面的yum repo配置文件已经写好,可以直接使用,所以下面的配置仍用/media/cdrom挂载点。
## 以下配置使用indirect mount point mapping方式,目录的创建和删除的动作都由autofs完成,无需人工干预。
############################################################################################

automount配置脚本:(indirect mount point mapping方式)

#!/bin/bash
#
yum install autofs -y
echo '/media /etc/auto.cdrom' >/etc/auto.master.d/cdrom.autofs
echo 'cdrom -fstype=iso9660,ro :/dev/cdrom' >/etc/auto.cdrom
systemctl start autofs
systemctl enable autofs

##此项操作可选,删除cdrom目录。autofs在使用时会自动创建的
# rm -rf /media/cdrom   

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

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

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

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

gsettings get org.gnome.desktop.interface scaling-factor ##查看设置

5、关闭SElinux

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

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

## 临时关闭selinux方案
[root@rhel7 ~]# getenforce
Enforcing
[root@rhel7 ~]# setenforce 0
[root@rhel7 ~]# getenforce
Permissive

## 彻底关闭方案
[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 firewalld
systemctl enable firewalld
systemctl stop firewalld
systemctl disable firewalld

firewall-cmd --add-service=ftp --permanent
firewall-cmd --remove-service=ftp --permanent
firewall-cmd --add-port=3128/tcp
systemctl restart firewalld
firewall-cmd --state

个人安装环境,主要用于测试开发与学习,还是关了吧
systemctl stop firewalld
systemctl disable firewalld

7、kdump测试

/etc/kdump.conf (select where you want the dump to go) 

## to crash the system
echo "c" > /proc/sysrq-trigger 

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

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

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

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

 

转载于:https://my.oschina.net/xinghaitao/blog/1015587

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值