Centos 虚拟机配置

Centos 虚拟机配置及相关报错信息

克隆虚拟机后设置静态IP

克隆虚拟机后设置静态IP无效的解决方法

1. 获取虚拟机网卡的MAC地址

通过下面的其中一个命令获取要设置的网卡MAC地址

1
2
3
ip link show
ifconfig -a
ip address show

img

2. 修改70-persistent-ipoib.rules 文件

将eth0的MAC地址改为第一步获取到的地址

1
vim /etc/udev/rules.d/70-persistent-ipoib.rules

img

3. 修改网卡配置文件

将对于网卡配置文件的MAC地址也改为第一步获取到的地址

1
vim /etc/sysconfig/network-scripts/ifcfg-eth0

img

4. 重启

重启网络服务

1
systemctl restart network

systemctl restart network失败

systemctl restart network 重启网络失败

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
[root@haiyong rules.d]# systemctl restart network
Job for network.service failed because the control process exited with error code. See "systemctl status network.service" and "journalctl -xe" for details.
[root@haiyong rules.d]# journalctl -xe
--
-- The start-up result is done.
Jun 19 12:10:01 haiyong CROND[5949]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jun 19 12:10:10 haiyong polkitd[754]: Registered Authentication Agent for unix-process:
Jun 19 12:10:10 haiyong systemd[1]: Starting LSB: Bring up/down networking...
-- Subject: Unit network.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit network.service has begun starting up.
Jun 19 12:10:10 haiyong NetworkManager[939]: <warn> [1624075810.7721] ifcfg-rh: mi
Jun 19 12:10:10 haiyong network[5992]: Bringing up loopback interface: [ OK ]
Jun 19 12:10:10 haiyong NetworkManager[939]: <warn> [1624075810.8999] ifcfg-rh: mi
Jun 19 12:10:10 haiyong NetworkManager[939]: <info> [1624075810.9472] agent-manager: r
Jun 19 12:10:10 haiyong NetworkManager[939]: <info> [1624075810.9481] audit: op="conne
Jun 19 12:10:10 haiyong network[5992]: Bringing up interface ens33: Error: Connection
Jun 19 12:10:10 haiyong network[5992]: [FAILED]
Jun 19 12:10:11 haiyong NetworkManager[939]: <info> [1624075811.0139] agent-manager: r
Jun 19 12:10:11 haiyong NetworkManager[939]: <info> [1624075811.0152] audit: op="conne
Jun 19 12:10:11 haiyong network[5992]: Bringing up interface ens37: Error: Connection
Jun 19 12:10:11 haiyong network[5992]: [FAILED]
Jun 19 12:10:11 haiyong network[5992]: RTNETLINK answers: File exists
Jun 19 12:10:11 haiyong network[5992]: RTNETLINK answers: File exists
Jun 19 12:10:11 haiyong network[5992]: RTNETLINK answers: File exists
Jun 19 12:10:11 haiyong network[5992]: RTNETLINK answers: File exists
Jun 19 12:10:11 haiyong network[5992]: RTNETLINK answers: File exists
Jun 19 12:10:11 haiyong network[5992]: RTNETLINK answers: File exists
Jun 19 12:10:11 haiyong network[5992]: RTNETLINK answers: File exists
Jun 19 12:10:11 haiyong network[5992]: RTNETLINK answers: File exists
Jun 19 12:10:11 haiyong network[5992]: RTNETLINK answers: File exists
Jun 19 12:10:11 haiyong systemd[1]: network.service: control process exited, code=exite
Jun 19 12:10:11 haiyong systemd[1]: Failed to start LSB: Bring up/down networking.
-- Subject: Unit network.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit network.service has failed.
--
-- The result is failed.
Jun 19 12:10:11 haiyong systemd[1]: Unit network.service entered failed state.
Jun 19 12:10:11 haiyong systemd[1]: network.service failed.
Jun 19 12:10:11 haiyong polkitd[754]: Unregistered Authentication Agent for unix-proces



解决方法:

1
2
3
4
5
6
[root@haiyong rules.d]# systemctl stop NetworkManager
[root@haiyong rules.d]# systemctl disable NetworkManager
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
Removed symlink /etc/systemd/system/network-online.target.wants/NetworkManager-wait-online.service.
[root@haiyong rules.d]# systemctl restart network

关闭防火墙

查看防⽕火墙状态

1
2
systemctl status firewalld
systemctl status firewalld.service

停⽌止firewall

1
systemctl stop firewalld.service

禁止firewall开机启动

1
systemctl disable firewalld.service 

关闭selinux

vi /etc/selinux/config

注释SELINUX=enforcing,添加SELINUX=disabled

1
2
3
4
5
6
7
8
9
10
11
12
# 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
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

时钟同步

ntpdate是一个linux时间同步服务软件,一般默认情况下是未安装。

1. 配置时间服务器

使用root⽤户

1
2
[root@linux .ssh]# ntpdate
-bash: ntpdate: command not found

安装ntpdate:

1
2
yum -y install ntpdate
yum -y install ntp
1
2
3
4
5
6
7
[root@linux ~]# systemctl status ntpd.service
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@linux ~]# rpm -qa | grep ntp
ntpdate-4.2.6p5-29.el7.centos.2.x86_64
ntp-4.2.6p5-29.el7.centos.2.x86_64

编辑/etc/ntp.conf

vim /etc/ntp.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
restrict 127.0.0.1
restrict ::1

# Hosts on local network are less restricted.
restrict 192.168.183.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst

server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10

保证BIOS与系统时间同步

vim /etc/sysconfig/ntpd ,添加:

1
2
3
# Command line options for ntpd
OPTIONS="-g"
SYNC_HWLOCK=yes

启动ntpd服务

1
systemctl start ntpd.service

设置ntpd的服务开机启动

1
2
chkconfig ntpd on
systemctl enable ntpd.service

设置时间同步:

1
2
3
4
5
# 通过⽹络连接外⽹进⾏时钟同步
ntpdate us.pool.ntp.org;
# 阿⾥云时钟同步服务器
ntpdate ntp4.aliyun.com

2. 其他机器配置

使用root⽤户

安装ntpdate:

1
yum -y install ntpdate

在其他机器配置10分钟与时间服务器同步⼀次
编写脚本

1
crontab -e

输入如下内容:

1
*/10 * * * * /usr/sbin/ntpdate 192.168.183.121

修改任意机器时间

1
date -s "2020-06-20 11:11:11"

查看crontab任务

1
crontab -l

查看crontab的执行日志

1
tail -n 30 -f /var/log/cron

安装jdk

查看系统⾃带的openjdk,如果有,卸载系统⾃带的openjdk

1
2
[root@linux ~]# rpm -qa | grep java
[root@linux ~]#

使用rz命令上传jdk-8u231-linux-x64.tar.gz文件,注意不要勾选Upload files as ASCII

解压jdk

1
tar -zxvf jdk-8u231-linux-x64.tar.gz -C ../servers/

配置环境变量

vi /etc/profile

1
2
export JAVA_HOME=/opt/bigdata/servers/jdk1.8.0_231
export PATH=:$JAVA_HOME/bin:$PATH

使配置文件生效

1
source /etc/profile
1
2
3
4
[root@linux software]# java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
--THE END--

本文标题:Centos 虚拟机配置

文章作者:hiyo

文章链接:https://hiyongz.github.io/posts/linux-centos-configure-tutorials/

许可协议:本博客文章除特别声明外,均采用CC BY-NC-ND 4.0 许可协议。转载请保留原文链接及作者。

关注微信公众号,及时接收最新技术文章!