自建yum仓库;编译安装http2.4 ;删除/etc/fstab文件中所有以#开头的行;sed 取本机的IP地址;sed命令取目录名
Posted njsummer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自建yum仓库;编译安装http2.4 ;删除/etc/fstab文件中所有以#开头的行;sed 取本机的IP地址;sed命令取目录名相关的知识,希望对你有一定的参考价值。
1、自建yum仓库
本地源
# 安装httpd服务,构建基础http环境
[root@centos8301]# yum -y install httpd
Last metadata expiration check: 0:04:01 ago on Sat 11 Dec 2021 12:05:00 PM CST.
............................................... #省略部分屏幕输出内容
Complete!
[root@centos8301]#
# 创建两个目录
[root@centos8301]# mkdir /var/www/html/centos/8 -pv
mkdir: created directory /var/www/html/centos
mkdir: created directory /var/www/html/centos/8
[root@centos8301]# mkdir /var/www/html/centos/7 -pv
mkdir: created directory /var/www/html/centos/7
[root@centos8301]#
#查看并验证目录结构
[root@centos8301]# cd /var/www/html
[root@centos8301 html]# tree
.
└── centos
├── 7
└── 8
3 directories, 0 files
[root@centos8301 html]#
# 启动httpd服务,并加到启动自运行
[root@centos8301]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@centos8301]#
# 查看光驱情况,本例子 sr0是CentOS7,sr1是CentOS8
[root@centos8301 html]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 200M 0 part /boot/efi
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 4G 0 part [SWAP]
└─sda4 8:4 0 50G 0 part /data
sr0 11:0 1 4.4G 0 rom
sr1 11:1 1 9.3G 0 rom
[root@centos8301 html]#
#挂载光盘
[root@centos8301]#
[root@centos8301]# mount /dev/sr0 /mnt/centos7
mount: /mnt/centos7: mount point does not exist.
[root@centos8301]# mkdir /mnt/centos7
[root@centos8301]# mkdir /mnt/centos8
[root@centos8301]# ls /mnt
centos7 centos8
[root@centos8301]#
[root@centos8301]# mount /dev/sr0 /mnt/centos7
mount: /mnt/centos7: WARNING: device write-protected, mounted read-only.
[root@centos8301]# mount /dev/sr1 /mnt/centos8
mount: /mnt/centos8: WARNING: device write-protected, mounted read-only.
[root@centos8301]#
#验证挂载成功
[root@centos8301]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 200M 0 part /boot/efi
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 4G 0 part [SWAP]
└─sda4 8:4 0 50G 0 part /data
sr0 11:0 1 4.4G 0 rom /mnt/centos7
sr1 11:1 1 9.3G 0 rom /mnt/centos8
[root@centos8301]#
# 将光盘内容与各自的版本目录关联
[root@centos8301]# mount /dev/sr0 /var/www/html/centos/7
mount: /var/www/html/centos/7: WARNING: device write-protected, mounted read-only.
[root@centos8301]# mount /dev/sr1 /var/www/html/centos/8
mount: /var/www/html/centos/8: WARNING: device write-protected, mounted read-only.
[root@centos8301]#
[root@centos8301]# vim /etc/yum.repos.d/base.repo
# /etc/yum.repos.d/base.repo
[BaseOS]
name=BaseOS
baseurl=http://192.168.250.101/centos/8/BaseOS/ enable=1
gpgcheck=0
[AppStream]
name=AppStream
baseurl=http://192.168.250.101/centos/8/AppStream/
enable=1
gpgcheck=0
[root@centos8301]# yum repolist
repo id repo name
AppStream AppStream
BaseOS BaseOS
[root@centos8301]#
[root@centos8301]# dnf list mariadb-server
BaseOS 4.7 MB/s | 2.5 MB 00:00
AppStream 8.4 MB/s | 7.1 MB 00:00
Last metadata expiration check: 0:00:01 ago on Sat 11 Dec 2021 03:44:27 PM CST.
Available Packages
mariadb-server.x86_64 3:10.3.27-3.module_el8.3.0+599+c587b2e7 AppStream
[root@centos8301]# yum list mariadb-server
Last metadata expiration check: 0:00:21 ago on Sat 11 Dec 2021 03:44:27 PM CST.
Available Packages
mariadb-server.x86_64 3:10.3.27-3.module_el8.3.0+599+c587b2e7 AppStream
[root@centos8301]#
[root@centos8301]# yum -y install mariadb-server
Last metadata expiration check: 0:01:43 ago on Sat 11 Dec 2021 03:44:27 PM CST.
Dependencies resolved.
............................................... #省略部分屏幕输出内容
Transaction Summary
===================================================================================================================
Install 10 Packages
Installed:
mariadb-3:10.3.27-3.module_el8.3.0+599+c587b2e7.x86_64
............................................... #省略部分屏幕输出内容
mariadb-backup-3:10.3.27-3mariadb-server-utils-3:10.3.27-3.module_el8.3.0+599+c587b2e7.x86_64
perl-DBD-mysql-4.046-3.module_el8.1.0+203+e45423dc.x86_64
Complete!
[root@centos8301]#
# 通过yum -y install mariadb-server验证,yum源成功
网络源
[root@centos8301]# dnf reposync --repoid=epel --download-metadata -p /var/www/html
EPEL 8.6 MB/s | 11 MB 00:01
Last metadata expiration check: 0:00:05 ago on Sat 11 Dec 2021 04:01:02 PM CST.
EPEL 8.0 MB/s | 24 MB 00:03
(1/8116): AusweisApp2-1.22.2-3.el8.x86_64.rpm 3.6 MB/s | 1.0 MB 00:00
(2/8116): 3proxy-0.8.13-1.el8.x86_64.rpm 542 kB/s | 175 kB 00:00
(3/8116): AusweisApp2-data-1.22.2-3.el8.noarch.rpm 4.6 MB/s | 5.2 MB 00:01
(4/8116): BackupPC-4.4.0-1.el8.x86_64.rpm 605 kB/s | 489 kB 00:00
...............................................
[root@centos8301 html]# ls /var/www/html/epel/
Packages repodata
[root@centos8301 html]#
# 按照下面格式和内容修改好 base.repo
[epel]
name=EPEL
baseurl=http://192.168.250.101/epel/
gpgkey=http://192.168.258.101/epel/RPM-GPG-KEY-EPEL-8
gpgcheck=1
enabled=1
[root@centos8301 html]# cat /etc/yum.repos.d/base.repo
# /etc/yum.repos.d/base.repo
[BaseOS]
name=BaseOS
baseurl=http://192.168.250.101/centos/8/BaseOS/
gpgcheck=0
enable=1
[AppStream]
name=AppStream
baseurl=http://192.168.250.101/centos/8/AppStream/
gpgcheck=0
enable=1
[epel]
name=EPEL
# baseurl=http://mirrors.aliyun.com/epel/$releasever/Everything/$basearch
baseurl=http://192.168.250.101/epel/
gpgkey=http://192.168.258.101/epel/RPM-GPG-KEY-EPEL-8
gpgcheck=1
enabled=1
[root@centos8301 html]#
[root@centos8301 html]# yum repolist
repo id repo name
AppStream AppStream
BaseOS BaseOS
epel EPEL
[root@centos8301 html]#
# 上面完成 EPEL 网络源的配置和测试
2、编译安装http2.4,实现可以正常访问,并将编译步骤和结果提交。
# 准备安装编译需要包
[root@centos8301 html]# dnf install gcc make autoconf apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config
Last metadata expiration check: 0:02:42 ago on Sat 11 Dec 2021 05:05:26 PM CST.
Package make-1:4.2.1-10.el8.x86_64 is already installed.
Dependencies resolved.
============================================================================================================================
Package Architecture Version Repository Size
============================================================================================================================
Installing:
apr-devel x86_64 1.6.3-12.el8 AppStream 246 k
apr-util-devel x86_64 1.6.1-6.el8 AppStream 86 k
autoconf noarch 2.69-29.el8 AppStream 710 k
gcc x86_64 8.5.0-4.el8_5 AppStream 23 M
openssl-devel x86_64 1:1.1.1k-4.el8 BaseOS 2.3 M
................................................
Installing weak dependencies:
apr-util-bdb x86_64 1.6.1-6.el8 AppStream 25 k
apr-util-openssl x86_64 1.6.1-6.el8 AppStream 27 k
Transaction Summary
============================================================================================================================
Install 48 Packages
Upgrade 20 Packages
Total download size: 65 M
Is this ok [y/N]: y
Downloading Packages:
(1/68): expat-devel-2.2.5-4.el8.x86_64.rpm 278 kB/s | 55 kB 00:00
(2/68): glibc-devel-2.28-164.el8.x86_64.rpm 4.5 MB/s | 1.0 MB 00:00
(3/68): cyrus-sasl-devel-2.1.27-5.el8.x86_64.rpm 480 kB/s | 128 kB 00:00
........................................................
(66/68): openssl-libs-1.1.1k-4.el8.x86_64.rpm 5.1 MB/s | 1.5 MB 00:00
(67/68): pcre-8.42-6.el8.x86_64.rpm 3.9 MB/s | 211 kB 00:00
(68/68): gcc-8.5.0-4.el8_5.x86_64.rpm 5.4 MB/s | 23 MB 00:04
----------------------------------------------------------------------------------------------------------------------------
Total 10 MB/s | 65 MB 00:06
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
.............................................................. #省略部分屏幕输出内容
Verifying : pcre-8.42-6.el8.x86_64 87/88
Verifying : pcre-8.42-4.el8.x86_64 88/88
Installed products updated.
Upgraded:
e2fsprogs-1.45.6-2.el8.x86_64 e2fsprogs-libs-1.45.6-2.el8.x86_64 glibc-2.28-164.el8.x86_64 glibc-common-2.28-164.el8.x86_64
glibc-langpack-en-2.28-164.el8.x86_64 keyutils-1.5.10-9.el8.x86_64 keyutils-libs-1.5.10-9.el8.x86_64 krb5-libs-1.18.2-14.el8.x86_64
.............................................................. #省略部分屏幕输出内容
pcre2-utf32-10.32-2.el8.x86_64 perl-srpm-macros-1-25.el8.noarch python-rpm-macros-3-4
#下载httpd源文件压缩文件 下面两个命令运行一个,阿里云更快些。
[root@centos8301]# wget https://mirrors.aliyun.com/apache/httpd/httpd-2.4.51.tar.bz2
[root@centos8301]# wget https://dlcdn.apache.org//httpd/httpd-2.4.51.tar.bz2
--2021-12-11 17:15:26-- https://dlcdn.apache.org//httpd/httpd-2.4.51.tar.bz2
Resolving dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
Connecting to dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7653609 (7.3M) [application/x-bzip2]
Saving to: ‘httpd-2.4.51.tar.bz2’
httpd-2.4.51.tar.bz2 100%[=========================>] 7.30M 16.7KB/s in 7m 11s
2021-12-11 17:22:44 (17.3 KB/s) - ‘httpd-2.4.51.tar.bz2’ saved [7653609/7653609]
# 查看下载的文件
[root@centos8301 data]# ls
httpd-2.4.51.tar.bz2
# 解压文件到指定目录
[root@centos8301 data]# tar xvf httpd-2.4.51.tar.bz2 -C /usr/local/src
httpd-2.4.51/
httpd-2.4.51/acinclude.m4
.............................................................. #省略部分屏幕输出内容
zlib-devel-1.2.11-17.el8.x86_64
Complete!
[root@centos8301 html]#
[root@centos8301 data]# cd /usr/local/src
[root@centos8301 src]# ls
httpd-2.4.51
[root@centos8301 src]#
# 编译配置
[root@centos8301 httpd-2.4.51]# ./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd --enable-ssl
checking for chosen layout... Apache
checking for working mkdir -p... yes
.............................................................. #省略部分屏幕输出内容
config.status: creating build/pkg/pkginfo
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands
configure: summary of build options:
Server Version: 2.4.51
Install prefix: /apps/httpd
C compiler: gcc
CFLAGS: -pthread
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
LDFLAGS:
LIBS:
C preprocessor: gcc -E
[root@centos8301 httpd-2.4.51]#
# 编译make 并 make install安装
[root@centos8301 httpd-2.4.51]# make -j 8 && make install
Making all in srclib
make[1]: Entering directory /usr/local/src/httpd-2.4.51/srclib
make[1]: Leaving directory /usr/local/src/httpd-2.4.51/srclib
Making all in os
.............................................................. #省略部分屏幕输出内容
Installing configuration files
mkdir /etc/httpd/extra
mkdir /etc/httpd/original
mkdir /etc/httpd/original/extra
Installing HTML documents
mkdir /apps/httpd/htdocs
Installing error documents
mkdir /apps/httpd/error
Installing icons
mkdir /apps/httpd/icons
mkdir /apps/httpd/logs
Installing CGIs
mkdir /apps/httpd/cgi-bin
Installing header files
mkdir /apps/httpd/include
Installing build system files
mkdir /apps/httpd/build
Installing man pages and online manual
mkdir /apps/httpd/man
mkdir /apps/httpd/man/man1
mkdir /apps/httpd/man/man8
mkdir /apps/httpd/manual
make[1]: Leaving directory /usr/local/src/httpd-2.4.51
[root@centos8301 httpd-2.4.51]#
# 配置软件运行环境
[root@centos8301 data]# echo PATH=/apps/httpd/bin:$PATH > /etc/profile.d/httpd.sh
[root@centos8301 data]# . /etc/profile.d/httpd.sh
[root@centos8301 data]#
# 启动apache,出现提示性信息
[root@centos8301 data]# apachectl start
AH00558: httpd: Could not reliably determine the servers fully qualified domain name, using fe80::4e77:57:8c52:15f1. Set the ServerName directive globally to suppress this message
#出现的错误处置
[root@centos8301 /]# find / -name "httpd.conf"
/etc/httpd/original/httpd.conf
/etc/httpd/httpd.conf
/usr/local/src/httpd-2.4.51/docs/conf/httpd.conf
[root@centos8301 /]#
vim /etc/httpd/httpd.conf
#ServerName www.example.com:80 修改成下面一行的表达方式
ServerName localhost:80
[root@centos8301 data]#
[root@centos8301]# apachectl restart
# 指定Apache运行专用user
[root@centos8301 data]# useradd -r -s /sbin/nologin -d /var/www -c Apache -u 48 apache
useradd: user apache already exists
[root@centos8301 data]# userdel -r apache
userdel: apache mail spool (/var/spool/mail/apache) not found
userdel: apache home directory (/usr/share/httpd) not found
[root@centos8301 data]# useradd -r -s /sbin/nologin -d /var/www -c Apache -u 48 apache
[root@centos8301 data]# apachectl restart
# 验证服务端口
[root@centos8301]# ss -ntul
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
tcp LISTEN 0 128 *:80 *:*
tcp LISTEN 0 128 [::]:22 [::]:*
tcp LISTEN 0 5 [::1]:631 [::]:*
tcp LISTEN 0 128 [::]:111 [::]:*
[root@centos8301]#
# 未将apachectl设为开机启动,重启服务器需要重新启动服务
[root@centos8301]# apachectl start
3、利用sed 取出ifconfig命令中本机的IPv4地址
#查看网卡信息
[root@centos8301]# ifconfig
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.250.101 netmask 255.255.255.0 broadcast 192.168.250.255
inet6 fe80::4e77:57:8c52:15f1 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:18:d0:d9 txqueuelen 1000 (Ethernet)
RX packets 863 bytes 58238 (56.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 216 bytes 65057 (63.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 48 bytes 4080 (3.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 48 bytes 4080 (3.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:25:fa:2f txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
# 取出本机的网卡
[root@centos8301]# ifconfig ens192 | sed -n /inet /s#\\(.*inet \\)\\(.*\\)\\( n.*\\)#\\2#gp
192.168.250.101
[root@centos8301]# ifconfig virbr0 | sed -n /inet /s#\\(.*inet \\)\\(.*\\)\\( n.*\\)#\\2#gp
192.168.122.1
[root@centos8301]# ifconfig | sed -n /inet /s#\\(.*inet \\)\\(.*\\)\\( n.*\\)#\\2#gp
192.168.250.101
127.0.0.1
192.168.122.1
[root@centos8301]#
4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
# 查看原始文件
[root@centos8301 data]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Nov 17 12:07:16 2021
#
# 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.
#
# After editing this file, run systemctl daemon-reload to update systemd
# units generated from this file.
#
UUID=57d88699-5f3c-495b-841d-b607b63f889b / xfs defaults 0 0
UUID=06E3-23DB /boot/efi vfat umask=0077,shortname=winnt 0 2
UUID=52c97161-2220-4118-ab83-28a16d96ec18 /data xfs defaults 0 0
UUID=0228351d-2146-434d-b023-d47a0865d460 none swap defaults 0 0
[root@centos8301 data]#
[root@centos8301 data]# cp /etc/fstab fstab
[root@centos8301 data]# ls
fstab httpd-2.4.51.tar.bz2
[root@centos8301 data]# sed -ri.bak /^#/s/^#// /data/fstab
[root@centos8301 data]# cat fstab
/etc/fstab
Created by anaconda on Wed Nov 17 12:07:16 2021
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.
After editing this file, run systemctl daemon-reload to update systemd
units generated from this file.
UUID=57d88699-5f3c-495b-841d-b607b63f889b / xfs defaults 0 0
UUID=06E3-23DB /boot/efi vfat umask=0077,shortname=winnt 0 2
UUID=52c97161-2220-4118-ab83-28a16d96ec18 /data xfs defaults 0 0
UUID=0228351d-2146-434d-b023-d47a0865d460 none swap defaults 0 0
[root@centos8301 data]#
5、处理/etc/fstab路径,使用sed命令取出其目录名和基名
[root@centos8301 data]# echo /etc/fstab | sed -nr s@^(.*)/([^/]+)/?$@\\1@p
/etc
[root@centos8301 data]# echo /etc/fstab | sed -nr s@^(.*)/([^/]+)/?$@\\2@p
fstab
[root@centos8301 data]#
6、列出ubuntu软件管理工具apt的一些用法
apt-get update 更新源
apt update 更新包索引
# 命令的基本用法
summer@ubuntu180401:~$ sudo apt-get update
[sudo] password for summer:
Hit:1 http://hk.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://hk.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:3 http://hk.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:4 http://hk.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [2,328 kB]
Get:5 http://hk.archive.ubuntu.com/ubuntu bionic-updates/main i386 Packages [1,387 kB]
Get:6 http://hk.archive.ubuntu.com/ubuntu bionic-updates/universe i386 Packages [1,592 kB]
Get:7 http://hk.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1,771 kB]
Get:8 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Fetched 7,330 kB in 12s (608 kB/s)
Reading package lists... Done
summer@ubuntu180401:~$
summer@ubuntu180401:~$
summer@ubuntu180401:~$ sudo apt update
Hit:1 http://hk.archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://hk.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:3 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:4 http://hk.archive.ubuntu.com/ubuntu bionic-backports InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
45 packages can be upgraded. Run apt list --upgradable to see them.
summer@ubuntu180401:~$
apt-get install package 安装包
apt install package 安装软件包
apt-get remove package 删除包
apt remove package 删除软件包
apt-cache show package 获取包的相关信息,如说明、大小、版本等
apt-get install package --reinstall 重新安装包
apt-get -f install 修复安装
apt-get remove package --purge 删除包,包括配置文件等
apt-get build-dep package 安装相关的编译环境
apt-get upgrade 更新已安装的包
apt-get dist-upgrade 升级系统
apt-cache depends package 了解使用该包依赖那些包
apt-cache rdepends package 查看该包被哪些包依赖
apt-get source package 下载该包的源代码
apt list 列出仓库软件包
apt search nginx 搜索软件包
apt show nginx 查看某个软件包的详细信息
以上是关于自建yum仓库;编译安装http2.4 ;删除/etc/fstab文件中所有以#开头的行;sed 取本机的IP地址;sed命令取目录名的主要内容,如果未能解决你的问题,请参考以下文章