Linux基础实践(三)

来源:互联网 发布:arm软件侵权赔偿 编辑:程序博客网 时间:2024/06/05 17:21

网络配置

1.IP

IPv4:  32位的二进制组成; 172.25.254.10 , 4段,每段8位(点分十进制法);
11111111. 111111111. 111111111. 111111111
255    255        255        255
172.258.268.1(不存在的IP地址)
地址的分类:
A类:1
B类:10
C类:110

IP::={net-id,host-id}
172.25.254.10/24   net-id: 172.25.254   host-id:10
网段: 172.25.254.0/24allow 172.25.0.0/16   172.25.254.0/24  172.25.254.10

2.配置IP

ifconfig 网卡 ip netmask临时设定

nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes#添加dhcp网络
nmcli connection add type ethernet con-name westos ifname eth0 ip4 ip/24#添加静态网络
nmcli connection delete westos#删除westos链接
nmcli connection show#显示所有网络链接
nmcli connection down westos#关闭指定链接
nmcli connection up westos#开启指定链接
nmcli connection modify "westos" ipv4.addresses newip/24#改变wetos的ip
nmcli connection modify "westos" ipv4.method <auto|manual>#改变westos的工作方式为动态或者静态
nmcli device connect eth0#开启设备
nmcli device disconnect eth0#关闭设备
nmcli device show#显示设备信息
nmcli device status#显示设备状态

配置IP的文件:
- 文件存放的目录: /etc/sysconfig/network-scripts/
- 文件名的命名: ifcfg-xxx
- 文件内容:
DEVICE=eth0# 设备名称
BOOTPROTO=static|none# boot protocol,启动的协议
ONBOOT=yes# 这个设置开启生效
NAME=xxx# 连接名称
IPADDR=xxxx# 设置你的IP
PREFIX=24# 设置你的网络位
- 注意: 要想生效,重启network网络服务
systemctl restart network

编写设置ip的命令:
1. 编辑文件/bin/set-ip
2. 文件内容`
cd /etc/sysconfig/network-scripts
rm -fr ifcfg-eth0
cat > ifcfg-eth0 <<EOF
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
NAME=eth0
IPADDR=172.25.0.$1# $1代表命令后面跟的第一个参数
PREFIX=24
EOF
systemctl  restart network

3. 文件其它操作:
chmod +x /bin/set-ip 增加权限
4. 使用命令: set-ip 12
3.网关

desktop:  172.25.88.10/24     GATEWAY=172.25.88.250

网关: 172.25.88.250/24   172.25.254.88/24

server:   172.25.254.11/24   GATEWAY=172.25.254.250

## 查看与设置

- 设置网关
/etc/sysconfig/network(优先级低)
/etc/sysconfig/network-scripts/ifcfg-xxx  (优先级高)

编写内容:GATEWAY=xxx

- 查看网关: route -n
# DNS:domain name server

- 管理IP和域名关系的本地文件/etc/hosts
ip域名
172.25.254.10    www.westos.org

- 指定DNS服务器的设定dns:
/etc/sysconfig/network-scripts/ifcfg-xxx  
# 永久修改,必须重启服务才生效
DNS1=xxx172.25.254.254
DNS2=xxx
DNS3=xxx
/etc/resolv.conf
# 即可即生效,无需重启服务
nameserver xxxx
- 检测DNS是否设置成功
ping westos.example.com  172.25.254.1

- 设置本地解析和DNS服务器上解析优先级的文件/etc/nsswitch.conf

*动态获取IP


server: 分配给别人IP
desktop: 动态获取IP


## server主机操作
1. server必须有一个IP: 172.25.x.11/24
2. 安装dhcp软件: yum install dhcp -y
3. 查看dhcp软件的配置文件: rpm -qc dhcp
4. 配置dhcpd.conf文件:
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example  /etc/dhcp/dhcpd.conf
  - 删除36行以后的内容; dG
  - 删除27,28行;
  
```
  1 option domain-name "westos.org";
  2 option domain-name-servers 172.25.254.254;
  3 default-lease-time 600;
  4 max-lease-time 7200;
  5 log-facility local7;
  6 subnet 172.25.0.0 netmask 255.255.255.0 {
  7   range 172.25.0.100 172.25.0.120;
  8   option routers 172.25.0.250;
  9 }
```
5. 重启dhcp服务:
systemctl  start dhcpd
systemctl  status dhcpd


## desktop主机操作
设置ip获取方式为dhcp;

4.虚拟机的管理
virt-manager# 打开虚拟机控制台
virsh list# 列出正在运行的虚拟机
virsh list --all# 列出所有的虚拟机
virsh start 虚拟机名# 打开指定虚拟机
virsh shutdown 虚拟机名# 正常关闭虚拟机
virsh destroy 虚拟机名# 强行关闭虚拟机
virsh undefine 虚拟机名# 删除虚拟机但不删除磁盘文件

 

 

软件安装

1. 软件包的安装:

1.rpm

rpm包安装

- 准备工作: 下载iso镜像

- 挂载设备到某个目录:mount xxx.iso /mnt/

- 进入Packages包执行命令:

rpm -ivh xxx.rpm# 安装软件, i:install,v,显示过程

rpm -qp xxx.rpm# 找出rpm包在系统中安装后的名字

rpm -e xxx    # 删除软件

 

查询:

rpm -ql xxx.rpm# 查询该软件生成了哪些文件;

rpm -qc xxx.rpm# 查询软件生成的配置文件;

rpm -qa    # 查询已经安装的软件包

rpm -qa | grep http# 查询与http相关的软件是否安装;

rpm -qf /bin/ls# 查看/bin/ls是由哪个软件包生成的;

 

- 缺点:必须切换到软件包所在的目录;依赖性需要自己查找安装;

 

 

2.yum

yum安装

 

- 前提

iso镜像

需要软件包仓库;

搭建本地yum仓库

1. 挂载iso镜像到本地的某个目录:

mount xxx.iso /mnt/

# 你可以在/mnt目录里面访问到iso镜像的内容;

2. 告诉yum仓库你的软件位置:

# 切换到yum仓库配置文件所在目录

cd /etc/yum.repos.d/

# 删除装系统时默认设置配置文件

rm -fr *

 

# 编辑属于你的配置文件

vim westos.repo# 一定要以.repo结尾,前面任意

```

[rhel7]# 仓库名称

name=rhel7# 仓库描述

baseurl=file:///mnt# 仓库地址,file://是协议,/mnt是本地所在位置;

gpgcheck=0# 不检测key

enabled=1# 1,仓库生效; 0,不生效;

```

3. 清除缓存:

# 默认会去/var/cache/yum去找软件信息,更改配置后一定要清缓存;

yum clean all

 

4. 检测

- 方法一:  

# 列出所有的软件仓库包含的软件包;

yum repolist

 

- 方法二:

# 任意安装一个软件

yum install lftp -y

 

 

 

2.搭建网络yum仓库

 

 

** desktop主机

1. 准备工作: 把本机文件让其他主机可以访问(httpd)

# 一般把安装了httpd软件的主机称为Web服务器,可以共享文件给其他主机;

yum install httpd -y

systemctl start httpd

systemctl enabled httpd

systemctl stop firewalld

systemctl disable firewalld

 

 

2. 把iso镜像的内容让其他主机可以访问:

# /var/www/html,是http的默认发布目录,http://ip/rhel7访问;

mkdir /var/www/html/rhel7

 

# iso挂载到http的默认发布目录

mount xxx.iso /var/www/html/rhel7

 

3. 修改yum仓库的配置文件

# 只需要修改baseurl

vim westos.repo# 一定要以.repo结尾,前面任意

```

[rhel7]# 仓库名称

name=rhel7# 仓库描述

baseurl=http://ip/rhel7# 仓库地址,http://是协议,/rhel7是ip主机/var/www/html/rhel7目录;

gpgcheck=0# 不检测key

enabled=1# 1,仓库生效; 0,不生效;

```

4. 清空缓存和检测

 

其他主机(想使用desktop搭建好的yum仓库)只需要修改yum仓库的配置文件,同desktop第3步;

 

3.搭建网络第三方软件仓库

 

iso镜像里面包含4000多个软件包,但还有一些软件(eg:wps,smplayer,ntfs)没有;

从其他地方(eg:baidu,www.pkgs.org)下载的其他软件包;

 

** desktop主机

1. 创建software目录,可让其他主机访问

mkdir /var/www/html/software

 

2. 将第三方软件放在/var/www/html/software目录下;

# 可通过网址http://ip/software访问;

cp xxxx.rpm /var/www/html/software/

3. 对software目录生成repodata元数据,让系统知道该目录下有软件包;

createrepo /var/www/html/software/

 

4. 修改yum仓库的配置文件;

vim westos.repo# 一定要以.repo结尾,前面任意

```

[rhel7]# 仓库名称

name=rhel7# 仓库描述

baseurl=http://ip/rhel7# 仓库地址,http://是协议,/rhel7是ip主机/var/www/html/rhel7目录;

gpgcheck=0# 不检测key

enabled=1# 1,仓库生效; 0,不生效;

 

 

[soft]# 仓库名称

name=soft# 仓库描述

baseurl=http://ip/software# 仓库地址,http://是协议,/software是ip主机/var/www/html/software目录;

gpgcheck=0# 不检测key

enabled=1# 1,仓库生效; 0,不生效;

5. 清空缓存和检测;

 

 

其他主机要使用第三方软件仓库只需要修改yum仓库的配置文件,同desktop主机第4步操作;

 

原创粉丝点击