[步骤] CentOS dnf 的使用 (通过阿里源实现)

内容一:dnf 简介
1.1 dnf 软件简介

1) 从 CentOS8&RHEL8 开始默认使用 dnf 管理软件和补丁安装
2) dnf 也是 yum v4
3) dnf 的命令参数和 yum 一样
4) dnf 软件源的配置方法和 yum 一样

1.2 dnf 软件源简介

1) BaseOS 系统和基础的软件包
2) AppStream 其余所有官方的软件包

内容二:dnf 软件源的配置案例
2.1 删除原有的软件源配置文件

# rm /etc/yum.repos.d/*.repo

2.2 配置 AppStream 库

# vim /etc/yum.repos.d/CentOS-AppStream.repo

创建以下内容:

[AppStream]
name=CentOS-$releasever - AppStream
baseurl=http://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

2.3 配置 Base 库

# vim /etc/yum.repos.d/CentOS-Base.repo

创建以下内容:

[BaseOS]
name=CentOS-$releasever - Base
baseurl=http://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

2.4 配置 Epel 库

# vim /etc/yum.repos.d/CentOS-Epel.repo

创建以下内容:

[epel]
name=CentOS-$releasever - Epel
baseurl=http://mirrors.aliyun.com/epel/8/Everything/$basearch
enabled=1
gpgcheck=0

2.5 配置 Media 库

# vim /etc/yum.repos.d/CentOS-Media.repo

创建以下内容:

[c8-media-BaseOS]
name=CentOS-BaseOS-$releasever - Media
baseurl=file:///media/CentOS/BaseOS/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[c8-media-AppStream]
name=CentOS-AppStream-$releasever - Media
baseurl=file:///media/CentOS/AppStream/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

2.6 清除 dnf 缓存

# dnf clean all

2.7 刷新并列出 dnf 软件源列表

# dnf repolist

[步骤] Linux Nginx 源码安装包的管理 (通过 systemd 实现)

注意:在通过 systemd 管理源码安装的软件或自制 rpm 包安装的软件(以 Nginx 为例)之前,先要源码安装 Nginx 或者自制 rpm 包安装 Nginx

正文:

步骤目录:

步骤一:创建 Nginx 的 systemd 文件

步骤二:导入新创建的 Nginx systemd 配置文件

步骤三:使用 systemd 管理 Ngixn
3.1 使用 systemd 启动 Nginx
3.2 使用 systemd 开机自启 Nginx
3.3 使用 systemd 查看 Nginx 的状态

具体的操作步骤:

步骤一:创建 Nginx 的 systemd 文件

# vim /etc/systemd/system/nginx.service 

创建以下内容:

[Unit]

Description=nginx server daemon

Documentation=man:nginx(8)

After=network.target

[Service]

Type=forking

ExecStart=/usr/local/nginx/sbin/nginx

ExecReload=/usr/local/nginx/sbin/nginx -s reload

ExecStop=/usr/local/nginx/sbin/nginx -s stop

PrivateTmp=true

[Install]

WantedBy=multi-user.target

步骤二:导入新创建的 Nginx systemd 配置文件

# systemctl daemon-reload

步骤三:使用 systemd 管理 Ngixn
3.1 使用 systemd 启动 Nginx

# systemctl start nginx.service

3.2 使用 systemd 开机自启 Nginx

# systemctl enable nginx.service

3.3 使用 systemd 查看 Nginx 的状态

# systemctl status nginx.service

[内容] CentOS&RHEL yum 的使用 (让某一个软件不被更新)

内容一:通过命令实现更新某一个软件(补丁)包以外其他所有软件(补丁)包的方法

# yum -x httpd* updaten

(补充:这里以更新除了名字以 httpd 开头外的所有软件包为例)

(注意:这种方法只在本次输入时有效)

或者:

# yum --exclude=kernel* update

(补充:这里以更新除了名字以 kernel 开头外的所有软件包为例)

(注意:这种方法只在本次输入时有效)

内容二:通过配置文件实现更新某一个软件(补丁)包以外其他所有软件(补丁)包的方法
2.1 修改 yum 的配置文件

# vim /etc/yum.conf

添加以下内容:

......
exlude=mysql* kernel*

(补充:多个不需要升级的软件可以用空格隔开)

2.2 使用 yum

# yum update


注意:
1) 这种方法是永久生效
2) 这个文件可能是位于 /etc/yum.conf 中,也可能是位于 /etc/yum/yum.conf

[实验] Nginx 源码软件包的安装

纪念:站主于 2019 年 9 月完成了此开源实验,并将过程中的所有命令经过整理和注释以后,形成以下教程

软件准备:

在 Nginx 官网上下载搭建集群所需软件 Nginx:

http://nginx.org/en/download.html

正文:

步骤目录:

步骤一:系统环境要求

步骤二:安装 Nginx 的依赖软件

步骤三:安装 Nginx
3.1 添加一个用于启动 Nginx 的用户身份
3.2 解压 Nginx 安装包
3.3 进入 Nginx 安装包目录
3.4 配置 Nginx
3.5 编译并安装 Nginx

步骤四:测试 Nginx
4.1 启动 Nginx
4.2 访问 Nginx 实现的网页服务
4.3 查看已安装 Nginx 的版本

具体的操作步骤:

步骤一:系统环境要求

(1)服务器的系统需要是 CentOS 7 版本
(2)服务器系统需要有 yum 源

步骤二:安装 Nginx 的依赖软件

# yum -y install gcc pcre-devel openssl-devel

步骤三:安装 Nginx
3.1 添加一个用于启动 Nginx 的用户身份

# useradd -s /sbin/nologin nginx

3.2 解压 Nginx 安装包

# tar -xvf nginx-1.16.1.tar.gz

(补充:这里要安装的 Nginx 版本是 1.16.1)

3.3 进入 Nginx 安装包目录

# cd nginx-1.16.1

(补充:这里要安装的 Nginx 版本是 1.16.1)

3.4 配置 Nginx

# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module

3.5 编译并安装 Nginx

# make && make install

步骤四:测试 Nginx
4.1 启动 Nginx

# /usr/local/nginx/sbin/nginx

4.2 访问 Nginx 实现的网页服务

# curl 127.0.0.1

4.3 查看已安装 Nginx 的版本

# /usr/local/nginx/sbin/nginx -V