翼度科技»论坛 云主机 LINUX 查看内容

安装Centos7初始化操作系统

4

主题

4

帖子

12

积分

新手上路

Rank: 1

积分
12
设置静态网络

1、设置静态网络,一是用来不让地址飘忽不定,二来是为了访问外网。
命令如下:
  1. [root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
复制代码
修改内容:
  1. TYPE="Ethernet"
  2. BOOTPROTO="static"    # 设置为静态网络static。
  3. DEFROUTE="yes"
  4. PEERDNS="yes"
  5. PEERROUTES="yes"
  6. IPV4_FAILURE_FATAL="no"
  7. IPV6INIT="yes"
  8. IPV6_AUTOCONF="yes"
  9. IPV6_DEFROUTE="yes"
  10. IPV6_PEERDNS="yes"
  11. IPV6_PEERROUTES="yes"
  12. IPV6_FAILURE_FATAL="no"
  13. IPV6_ADDR_GEN_MODE="stable-privacy"
  14. NAME="ens33"
  15. UUID="66f9933b-54eb-4156-81f4-8cb3f344124b"
  16. DEVICE="ens33"
  17. ONBOOT="yes"
  18. IPADDR="192.168.43.2"    # 配置跟宿主机联网的同网段IP地址
  19. NETMASK="255.255.255.0"      # 配置子网掩码
  20. GATEWAY="192.168.43.1"      # 配置宿主机的网关
  21. DNS1="8.8.8.8"      # 配置DNS解析服务器
复制代码
 2、重启网络服务。
  1. [root@localhost ~]# systemctl restart network
复制代码
 3、查看IP地址是否已经更改。
  1. [root@localhost ~]# ip add
  2. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
  3.     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  4.     inet 127.0.0.1/8 scope host lo
  5.        valid_lft forever preferred_lft forever
  6.     inet6 ::1/128 scope host
  7.        valid_lft forever preferred_lft forever
  8. 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  9.     link/ether 00:0c:29:b2:e5:54 brd ff:ff:ff:ff:ff:ff
  10.     inet 192.168.43.2/24 brd 192.168.43.255 scope global ens33    # 可以查看这里IP地址已经更改
  11.        valid_lft forever preferred_lft forever
  12.     inet6 2409:890c:39b0:630:1427:b41a:753c:ef8d/64 scope global noprefixroute dynamic
  13.        valid_lft 3472sec preferred_lft 3472sec
  14.     inet6 fe80::e458:494f:e11c:bbe8/64 scope link
  15.        valid_lft forever preferred_lft forever
  16. 3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
  17.     link/ether 52:54:00:cd:f3:96 brd ff:ff:ff:ff:ff:ff
  18.     inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
  19.        valid_lft forever preferred_lft forever
  20. 4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000
  21.     link/ether 52:54:00:cd:f3:96 brd ff:ff:ff:ff:ff:ff
复制代码
 4、验证网络是否联通。
  1. [root@localhost ~]# ping www.baidu.com
  2. PING www.a.shifen.com (39.156.66.18) 56(84) bytes of data.
  3. 64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=1 ttl=50 time=51.6 ms
  4. 64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=2 ttl=50 time=69.3 ms
  5. 64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=3 ttl=50 time=57.5 ms
复制代码
 关闭防火墙

1、关闭防火墙,防止以后服务会被防火墙挡掉。
  1. [root@localhost ~]# iptables -F
  2. [root@localhost ~]# systemctl stop firewalld
  3. [root@localhost ~]# systemctl disable firewalld
  4. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
  5. Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
  6. [root@localhost ~]# systemctl status firewalld
  7. ● firewalld.service - firewalld - dynamic firewall daemon
  8.    Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
  9.    Active: inactive (dead)
  10.      Docs: man:firewalld(1)
  11. Mar 16 02:52:21 localhost.localdomain systemd[1]: Starting firewalld - dynami....
  12. Mar 16 02:52:27 localhost.localdomain systemd[1]: Started firewalld - dynamic....
  13. Mar 16 03:45:13 localhost.localdomain systemd[1]: Stopping firewalld - dynami....
  14. Mar 16 03:45:18 localhost.localdomain systemd[1]: Stopped firewalld - dynamic....
  15. Hint: Some lines were ellipsized, use -l to show in full.
复制代码
 关闭selinux

1、临时关闭selinux。
  1. [root@localhost ~]# getenforce
  2. Enforcing
  3. [root@localhost ~]# setenforce 0
  4. [root@localhost ~]# getenforce
  5. Permissive
复制代码
 2、永久关闭selinux。
执行命令:
  1. [root@localhost ~]# vim /etc/selinux/config       # 这两种配置文件效果一样,任选其一。
  2. [root@localhost ~]# vim /etc/sysconfig/selinux
复制代码
 修改内容:
  1. # This file controls the state of SELinux on the system.
  2. # SELINUX= can take one of these three values:
  3. #     enforcing - SELinux security policy is enforced.
  4. #     permissive - SELinux prints warnings instead of enforcing.
  5. #     disabled - No SELinux policy is loaded.
  6. # SELINUX=enforcing      # 注释第一行即可
  7. # SELINUXTYPE= can take one of three two values:
  8. #     targeted - Targeted processes are protected,
  9. #     minimum - Modification of targeted policy. Only selected processes are protected.
  10. #     mls - Multi Level Security protection.
  11. # SELINUXTYPE=targeted      # 注释这一行即可
复制代码
 修改主机名

修改命令如下:
  1. [root@localhost ~]# hostnamectl set-hostname K8s-master
  2. [root@localhost ~]# bash
  3. [root@k8s-master ~]#
复制代码
 配置主机和IP地址映射关系

1、修改配置文件。
执行命令:
  1. [root@k8s-master ~]# vim /etc/hosts
复制代码
 添加内容:
  1. 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
  2. ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
  3. K8s-master 192.168.43.2      # 前面是主机名,后面是对应IP
  4. K8s-node01 192.168.43.3
  5. K8s-node02 192.168.43.4
复制代码
 2、重载配置文件。
  1. [root@k8s-master ~]# systemctl daemon-reload
复制代码
 配置网络yum源

阿里云Centos7镜像下载地址:Centos7地址
1、安装wget工具。
  1. [root@k8s-master ~]# yum -y install wget
复制代码
 2、备份本地源。
  1. [root@k8s-master ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
复制代码
 3、下载阿里云镜像源。
  1. [root@k8s-master ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
复制代码
 4、生成缓存。
  1. [root@k8s-master ~]# yum makecache
复制代码
5、安装epel扩展源(可以搜到更多的包)。
  1. [root@k8s-master ~]# yum install -y epel-release
复制代码
来源:https://www.cnblogs.com/Bookcict/p/17224025.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

举报 回复 使用道具