[实验] Linux RPM 软件包的制作 (通过 rpm-build 实现) (Nginx 版)

注意:

文中的很多信息例如软件的名称等是站主在本次操作中随意取的名称,读者可以根据自己的喜好换成任意别的名称

软件准备:

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

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

正文:

步骤一:系统环境要求

1) 服务器的系统是 CentOS 7 版本
2) 服务器系统要配置好 YUM 源

步骤二:准备 rpm-build 软件

2.1 安装 rpm-build

# yum -y install rpm-build

2.2 生成 rpm-build 目录

# rpmbuild -ba nginx.spec
error: failed to stat /root/nginx.spec: No such file or directory

2.3 显示生成的 rpm-build 目录

# ls /root/rpmbuild/
BUILD  BUILDROOT  RPMS	SOURCES  SPECS	SRPMS

步骤三:制作 Nginx 软件的 RPM 包

3.1 将 Nginx 的源码安装包放在固定的位置

# cp nginx-1.16.1.tar.gz /root/rpmbuild/SOURCES/

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

3.2 制作 Nginx 的 nginx.spec 文件

# vi /root/rpmbuild/SPECS/nginx.spec

将部分内容修改如下:

Name:nginx
Version:1.16.1
Release:1.0
Summary:Nginx is a web server software.
......
License:GPL
URL:www.nginx.org
Source0:%{name}-%{version}.tar
......
%description
nginx is an HTTP and reverse proxy server ......
......
%post
useradd nginx
......
%prep
%setup -q
......
%build
./configure --user=nginx --group=nginx --with-http_ssl_module
make %{?_smp_mflags}
%install
make install DESTDIR=%{buildroot}
......
%files
......
%doc
/usr/local/nginx/*
......
%changelog


补充:
1) 这里的 Name:nginx 是指软件名称是 nginx
2) 这里的 Version:1.16.1 是指软件的版本是 1.16.1
3) 这里的 Release:1.0 是指发布的版本是 1。0
4) 这里的 Summary: Nginx is a web server software. 是指软件的描述是 Summary: Nginx is a web server software.
5) 这里的 License:GPL 是指软件使用的协议是 GPL
6) 这里的 URL:www.nginx.org 是指软件的官网是 www.nginx.org
7) 这里的 Source0:%{name}-%{version}.tar 是指软件源码文件的名称
8) 这里的 #BuildRequires: 是指软件编译安装时需要的依赖包,这里没有内容
9) 这里的 #Requires: 是指软件安装时所需要的依赖包,这里没有内容
10) 这里的 %description 是指软件的详细描述,这里没有内容
11) 这里的

%post
useradd nginx

是指软件安装后创建 nginx 用户

12) 这里的 %prep 是指软件安装前的准备,这里没有内容
13) 这里的 %setup –q 是指自动解压软件的源码包,并 cd 进入刚刚解压出来的目录
14) 这里的

%build
./configure
make %{?_smp_mflags}

是指对源码安装包进行配置
15) 这里的

%install
make install DESTDIR=%{buildroot}

是指对源码安装包进行编译安装
16) 这里的

%files
%doc
/usr/local/nginx/*

是指将源码安装包安装到 /usr/local/nginx/ 目录里

3.4 安装 Nginx 软件的依赖包

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

3.5 生成 Nginx rpm 软件包

# rpmbuild -ba /root/rpmbuild/SPECS/nginx.spec

3.6 显示新生成的 Nginx rpm 软件包

# rpm -qpi /root/rpmbuild/RPMS/x86_64/nginx-1.16.1-1.0.x86_64.rpm

步骤四:使用新生成的 Nginx rpm 软件包

4.1 安装刚刚新生成的 Nginx rpm 软件包

# rpm -ivh /root/rpmbuild/RPMS/x86_64/nginx-1.16.1-1.0.x86_64.rpm

4.2 启动 Nginx 服务

# /usr/local/nginx/sbin/nginx

4.3 显示 Nginx 服务的启动状态

4.3.1 显示 Nginx 网页是否可以访问
# curl http://127.0.0.1/
4.3.2 显示 Nginx 的端口有没有启动
# ss -ntulap | grep 80

[工具] Shell 批量检测域名的 DNS 解析是否正确

介绍

基本信息

作者:朱明宇
名称:批量检测域名的 DNS 解析是否正确
作用:批量检测域名的 DNS 解析是否正确

使用方法

1. 在此脚本的分割线内写入相应的内容
2. 给此脚本添加执行权限
3. 执行此脚本

脚本分割线里的变量

1. main_domain=eternalcenter.com #此处填写网站的“主域名”,网站一般会有几个域名,其中“主域名”直接指向 ip 地址,其他的域名都指向主域名
2. ip=192.154.240.64 #域名指向的 ip 地址
3. nginx=1.16.0 #web 程序的对应版本的版本
4. content1=”eteranlcenter” # 随即填写一个具有代表性的网站首页的内容
5. content2=”Mingyu” # 随即填写一个具有代表性的网站首页的内容,但是要和前面的 content1 在同一行
6. domain=”eternalcenter.com eternalcentre.com zhumingyu.com mingyuzhu.com eternalcenter.org eternalcentre.org” #需要检测的域名

脚本

#!/bin/bash

####################### Separator ########################

main_domain=eternalcenter.com
ip=144.48.142.148
nginx=1.16.0
content1="eternalcenter"
content2="Mingyu"
domain="eternalcenter.com eternalcentre.com zhumingyu.com mingyuzhu.com eternalcenter.org eternalcentre.org"

####################### Separator ########################

check_domain_name(){
if [ $1 == $main_domain ];then
	
	ping -c4 -i0.4 $1 | grep $ip &> /dev/null
	if [ $? -ne 0 ];then
		echo -e "\033[31m $1 is error !!!!! ip is error !!!!! \033[0m"
	else
		curl $1 | grep $nginx &> /dev/null
		if [ $? -ne 0 ];then
			echo -e "\033[31m $1 is error !!!!! software is error !!!!! \033[0m"
		else	
			elinks $1 | grep "$content1" | grep "$content2" &> /dev/null
			if [ $? -ne 0 ];then
				echo -e "\033[31m $1 is error !!!!! web is error !!!!! \033[0m"
			else
				echo -e "\033[32m $1 is ok \033[0m"
			fi
		fi
		
	fi
else
	elinks $1 | grep "$content1" | grep "$content2" &> /dev/null
	if [ $? -ne 0 ];then
		echo -e "\033[31m $1 is error !!!!! web is error !!!!! \033[0m"
	else
		echo -e "\033[32m $1 is ok \033[0m"
	fi


fi
}

for i in $domain
do
	check_domain_name $i
done

[实验] FTP + Pacemaker 存储服务高可用的实现

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

注意:

在实现 FTP + Pacemaker 存储服务高可用之前要先安装 Pacemaker 集群 ,并且需要 root 权限

正文:

步骤一:Pacemaker 高可用 FTP 服务的解析

1.1 集群本身需要的服务

需要额外一台服务器提供 Iscasi 远程目录服务

1.2 本 Pacemaker 高可用 FTP 服务的特点

1) 使用其他服务器提供的 Iscasi 服务器作为 FTP 的共享目录
2) 提供 FTP 服务
4) 提供虚拟 IP 服务
5) 以上三项服务器都实现高可用
6) 唯一的单点故障在于额外的那台服务器提供的 Iscasi 远程目录服务器

步骤二:前期准备所有集群主机上都安装 FTP 服务

2.1 在所有集群主机上安装 FTP

(在所有集群服务器上执行以下步骤)

# yum -y install vsftpd

2.2 确保 vsftpd 服务没有启动

(在所有集群服务器上执行以下步骤)

# systemctl stop vsftpd
# systemctl disable vsftpd

步骤三:部署 Pacemaker 的 FTP 高可用服务

3.1 在 ftp 资源组中创建名为 ftpip 的虚拟 ip 资源

(只在一台集群里的服务器上执行以下步骤)

# pcs resource create ftpip IPaddr2 ip=192.168.0.21 cidr_netmask=24 --group ftp

3.2 在 ftp 资源组中创建名为 ftpfiles 挂载其他服务器的 Iscasi 服务的资源

(只在 1 台集群里的服务器上执行以下步骤)

# pcs resource create ftpfiles Filesystem device=192.168.8.21:/content/ftp directory=/var/ftp fstype=nfs options=ro --group ftp

(注意:这里的 Filesystem 指的是其他服务器搭建的 Iscasi 服务,这个服务需要提前搭建好)

3.3 在 ftp 资源组中创建名为 vsftpd 的 ftp 资源

(只在一台集群里的服务器上执行以下步骤)

# pcs resource create vsftpd systemd:vsftpd --group ftp

[实验] Apache + Pacemaker 网站服务高可用的实现

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

注意:

在实现 Apache + Pacemaker 网站服务高可用之前要先安装 Pacemaker 集群

正文:

步骤一:Pacemaker 高可用网站服务的解析

1.1 集群本身需要的服务

需要额外一台服务器提供 NFS 远程目录服务

1.2 本 Pacemaker 高可用网站服务的特点

1) 使用其他服务器提供的 NFS 服务器作为网站的网页目录
2) 提供网站 服务
3) 提供虚拟 IP 地址服务
4) 以上三项服务器都实现高可用
5) 唯一的单点故障在于额外的那台服务器提供的 NFS 远程目录服务器

步骤二:前期准备

2.1 在所有集群服务器上安装 httpd

(在所有集群服务器上执行以下步骤)

# yum -y install httpd

2.2 确保 httpd 不会被 SELinux 限制

(在所有集群服务器上执行以下步骤)

# setsebool -P httpd_use_nfs 1

(补充:这里是要求 SELinux 的布尔值让 httpd 也可以使用 NFS 服务)

2.3 确保 httpd 没有启动

(在所有集群服务器上执行以下步骤)

# systemctl stop httpd
# systemctl disable httpd

步骤三:部署 Pacemaker 的网站高可用服务

3.1 在 网站资源组中创建名为 webip 的虚拟 IP 地址资源

(只在一台集群里的服务器上执行以下步骤)

# pcs resource create webip IPaddr2 ip=192.168.0.20 cidr_netmask=24 --group=web

3.2 在 网站资源组中创建名为 webnfs 挂载其他服务器的 NFS 服务的资源

(只在一台集群里的服务器上执行以下步骤)

# pcs resource create webnfs Filesystem device=192.168.8.21:/content directory=/var/www/html fstype=nfs options=ro --group web

(注意:这里的 Filesystem 指的是其他服务器搭建的 NFS 服务,这个服务需要提前搭建好,可以参考 https://eternalcenter.com/nfs/ 里的内容)

3.3 在网站资源组中创建名为 webserver 的网站资源

(只在 1 台集群里的服务器上执行以下步骤)

# pcs resource create webserver apache configfile="/etc/httpd/conf/httpd.conf" statusurl="http://127.0.0.1/server-status" --group web

[内容] Apache 的使用 (开启网页目录结构)

内容一:开启 Apache 目录结构的目的

默认安装了 Apache 之后,被访问的网页只会显示一张 Apache 的欢迎页面或者 404
有时候我们需要让网页现实网页根 “/” 目录中的文件和目录,用于提供 http 下载等功能,这个时候就需要开启 Apache 的目录结构

内容二:开启 Apahce 目录结构的方法

# vim /etc/httpd/conf.d/welcome.conf

将其中的:

......
Options -Indexes 
......

修改为:

......
Options +Indexes 
......