1. 了解系统信息
# 查看系统发行版本信息
[root@node ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
# 查看系统架构信息
[root@node ~]# uname -a
Linux node 3.10.0-1062.12.1.el7.x86_64 #1 SMP Tue Feb 4 23:02:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Linux: 操作系统类别
node: 主机名
3.10.0-1062.12.1.el7.x86_64: 内核版本
#1 SMP Tue Feb 4 23:02:59 UTC 2020: 发行时间
x86_64 x86_64 x86_64: 32位还是64位
GNU/Linux: 属于哪个项目
# 上面的信息可以单独查看
# -a,--all: print all information, in the following order,except omit -p and -i if unknown:
# -s,--kernel-name: print the kernel name
# -n,--nodename: print the network node hostname
# -r,--kernel-release: print the kernel release
# -v,--kernel-version: print the kernel version
# -m,--machine: print the machine hardware name
# -p,--processor: print the processor type or "unknown"
# -i,--hardware-platform: print the hardware platform or "unknown"
# -o,--operating-system: print the operating system
[root@node ~]# uname -s
Linux
[root@node ~]# uname -n
node
[root@node ~]# uname -r
3.10.0-1062.12.1.el7.x86_64
[root@node ~]# uname -m
x86_64
[root@node ~]# uname -p
x86_64
[root@node ~]# uname -i
x86_64
[root@node ~]# uname -o
GNU/Linux
# 这些选项可以组合使用
[root@node ~]# uname -nri
node 3.10.0-1062.12.1.el7.x86_64 x86_64
2. 网络配置
2.1 设置静态IP地址
修改/etc/sysconfig/network-scripts/ifcfg-ens33
文件,作如下修改:
# 修改的内容
BOOTPROTO=static
ONBOOT=yes
# 新增的内容:
NM_CONTROLLED=no # 不使用NetworkManager来管理网络
# 设置静态IP
IPADDR=192.168.152.101
# 设置网关IP
GATEWAY=192.168.152.2
# 设置阿里云的DNS
DNS1=223.5.5.5
# 设置子网掩码
NETMASK=255.255.255.0
# 删除的内容(可选)
# 假如你的虚拟机还要被克隆,那么删除UUID这个配置
UUID=XXXXXXXXXXXXXXXXXXXX
说明:这个文件名称为ifcfg-ensxx
,每个人的虚拟机中这个文件的最后两位数字可能不一样,可能是33或者32或者其他
保存退出后,停止NetworkManager服务、禁用NetworkManager服务并重启网络服务
systemctl stop NetworkManager.service
systemctl disable NetworkManager.service
systemctl restart network
2.2 配置DNS
在2.1 设置静态IP地址中,在/etc/sysconfig/network-scripts/ifcfg-ens33
文件中已经添加了DNS服务地址:
DNS1=223.5.5.5
那么重启网络服务后,查看/etc/resolv.conf
文件就可以看到增加的DNS服务地址:
[hadoop@beh01 ~]$ sudo cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 223.5.5.5
而如果你没有在/etc/sysconfig/network-scripts/ifcfg-ens33
文件中配置DNS,那么可以直接在/etc/resolv.conf
文件中添加,格式为nameserver DNS地址
,CentOS-7最多支持3个NDS地址,即使配置超过3个,多余的也不起作用
建议在/etc/sysconfig/network-scripts/ifcfg-ens33
中配置DNS并重启网络服务来修改NDS的配置
2.3 修改主机名
编辑/etc/hostname
文件,设置主机名,例如我的主机名为beh01
[hadoop@beh01 ~]$ sudo cat /etc/hostname
beh01
假如你在安装虚拟机的时候,在UI界面配置了主机名,那么这里就不需要在额外配置了。

2.4 配置主机名与IP地址的映射
编辑/etc/hosts
文件,增加你的IP地址和主机名的映射
[hadoop@beh01 ~]$ sudo cat /etc/hosts
127.0.0.1 localhost
::1 localhost
192.168.152.101 beh01
同时在windows的C:\Windows\System32\drivers\etc\hosts
文件中也增加同样的内容:192.168.152.101 beh01
测试网络配置:
- 查看IP地址

没有ifconfig
命令的话:yum install net-tools -y
虚拟机ping外网:

windows ping 虚拟机:

2.5 关闭防火墙
# CentOS7
# 临时关闭防火墙服务
systemctl stop firewalld
# 永久关闭防火墙服务
systemctl disable firewalld
# 查看防护墙服务状态
systemctl status firewalld
# 查看服务状态信息简便方法
systemctl is-active firewalld # 检查服务是否正常运行
systemctl is-failed firewalld # 检查服务是否停止
systemctl is-enabled firewalld # 检查确认服务是否开机运行
# CentOS6
# 查看防护墙服务状态
/etc/init.d/iptables status
# 临时关闭防火墙服务
/etc/init.d/iptables stop
# 永久关闭防火墙服务
chkconfig iptables off
2.6 禁用SELINUX
永久禁用SELINUX
编辑/etc/selinux/config
文件:
# 原来为 SELINUX=enforcing
SELINUX=disabled
禁用SELINUX后需要重启虚拟机生效
其他相关命令:
# 查看SELINUX状态
[root@node ~]# getenforce
Disabled
# 临时禁用SELINUX
setenforce 0
setenforce Permissive
# 临时开启SELINUX
setenforce 1
setenforce Enforcing
# SELINUX的三种状态
Disabled # 禁用
Permissive # 违反SELinux规则的行为只会记录到日志中,当仍可执行
Enforcing # 违反SELinux规则的行为将被阻止并记录到日志中
2. 配置阿里云的yum源
- 下载wget
yum install wget -y
- 备份旧的yum源文件
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
- 下载阿里云的yum源文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 同时下载扩展的yum源文件
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
- 执行以下命令:
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
- 重新生成yum缓存
yum clean all
yum makecache
[hadoop@beh01 yum.repos.d]$ yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: base extras updates
Cleaning up list of fastest mirrors
Other repos take up 64 M of disk space (use --verbose for details)
[hadoop@beh01 yum.repos.d]$ yum makecache
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/7): extras/x86_64/prestodelta | 52 kB 00:00:01
(2/7): extras/x86_64/other_db | 120 kB 00:00:04
(3/7): extras/x86_64/filelists_db | 236 kB 00:00:06
(4/7): updates/x86_64/prestodelta | 511 kB 00:00:04
(5/7): updates/x86_64/filelists_db | 3.0 MB 00:00:37
(6/7): base/x86_64/filelists_db | 7.1 MB 00:00:44
(7/7): base/x86_64/other_db | 2.6 MB 00:00:47
元数据缓存已建立
# 检查可用yum源
[hadoop@beh01 yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,070
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,314
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 397
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 743
repolist: 24,524
3. 系统更新
yum update -y
# 或者
yum upgrade -y
4. 安装常用的软件
yum install -y tree nmap dos2unix lrzsz nc lsof wget tcpdump htop iftop iotop sysstat nethogs psmisc net-tools bash-completion bash-completion-extras vim-enhanced
软件包名 | 包含的核心命令 |
---|---|
tree | tree以树形结构显示文件和目录 |
nmap | nmap扫描端口的工具 |
dos2unix | 转换脚本格式的工具 |
lrzsz | 包含上传(rz)、下载(sz)文件工具 |
nc | 文件传输、端口检查工具 |
lsof | 反查端口进程以及服务开发文件工具 |
wget | 下载软件包工具 |
tcpdump | 抓包、监听等重要排错工具 |
htop | 系统进程相关信息查看工具 |
iftop | 查看主机网卡带宽工具 |
iotop | IO分析工具 |
sysstat | 含有sar、iostat等重要系统性能查看工具 |
nethogs | 显示进程的网络流量 |
psmisc | 含有killall、pstree等命令 |
net-tools | 含有netstat、ifconfig、route、arp等命令 |
bash-completion<br />bash-completion-extras | tab补全功能工具包 |
vim-enhanced | vim编辑器工具包 |
-
查找某个命令对应的软件包,例如查找
killall
命令对应的软件包,前提是命令存在:rpm -qf `which killall`
-
查找某个包有哪些命令,例如查找net-tools有哪些命令,前提是包已安装:
rpm -ql net-tools
-
如果想安装一些未在系统安装时安装的包组,按照以下步骤进行:
-
查看哪些包组已经安装,哪些还没有安装
[root@node01 ~]# yum grouplist Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.bit.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com # 可以安装的包组 Available Environment Groups: Minimal Install Compute Node Infrastructure Server File and Print Server Basic Web Server Virtualization Host Server with GUI GNOME Desktop KDE Plasma Workspaces Development and Creative Workstation # 已安装的包组 Installed Groups: Compatibility Libraries Development Tools Security Tools System Administration Tools # 可以安装的包组 Available Groups: Console Internet Tools Graphical Administration Tools Legacy UNIX Compatibility Scientific Support Smart Card Support System Management Done [root@node01 ~]#
-
执行以下命令安装包组
# 以"Console Internet Tools"这个包组为例 yum groupinstall "Console Internet Tools" -y
-
5. 定时清理系统日志
在/usr/local/bin
目录下创建清理系统日志的脚本clean-log.sh
,内容如下:
#!/bin/bash
rm -rf /var/log/boot.log-*
rm -rf /var/log/btmp-*
rm -rf /var/log/cron-*
rm -rf /var/log/dmesg.*
rm -rf /var/log/maillog-*
rm -rf /var/log/messages-*
rm -rf /var/log/secure-*
rm -rf /var/log/spooler-*
rm -rf /var/log/vmware-network.[0-9]*.log
说明,这里只是添加了操作系统的日志,这些日志都是会按照一定的规则滚动,删除的时候保留了最新的,后续在系统上安装的各种应用也会产生日志,应该合理设置日志滚动规则,并将删除过期日志的操作添加到这个脚本中
编辑/etc/rc.d/rc.local
文件,添加命令,让系统在开机后清理一次过期日志文件:
sh /usr/local/bin/clean-log.sh
给/etc/rc.d/rc.local
脚本添加执行权限:
chmod +x /etc/rc.d/rc.local
开启定时任务,每天晚上00:00删除一次系统过期日志:
# 执行crontab -e命令编辑定时调度任务
0 0 * * * sh /usr/local/bin/clean-log.sh
6. 修改系统字符编码集
# 查看系统编码字符集
[root@node ~]# echo $LANG
en_US.UTF-8
# 临时修改系统字符集
[root@node ~]# LANG=zh_CN.UTF-8
# 永久修改系统字符集
# 方法一
# 编辑/etc/profile文件,添加如下内容
export LANG=zh_CN.UTF-8
# 然后source /etc/profile文件即可
# 方法二:CentOS6
# 编辑/etc/sysconfig/i18n文件
LANG="zh_CN.UTF-8"
# 然后source /etc/sysconfig/i18n文件即可
# 方法三:CentOS7
# 编辑/etc/locale.conf文件
LANG="zh_CN.UTF-8"
# 然后source /etc/locale.conf文件即可
# 方法三:CentOS7
[root@node ~]# localectl set-locale LANG=zh_CN.UTF-8
# 然后source /etc/locale.conf文件即可
7. 远程连接优化
# 1. 修改/etc/ssh/sshd_config文件中的内容
# 这一行默认为yes,改为no
GSSAPIAuthentication no
# 这一行默认注释且值为no,放开注释并修改为no
UseDNS no
# 2.然后确保/etc/hosts文件中有本机的IP和主机名映射
[root@node ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.10 node
# 3.重启sshd服务
systemctl restart sshd
8. 用户管理
创建一个普通用户,并赋予sudo权限:
useradd hadoop # 创建hadoop用户
passwd hadoop # 给hadoop用户设置密码
给hadoop用户添加sudo权限,并且设置hadoop用户可以不输入密码就执行sudo命令,编辑/etc/sudoers
文件:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
# 这一行是新增加的
hadoop ALL=(ALL) NOPASSWD:ALL

网友评论