Linux系统基本管理

实验环境为Centos 7.9

1、自建yum仓库,分别为网络源和本地源
1)网络源
[root@OurLab ~]# vim /etc/yum.repos.d/Centos-7.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/

​ 验证

[root@OurLab ~]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                                                                                         repo name                                                                                                               status
base/7/x86_64                                                                                   CentOS-7 - Base - mirrors.aliyun.com                                                                                    10,072
extras/7/x86_64                                                                                 CentOS-7 - Extras - mirrors.aliyun.com                                                                                     498
updates/7/x86_64                                                                                CentOS-7 - Updates - mirrors.aliyun.com                                                                                  2,543
repolist: 17,134

2)本地源

​ 选择光盘镜像作为本地源,挂载光盘镜像

[root@OurLab ~]# mount /dev/cdrom /mnt/cdrom/
mount: /dev/sr0 is write-protected, mounting read-only

​ 编辑repo文件

[root@OurLab ~]# vim /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///mnt/cdrom
gpgcheck=0
enabled=1

​ 验证

[root@OurLab ~]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                                                                                         repo name                                                                                                               status
base/7/x86_64                                                                                   CentOS-7 - Base - mirrors.aliyun.com                                                                                    10,072
extras/7/x86_64                                                                                 CentOS-7 - Extras - mirrors.aliyun.com                                                                                     498
local                                                                                           local                                                                                                                    4,021
updates/7/x86_64                                                                                CentOS-7 - Updates - mirrors.aliyun.com                                                                                  2,543
repolist: 17,134
2、编译安装http2.4,实现可以正常访问
1).下载http 2.4

​ 进入https://httpd.apache.org/download.cgi,下载http2.4

2).查看是否安装http
[root@OurLab ~]# rpm -qa | grep http
httpd-tools-2.4.6-93.el7.centos.x86_64
http-parser-2.7.1-8.el7_7.2.x86_64
httpd-2.4.6-93.el7.centos.x86_64

​ 卸载http

[root@OurLab ~]# yum remove httpd httpd-tools http-parser
3).源码包安装环境依赖的包
yum install apr-devel apr-util-devel openssl-devel pcre-devel gcc -y
4).解包
[root@OurLab data]# ls
httpd-2.4.48.tar.bz2
[root@OurLab data]# tar -jxvf httpd-2.4.48.tar.bz2
5).编译安装httpd
[root@OurLab httpd-2.4.48]# ./configure --prefix=/usr/local/httpd24 --sysconfdir=/etc/httpd/ --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
[root@OurLab httpd-2.4.48]# make && make install
6).配置环境变量,启动httpd服务
[root@OurLab httpd-2.4.48]# cd /usr/local/httpd24/bin/
[root@OurLab bin]# echo 'PATH=$PATH:/usr/local/httpd24/bin' > /etc/profile.d/httpd.sh
[root@OurLab bin]# . /etc/profile.d/httpd.sh
[root@OurLab bin]# apachectl start
[root@OurLab bin]# curl 127.0.0.1
<html><body><h1>It works!</h1></body></html>
3、利用sed 取出ifconfig命令中本机的IPv4地址
[root@OurLab bin]# ifconfig ens33 | sed -n '/inet /s#\(.*inet \)\(.*\)\( n.*\)#\2#gp'
192.168.1.59
4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
[root@OurLab bin]# cat /etc/fstab |sed -r 's/^#\ ?(.*)/\1/'|sed '/^$/d'
/etc/fstab
Created by anaconda on Fri May 17 05:52:23 2019
Accessible filesystems, by reference, are maintained under '/dev/disk'
See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=89dbf7a6-b689-4b3b-9a2e-2c56613dcecf /boot                   xfs     defaults        0 0
/dev/mapper/centos-home /home                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
5、处理/etc/fstab路径,使用sed命令取出其目录名和基名
目录名
[root@OurLab bin]# ls -d /etc/fstab | sed -nr 's@^(.*)/([^/]+)/?$@\1@p'
/etc
基名
[root@OurLab bin]# ls -d /etc/fstab | sed -nr 's@^(.*)/([^/]+)/?$@\2@p'
fstab
6、列出ubuntu软件管理工具apt的一些用法(以vim软件包为例)
1).安装软件包
gw@node2:~$ sudo apt-get install vim -y
Reading package lists... Done
Building dependency tree
......
2).卸载软件包
gw@node2:~$ sudo apt-get remove vim -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
......
3).更新软件包列表
gw@node2:~$ sudo apt-get update
0% [Connecting to mirrors.aliyun.com]
......
4).升级有可用更新的系统(慎用)
gw@node2:~$ sudo apt-get update
Hit:1 http://mirrors.aliyun.com/ubuntu bionic InRelease
Get:2 http://mirrors.aliyun.com/ubuntu bionic-security InRelease [88.7 kB]
......
5).搜索
gw@node2:~$ apt search vim
Sorting... Done
Full Text Search... Done
acr/bionic,bionic 1.2-1 all
  autoconf like tool
  ......
6).获取包信息
gw@node2:~$ apt show vim
Package: vim
Version: 2:8.0.1453-1ubuntu1.4
Priority: optional
Section: editors
......
7).了解使用依赖
gw@node2:~$ apt depends vim
vim
  Depends: vim-common (= 2:8.0.1453-1ubuntu1.4)
  Depends: vim-runtime (= 2:8.0.1453-1ubuntu1.4)
  Depends: libacl1 (>= 2.2.51-8)
  ......
8).查看被那些包依赖
gw@node2:~$ apt-cache rdepends vim
vim
Reverse Depends:
  byobu
    vim-athena
    vim-gtk
    vim-gtk3
    ......
9).安装相关的编译环境
gw@node2:~$ sudo apt-get build-dep vim
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
......
10).下载源代码
gw@node2:~$ apt-get source vim
Reading package lists... Done
NOTICE: 'vim' packaging is maintained in the 'Git' version control system at:
https://salsa.debian.org/vim-team/vim.git
......
11).清理无用包
gw@node2:~$ sudo apt-get clean
gw@node2:~$ sudo apt-get autoclean
Reading package lists... Done
Building dependency tree
Reading state information... Done
12).检查是否有损坏的依赖
gw@node2:~$ sudo apt-get check
Reading package lists... Done
Building dependency tree
Reading state information... Done
posted @ 2021-08-01 21:03  温白开  阅读(82)  评论(0编辑  收藏  举报