Linux网络配置和系统管理操作

配置网络ip地址

1. ifconfig配置网络接口

ifconfig :network interfaces configuring网络接口配置
1.基本语法
ifconfig (功能描述:显示所有网络接口的配置信息)
2. 案例实操
(1)查看当前网络ip

[root@hadoop100 桌面]# ifconfig

2.ping测试主机之间网络连通性

  1. 基本语法
    ping 目的主机 (功能描述:测试当前服务器是否可以连接目的主机)
  2. 案例实操
    (1)测试当前服务器是否可以连接百度
[root@hadoop100 桌面]# ping www.baidu.com

3.修改IP地址

  1. 查看IP配置文件,如图5-5所示
[root@hadoop100 桌面]#vim /etc/sysconfig/network-scripts/ifcfg-ens33

在这里插入图片描述
有值的按照下面的值修改,没有该项的要增加。

TYPE="Ethernet"    #网络类型(通常是Ethemet)
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"   #IP的配置方法[none|static|bootp|dhcp](引导时不 使用协议|静态分配IP|BOOTP协议|DHCP协议)
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"   
UUID="e83804c1-3257-4584-81bb-660665ac22f6"   #随机id
DEVICE="ens33"   #接口名(设备,网卡)
ONBOOT="yes"   #系统启动的时候网络接口是否有效(yes/no)
#IP地址
IPADDR=192.168.202.100  
#网关  
GATEWAY=192.168.202.2      
#域名解析器
DNS1=192.168.202.2

编辑完后,按键盘esc ,然后输入 :wq 回车即可。
2. 执行service network restart 重启网络
在这里插入图片描述

4.修改IP地址后可能会遇到的问题

1.物理机能ping通虚拟机,但是虚拟机ping不通物理机,一般都是因为物理机的防火墙问题,把防火墙关闭就行
2.虚拟机能Ping通物理机,但是虚拟机Ping不通外网,一般都是因为DNS的设置有问题
3.虚拟机Ping www.baidu.com 显示域名未知等信息,一般查看GATEWAY和DNS设置是否正确
4.如果你修改了windows主机的vmnet8的ip需要重启电脑
5.如果以上全部设置完还是不行,需要关闭NetworkManager服务
systemctl stop NetworkManager 关闭
systemctl disable NetworkManager 禁用
6.如果检查发现 systemctl status network 有问题 需要检查ifcfg-ens33

配置主机名

1.修改主机名称

  1. 基本语法
    hostname (功能描述:查看当前服务器的主机名称)
  2. 案例实操
    (1)查看当前服务器主机名称
[root@hadoop100 桌面]# hostname

(2)如果感觉此主机名不合适,我们可以进行修改。通过编辑/etc/hostname文件

[root@hadoop100 桌面]# vi /etc/hostname

修改完成后重启生效。

2.修改hosts映射文件

  1. 修改linux的主机映射文件(hosts文件)

后续在hadoop阶段,虚拟机会比较多,配置时通常会采用主机名的方式配置,
比较简单方便。 不用刻意记ip地址。
(1)打开/etc/hosts

[root@hadoop100 桌面]# vim /etc/hosts

添加如下内容
192.168.202.100 hadoop100
192.168.202.101 hadoop101
192.168.202.102 hadoop102
192.168.202.103 hadoop103
192.168.202.104 hadoop104
192.168.202.105 hadoop105
2. 修改windows7的主机映射文件(hosts文件)
(1)进入C:\Windows\System32\drivers\etc路径
(2)打开hosts文件并添加如下内容
192.168.202.100 hadoop100
192.168.202.101 hadoop101
192.168.202.102 hadoop102
192.168.202.103 hadoop103
192.168.202.104 hadoop104
192.168.202.105 hadoop105
3. 修改window10的主机映射文件(hosts文件)
(1)进入C:\Windows\System32\drivers\etc路径
(2)拷贝hosts文件到桌面
(3)打开桌面hosts文件并添加如下内容
192.168.202.100 hadoop100
192.168.202.101 hadoop101
192.168.202.102 hadoop102
192.168.202.103 hadoop103
192.168.202.104 hadoop104
192.168.202.105 hadoop105
(4)将桌面hosts文件覆盖C:\Windows\System32\drivers\etc路径hosts文件

关闭防火墙

1.service

  1. 基本语法
    service 服务名 start | stop | restart | status
  2. 经验技巧
    查看服务的方法:/etc/init.d/服务名 ,发现只有两个服务保留在service
[root@hadoop100 init.d]# pwd
/etc/init.d
[root@hadoop100 init.d]# ls -al
drwxr-xr-x.  2 root root  4096 3月  19 15:24 .
drwxr-xr-x. 10 root root  4096 3月  19 15:24 ..
-rw-r--r--.  1 root root 18104 1月   3 2018 functions
-rwxr-xr-x.  1 root root  4334 1月   3 2018 netconsole
-rwxr-xr-x.  1 root root  7293 1月   3 2018 network
-rw-r--r--.  1 root root  1160 4月  11 2018 README
  1. 案例实操
    (1)查看网络服务的状态
[root@hadoop100 桌面]#service network status

(2)停止网络服务

[root@hadoop100 桌面]#service network stop

(3)启动网络服务

[root@hadoop100 桌面]#service network start

(4)重启网络服务

[root@hadoop100 桌面]#service network restart

2.chkconfig 设置后台服务的自启配置

  1. 基本语法
    chkconfig (功能描述:查看所有服务器自启配置)
    chkconfig 服务名 off (功能描述:关掉指定服务的自动启动)
    chkconfig 服务名 on (功能描述:开启指定服务的自动启动)
    chkconfig 服务名 --list (功能描述:查看服务开机启动状态)
  2. 案例实操
    (1)开启/关闭network(网络)服务的自动启动
[root@hadoop100 桌面]#chkconfig network on   

[root@hadoop100 桌面]#chkconfig network off

(2)开启/关闭 network服务指定级别的自动启动

[root@hadoop100 桌面]#chkconfig --level 指定级别 network on
[root@hadoop100 桌面]#chkconfig --level 指定级别 network off

3.systemctl

  1. 基本语法
    systemctl start | stop | restart | status 服务名
  2. 经验技巧
    查看服务的方法:/usr/lib/systemd/system
[root@hadoop100 system]# pwd
/usr/lib/systemd/system
[root@hadoop100 init.d]# ls -al
-rw-r--r--. 1 root root  275 4月  27 2018 abrt-ccpp.service
-rw-r--r--. 1 root root  380 4月  27 2018 abrtd.service
-rw-r--r--. 1 root root  361 4月  27 2018 abrt-oops.service
-rw-r--r--. 1 root root  266 4月  27 2018 abrt-pstoreoops.service
-rw-r--r--. 1 root root  262 4月  27 2018 abrt-vmcore.service
-rw-r--r--. 1 root root  311 4月  27 2018 abrt-xorg.service
-rw-r--r--. 1 root root  751 4月  11 2018 accounts-daemon.service
-rw-r--r--. 1 root root  527 3月  25 2017 alsa-restore.service
-rw-r--r--. 1 root root  486 3月  25 2017 alsa-state.service
……
  1. 案例实操
    (1)查看防火墙服务的状态
[root@hadoop100 桌面]# systemctl status firewalld

(2)停止防火墙服务

[root@hadoop100 桌面]# systemctl stop firewalld

(3)启动防火墙服务

[root@hadoop100 桌面]# systemctl start firewalld

(4)重启防火墙服务

[root@hadoop100 桌面]# systemctl restart firewalld	

4.systemctl 设置后台服务的自启动配置

  1. 基本语法
    systemctl list-unit-files (功能描述:查看服务开机启动状态)
    systemctl disable service_name (功能描述:关掉指定服务的自动启动)
    systemctl enable service_name (功能描述:开启指定服务的自动启动)
  2. 案例实操
    (1)开启/关闭firewalld(防火墙)服务的自动启动
    [root@hadoop100 桌面]# systemctl enable firewalld.service

[root@hadoop100 桌面]# systemctl disable firewalld.service

5.进程运行级别

  1. Linux进程运行级别
    在这里插入图片描述
    2.CentOS7的运行级别简化为:
    multi-user.target 等价于原运行级别3(多用户有网,无图形界面)
    graphical.target 等价于原运行级别5(多用户有网,有图形界面

3.查看默认的运行级别:

[root@hadoop100桌面]# vim /etc/inittab

# inittab is no longer used when using systemd.
#
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
#
# systemd uses 'targets' instead of runlevels. By default, there are two main targets:
#
# multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5
#
# To view current default target, run:
# systemctl get-default
#
# To set a default target, run:
# systemctl set-default TARGET.target

6.关闭防火墙

  1. 临时关闭防火墙
    (1)查看防火墙状态
[root@hadoop100桌面]# systemctl status firewalld

(2)临时关闭防火墙

[root@hadoop100桌面]# systemctl stop firewalld

2.开机启动时关闭防火墙
(1)查看防火墙开机启动状态

[root@hadoop100桌面]# 	systemctl enable firewalld.service

(2)设置开机时关闭防火墙

[root@hadoop100桌面]# systemctl disable firewalld.service

(3)查看服务是否开机自启

[root@hadoop100桌面]# systemctl is-enabled firewalld.service

disabled 表示开机不自启
enabled 表示开机自启

关机重启命令

  在linux领域内大多用在服务器上,很少遇到关机的操作。毕竟服务器上跑一个服务是永无止境的,除非特殊情况下,不得已才会关机。
正确的关机流程为:sync > shutdown > reboot > halt

  1. 基本语法
    (1)sync    (功能描述:将数据由内存同步到硬盘中)
    (2)halt     (功能描述:关闭系统,等同于shutdown -h now 和 poweroff)
    (3)reboot    (功能描述:就是重启,等同于 shutdown -r now)
    (4)shutdown [选项] 时间
    选项   功能
    -h    -h=halt关机
    -r    -r=reboot重启

参数   功能
now   立刻关机
时间   等待多久后关机(时间单位是分钟)。
2. 经验技巧
  Linux系统中为了提高磁盘的读写效率,对磁盘采取了 “预读迟写”操作方式。当用户保存文件时,Linux核心并不一定立即将保存数据写入物理磁盘中,而是将数据保存在缓冲区中,等缓冲区满时再写入磁盘,这种方式可以极大的提高磁盘写入数据的效率。但是,也带来了安全隐患,如果数据还未写入磁盘时,系统掉电或者其他严重问题出现,则将导致数据丢失。使用sync指令可以立即将缓冲区的数据写入磁盘。
3.案例实操
(1)将数据由内存同步到硬盘中

[root@hadoop100桌面]#sync  `

(2)重启

[root@hadoop100桌面]# reboot 

(3)关机

[root@hadoop100桌面]#halt 

(4)计算机将在1分钟后关机,并且会显示在登录用户的当前屏幕中

[root@hadoop100桌面]#shutdown -h 1 ‘This server will shutdown after 1 mins’

(5)立马关机(等同于 halt)

[root@hadoop100桌面]# shutdown -h now 

(6)系统立马重启(等同于 reboot)

[root@hadoop100桌面]# shutdown -r now
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值