設置靜態網路 1、設置靜態網路,一是用來不讓地址飄忽不定,二來是為了訪問外網。 命令如下: [root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 修改內容: TYPE="Ethernet" BOOTPROTO="stat ...
設置靜態網路
1、設置靜態網路,一是用來不讓地址飄忽不定,二來是為了訪問外網。
命令如下:
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
修改內容:
TYPE="Ethernet"
BOOTPROTO="static" # 設置為靜態網路static。
DEFROUTE="yes"
PEERDNS="yes"
PEERROUTES="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="66f9933b-54eb-4156-81f4-8cb3f344124b"
DEVICE="ens33"
ONBOOT="yes"
IPADDR="192.168.43.2" # 配置跟宿主機聯網的同網段IP地址
NETMASK="255.255.255.0" # 配置子網掩碼
GATEWAY="192.168.43.1" # 配置宿主機的網關
DNS1="8.8.8.8" # 配置DNS解析伺服器
2、重啟網路服務。
[root@localhost ~]# systemctl restart network
3、查看IP地址是否已經更改。
[root@localhost ~]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:b2:e5:54 brd ff:ff:ff:ff:ff:ff
inet 192.168.43.2/24 brd 192.168.43.255 scope global ens33 # 可以查看這裡IP地址已經更改
valid_lft forever preferred_lft forever
inet6 2409:890c:39b0:630:1427:b41a:753c:ef8d/64 scope global noprefixroute dynamic
valid_lft 3472sec preferred_lft 3472sec
inet6 fe80::e458:494f:e11c:bbe8/64 scope link
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
link/ether 52:54:00:cd:f3:96 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000
link/ether 52:54:00:cd:f3:96 brd ff:ff:ff:ff:ff:ff
4、驗證網路是否聯通。
[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (39.156.66.18) 56(84) bytes of data.
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=1 ttl=50 time=51.6 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=2 ttl=50 time=69.3 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=3 ttl=50 time=57.5 ms
關閉防火牆
1、關閉防火牆,防止以後服務會被防火牆擋掉。
[root@localhost ~]# iptables -F
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
Mar 16 02:52:21 localhost.localdomain systemd[1]: Starting firewalld - dynami....
Mar 16 02:52:27 localhost.localdomain systemd[1]: Started firewalld - dynamic....
Mar 16 03:45:13 localhost.localdomain systemd[1]: Stopping firewalld - dynami....
Mar 16 03:45:18 localhost.localdomain systemd[1]: Stopped firewalld - dynamic....
Hint: Some lines were ellipsized, use -l to show in full.
關閉selinux
1、臨時關閉selinux。
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
2、永久關閉selinux。
執行命令:
[root@localhost ~]# vim /etc/selinux/config # 這兩種配置文件效果一樣,任選其一。
[root@localhost ~]# vim /etc/sysconfig/selinux
修改內容:
# 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 # 註釋這一行即可
修改主機名
修改命令如下:
[root@localhost ~]# hostnamectl set-hostname K8s-master
[root@localhost ~]# bash
[root@k8s-master ~]#
配置主機和IP地址映射關係
1、修改配置文件。
執行命令:
[root@k8s-master ~]# vim /etc/hosts
添加內容:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
K8s-master 192.168.43.2 # 前面是主機名,後面是對應IP
K8s-node01 192.168.43.3
K8s-node02 192.168.43.4
2、重載配置文件。
[root@k8s-master ~]# systemctl daemon-reload
配置網路yum源
阿裡雲Centos7鏡像下載地址:Centos7地址
1、安裝wget工具。
[root@k8s-master ~]# yum -y install wget
2、備份本地源。
[root@k8s-master ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
3、下載阿裡雲鏡像源。
[root@k8s-master ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
4、生成緩存。
[root@k8s-master ~]# yum makecache
5、安裝epel擴展源(可以搜到更多的包)。
[root@k8s-master ~]# yum install -y epel-release