10. 第八章 软件包管理

一.练习题

1、查询命令java来自于哪个rpm包

[root@centos8 ~]# yum provides java
Last metadata expiration check: 0:58:50 ago on Wed 02 Dec 2020 07:35:03 PM CST.
java-1.8.0-openjdk-1:1.8.0.272.b10-1.el8_2.x86_64 : OpenJDK Runtime Environment 8
Repo        : Appstream
Matched from:
Provide    : java = 1:1.8.0

2、yum配置和使用,包括yum仓库的创建

[root@centos8 ~]# cat /etc/yum.repos.d/base.repo
[BaseOS]
name=BaseOS
baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os
        https://mirrors.huaweicloud.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

[Appstream]
name=Appstream
baseurl=https://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/
        https://mirrors.huaweicloud.com/centos/$releasever/AppStream/$basearch/os/
gpgcheck=0
enabled=1

[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/8/extras/x86_64/os/
        https://mirrors.huaweicloud.com/centos/8/extras/x86_64/os/
gpgcheck=0

[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/8/Everything/x86_64/
        https://mirrors.huaweicloud.com/epel/8/Everything/x86_64/
gpgcheck=0

3、编写系统初始化脚本reset.sh,包括别名,提示符颜色,yum仓库配置文件,安装tree ,ftp,lftp,telnet等包

#!/bin/bash
#
#*************************************************************
#Author:          zhanghui
#QQ:              19661891
#Date:            2020-12-02
#FileName:        reset.sh
#URL:             www.neteagles.cn
#Description:     Reset CentOS
#Copyright (C):   2020 All rights reserved
#*************************************************************
. /etc/init.d/functions

centos_version() {
    sed -rn 's#^.* ([0-9]+)\..*#\1#p' /etc/redhat-release
}

disable_selinux(){
sed -ri.bak 's/^(SELINUX=).*/\1disabled/' /etc/selinux/config
action "CentOS`centos_version`SELinux已禁用,请重新启动系统后才能生效!"
}

set_alias(){
cat >>~/.bashrc <<EOF
alias cdnet="cd /etc/sysconfig/network-scripts"
alias editeth0="vim /etc/sysconfig/network-scripts/ifcfg-eth0"
alias scandisk="echo '- - -' > /sys/class/scsi_host/host0/scan;echo '- - -' > /sys/class/scsi_host/host1/scan;echo '- - -' > /sys/class/scsi_host/host2/scan"
EOF
action "CentOS`centos_version`系统别名已设置成功,请重新登陆后生效!"
}

set_vimrc(){
cat >~/.vimrc <<EOF  
set ts=4
set expandtab
set ignorecase
set cursorline
set autoindent
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
	if expand("%:e") == 'sh'
	call setline(1,"#!/bin/bash") 
	call setline(2,"#") 
	call setline(3,"#********************************************************************") 
	call setline(4,"#Author:		    zhanghui") 
	call setline(5,"#QQ: 			    19661891") 
	call setline(6,"#Date: 			    ".strftime("%Y-%m-%d"))
	call setline(7,"#FileName:		    ".expand("%"))
	call setline(8,"#URL: 			    www.neteagles.cn")
	call setline(9,"#Description:		The test script") 
	call setline(10,"#Copyright (C): 	".strftime("%Y")." All rights reserved")
	call setline(11,"#********************************************************************") 
	call setline(12,"") 
	endif
endfunc
autocmd BufNewFile * normal G
EOF
action "CentOS`centos_version`vimrc设置完成,请重新系统启动才能生效!"
}

set_mailrc(){
rpm -q postfix &> /dev/null || { yum -y install postfix &> /dev/null; systemctl enable --now postfix &> /dev/null; }
rpm -q mailx &> /dev/null || yum -y install mailx &> /dev/null
read -p "请输入邮箱地址:" MAIL
read -p "请输入邮箱授权码:" AUTH
SMTP=`echo ${MAIL} |awk -F"@" '{print $2}'`
cat >~/.mailrc <<-EOF
set from=${MAIL}
set smtp=smtp.${SMTP}
set smtp-auth-user=${MAIL}
set smtp-auth-password=${AUTH}
set smtp-auth=login
set ssl-verify=ignore
EOF
action "CentOS`centos_version`mailrc设置完成,请重新登录后才能生效!"
}

disable_firewalld_centos78(){
systemctl disable --now firewalld &> /dev/null
action "CentOS`centos_version`防火墙已关闭!"
}

disable_firewalld_centos6(){
chkconfig iptables off
action "CentOS`centos_version`防火墙已关闭!"
}

disable_firewalld(){
centos_version | while read ov ;do
	if [ $ov -eq 6 ];then 
		disable_firewalld_centos6
	else
		disable_firewalld_centos78
	fi
done
}

set_yum_centos8(){
mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
cat > /etc/yum.repos.d/base.repo <<EOF
[BaseOS]
name=BaseOS
baseurl=https://mirrors.aliyun.com/centos/\$releasever/BaseOS/\$basearch/os/
        https://mirrors.huaweicloud.com/centos/\$releasever/BaseOS/\$basearch/os/
        https://mirrors.cloud.tencent.com/centos/\$releasever/BaseOS/\$basearch/os/
        https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/BaseOS/\$basearch/os/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[AppStream]
name=AppStream
baseurl=https://mirrors.aliyun.com/centos/\$releasever/AppStream/\$basearch/os/
        https://mirrors.huaweicloud.com/centos/\$releasever/AppStream/\$basearch/os/
        https://mirrors.cloud.tencent.com/centos/\$releasever/AppStream/\$basearch/os/
        https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/AppStream/\$basearch/os/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[EPEL]
name=EPEL
baseurl=https://mirrors.aliyun.com/epel/\$releasever/Everything/\$basearch/
        https://mirrors.huaweicloud.com/epel/\$releasever/Everything/\$basearch/
        https://mirrors.cloud.tencent.com/epel/\$releasever/Everything/\$basearch/
        https://mirrors.tuna.tsinghua.edu.cn/epel/\$releasever/Everything/\$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-\$releasever

[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/os/
        https://mirrors.huaweicloud.com/centos/\$releasever/extras/\$basearch/os/
        https://mirrors.cloud.tencent.com/centos/\$releasever/extras/\$basearch/os/
        https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/extras/\$basearch/os/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
enabled=1

[centosplus]
name=centosplus
baseurl=https://mirrors.aliyun.com/centos/\$releasever/centosplus/\$basearch/os/
        https://mirrors.huaweicloud.com/centos/\$releasever/centosplus/\$basearch/os/
        https://mirrors.cloud.tencent.com/centos/\$releasever/centosplus/\$basearch/os/
        https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/centosplus/\$basearch/os/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
dnf clean all
dnf repolist
action "CentOS`centos_version`阿里YUM源设置完成!"
}

set_yum_centos67(){
mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=base
baseurl=https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/ 
        https://mirrors.huaweicloud.com/centos/\$releasever/os/\$basearch/ 
        https://mirrors.cloud.tencent.com/centos/\$releasever/os/\$basearch/
        https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/os/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-\$releasever

[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/\$releasever/\$basearch/
        https://mirrors.huaweicloud.com/epel/\$releasever/\$basearch/
        https://mirrors.cloud.tencent.com/epel/\$releasever/\$basearch/
        https://mirrors.tuna.tsinghua.edu.cn/epel/\$releasever/\$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-\$releasever

[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/
        https://mirrors.huaweicloud.com/centos/\$releasever/extras/\$basearch/
        https://mirrors.cloud.tencent.com/centos/\$releasever/extras/\$basearch/
        https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/extras/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-\$releasever

[updates]
name=updates
baseurl=https://mirrors.aliyun.com/centos/\$releasever/updates/\$basearch/
        https://mirrors.huaweicloud.com/centos/\$releasever/updates/\$basearch/
        https://mirrors.cloud.tencent.com/centos/\$releasever/updates/\$basearch/
        https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/updates/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-\$releasever

[centosplus]
name=centosplus
baseurl=https://mirrors.aliyun.com/centos/\$releasever/centosplus/\$basearch/
        https://mirrors.huaweicloud.com/centos/\$releasever/centosplus/\$basearch/
        https://mirrors.cloud.tencent.com/centos/\$releasever/centosplus/\$basearch/
        https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/centosplus/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-\$releasever
EOF
yum clean all
yum repolist
action "CentOS`centos_version`阿里YUM源设置完成!"
}

set_yum(){
centos_version | while read ov2 ;do
        if [ $ov2 -eq 8 ];then
                set_yum_centos8
        else
                set_yum_centos67
        fi
done
}

set_eth(){
ETHNAME=`ifconfig |head -1| tr -s ":" " "|cut -d" " -f 1`
#修改网卡名称配置文件
sed -ri.bak '/^GRUB_CMDLINE_LINUX=/s@"$@ net.ifnames=0"@' /etc/default/grub 
grub2-mkconfig -o /boot/grub2/grub.cfg >& /dev/null
                                     
#修改网卡文件名
mv /etc/sysconfig/network-scripts/ifcfg-${ETHNAME} /etc/sysconfig/network-scripts/ifcfg-eth0
                                                                                                                
#修改配置文件
sed -i.bak -e 's/NAME="'${ETHNAME}'"/NAME="eth0"/' -e 's/DEVICE="'${ETHNAME}'"/DEVICE="eth0"/' /etc/sysconfig/network-scripts/ifcfg-eth0

#修改IP地址
read -p "请输入IP地址:"  IP
 echo  $IP
echo "$IP" | grep -E --color '^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])\.(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){2}([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])$'
if [ $? -ne 0 ];then
	echo "你输入ip地址不符和要求"
	exit
fi
cat >> /etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF
IPADDR=$IP
NETMASK=255.255.255.0
GATEWAY=10.0.0.2
DNS1=223.5.5.5
DNS2=223.6.6.6
EOF
sed -i.bak -e 's/BOOTPROTO="dhcp"/BOOTPROTO="none"/' /etc/sysconfig/network-scripts/ifcfg-eth0 
action "CentOS`centos_version`网卡名和IP地址已修改成功,请重新启动系统后才能生效!"
}

set_ip_centos6(){
read -p "请输入IP地址:"  IP
 echo  $IP
echo "$IP" | grep -E --color '^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])\.(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){2}([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])$'
if [ $? -ne 0 ];then
        echo "你输入ip地址不符和要求"
        exit
fi
cat >> /etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF
IPADDR=$IP
NETMASK=255.255.255.0
GATEWAY=10.0.0.2
DNS1=223.5.5.5
EOF
sed -i.bak -e 's/BOOTPROTO=dhcp/BOOTPROTO=none/' /etc/sysconfig/network-scripts/ifcfg-eth0
action "CentOS`centos_version`IP地址已修改成功,请重新启动系统后才能生效!"
}

centos_minimal_install(){
yum -y install  gcc make autoconf gcc-c++ glibc glibc-devel pcre pcre-devel openssl  openssl-devel systemd-devel zlib-devel  vim lrzsz tree  tmux  lsof tcpdump wget  net-tools iotop bc  bzip2 zip unzip nfs-utils man-pages
action "CentOS`centos_version`最小化安装建议安装软件已安装完成!"
}

set_centosps1(){
TIPS="action CentOS`centos_version`PS1已设置完成,请重新登录生效!"
while true;do
echo -e "\E[$[RANDOM%7+31];1m"
cat <<EOF
1)31 红色
2)32 绿色
3)33 黄色
4)34 蓝色
5)35 紫色
6)36 青色
7)随机颜色
8)退出
EOF
echo -e '\E[0m'

read -p "请输入颜色编号(1-8)" NUM
case $NUM in
1)
	echo "PS1='\[\e[1;31m\][\u@\h \W]\\$ \[\e[0m\]'" > /etc/profile.d/env.sh
	$TIPS
	;;
2)
	echo "PS1='\[\e[1;32m\][\u@\h \W]\\$ \[\e[0m\]'" > /etc/profile.d/env.sh
	$TIPS
	;;
3)
	echo "PS1='\[\e[1;33m\][\u@\h \W]\\$ \[\e[0m\]'" > /etc/profile.d/env.sh
	$TIPS  
	;;
4)
	echo "PS1='\[\e[1;34m\][\u@\h \W]\\$ \[\e[0m\]'" > /etc/profile.d/env.sh
	$TIPS
	;;
5)
	echo "PS1='\[\e[1;35m\][\u@\h \W]\\$ \[\e[0m\]'" > /etc/profile.d/env.sh
	$TIPS
	;;
6)
	echo "PS1='\[\e[1;36m\][\u@\h \W]\\$ \[\e[0m\]'" > /etc/profile.d/env.sh
	$TIPS
	;;
7)
    echo "PS1='\[\e[1;"$[RANDOM%7+31]"m\][\u@\h \W]\\$ \[\e[0m\]'" > /etc/profile.d/env.sh
	$TIPS
	;;
8)
	break
	;;
*)
	echo -e "\e[1;31m输入错误,请输入正确的数字(1-8)!\e[0m"
	;;
esac	
done
}

PS3="请选择相应的编号(1-13):"
MENU=" 
CentOS禁用SELinux
CentOS设置系统别名
CentOS设置vimrc配置文件
CentOS设置mailrc配置文件
CentOS关闭防火墙 
CentOS设置YUM源
CentOS_Minimal安装建议安装软件
CentOS1-7全执行
CentOS7和8修改网卡名和IP地址
CentOS6修改IP地址
CentOS设置PS1(请进入选择颜色)
重启系统
退出
"

select menu in $MENU;do
case $REPLY in
1)
	disable_selinux
	;;
2)
	set_alias
	;;
3)
	set_vimrc
	;;
4)
	set_mailrc
	;;
5)
	disable_firewalld
	;;
6)
	set_yum
	;;
7)
	centos_minimal_install
	;;
8)
	disable_selinux
	set_alias
    set_vimrc
	set_mailrc
	disable_firewalld
	set_yum
	centos_minimal_install
	;;
9)
	set_eth
	;;
10)
	set_ip_centos6
	;;
11)
	set_centosps1
	;;
12)
	reboot
	;;
13)
	break
	;;
*)
	echo -e "\e[1;31m输入错误,请输入正确的数字(1-13)!\e[0m"
	;;
esac
done



#!/bin/bash
#
#*************************************************************
#Author:          zhanghui
#QQ:              19661891
#Date:            2020-11-22
#FileName:        reset.sh
#URL:             www.neteagles.cn
#Description:     The test script
#Copyright (C):   2020 All rights reserved
#*************************************************************
set_vimrc(){
cat >~/.vimrc <<EOF  
set ts=4
set expandtab
set ignorecase
set cursorline
set autoindent
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
	if expand("%:e") == 'sh'
	call setline(1,"#!/bin/bash") 
	call setline(2,"#") 
	call setline(3,"#********************************************************************") 
	call setline(4,"#Author:		    zhanghui") 
	call setline(5,"#QQ: 			    19661891") 
	call setline(6,"#Date: 			    ".strftime("%Y-%m-%d"))
	call setline(7,"#FileName:		    ".expand("%"))
	call setline(8,"#URL: 			    www.neteagles.cn")
	call setline(9,"#Description:		The test script") 
	call setline(10,"#Copyright (C): 	".strftime("%Y")." All rights reserved")
	call setline(11,"#********************************************************************") 
	call setline(12,"") 
	endif
endfunc
autocmd BufNewFile * normal G
EOF
echo -e "\e[1;31mvimrc设置完成,请重新启动才能生效!\e[0m"
}

ubuntu_version(){
	sed -rn '2s/^.*="([0-9]+)\..*/\1/p' /etc/os-release
}

set_apt_18(){
mv /etc/apt/sources.list /etc/apt/sources.list.bak
cat > /etc/apt/sources.list <<EOF
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
EOF
apt update
echo -e "\e[1;31mUbuntu阿里源设置完成!\e[0m"
}

set_apt_20(){
mv /etc/apt/sources.list /etc/apt/sources.list.bak
cat > /etc/apt/sources.list <<EOF
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
EOF
apt update
echo -e "\e[1;31mUbuntu阿里源设置完成!\e[0m"
}

set_apt(){
ubuntu_version | while read ov ;do
        if [ $ov -eq 18 ];then
                set_apt_18
        else
                set_apt_20
        fi
done
}

ubuntu_minimal_install(){
apt -y install iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev gcc openssh-server iotop unzip zip
}

unsetps1(){
currentps1set=`grep "^PS1.*" ~/.bashrc |cut -d "=" -f 1`
if [ "$currentps1set" = "PS1" ] ;then
	sed -i "/^PS1.*/d" ~/.bashrc
	echo -e "\e[1;31m已清空PS1设置,请重新设置\e[0m"
else
	echo -e "\e[1;31m没有设置PS1,请直接设置\e[0m"
fi
}

set_ubuntups1(){
TIPS="echo -e \e[1;31mPS1已设置完成,请重新登录生效!\e[0m"
while true;do
echo -e "\E[$[RANDOM%7+31];1m"
cat <<EOF
1)31 红色
2)32 绿色
3)33 黄色
4)34 蓝色
5)35 紫色
6)36 青色
7)随机颜色
8)清空PS1设置
9)退出
EOF
echo -e '\E[0m'

read -p "请输入颜色编号(1-9)" NUM
case $NUM in
1)
	echo 'PS1="\[\e[1;31m\]${debian_chroot:+($debian_chroot)}\u@\h:\w\\$ \[\e[0m\]"' >> ~/.bashrc
	$TIPS
	;;
2)
	echo 'PS1="\[\e[1;32m\]${debian_chroot:+($debian_chroot)}\u@\h:\w\\$ \[\e[0m\]"' >> ~/.bashrc
	$TIPS
	;;
3)
	echo 'PS1="\[\e[1;33m\]${debian_chroot:+($debian_chroot)}\u@\h:\w\\$ \[\e[0m\]"' >> ~/.bashrc	
	$TIPS  
	;;
4)
	echo 'PS1="\[\e[1;34m\]${debian_chroot:+($debian_chroot)}\u@\h:\w\\$ \[\e[0m\]"' >> ~/.bashrc
	$TIPS
	;;
5)
	echo 'PS1="\[\e[1;35m\]${debian_chroot:+($debian_chroot)}\u@\h:\w\\$ \[\e[0m\]"' >> ~/.bashrc
	$TIPS
	;;
6)
	echo 'PS1="\[\e[1;36m\]${debian_chroot:+($debian_chroot)}\u@\h:\w\\$ \[\e[0m\]"' >> ~/.bashrc
	$TIPS
	;;
7)
	echo 'PS1="\[\e[1;'$[RANDOM%7+31]'m\]${debian_chroot:+($debian_chroot)}\u@\h:\w\\$ \[\e[0m\]"' >> ~/.bashrc
	$TIPS
	;;
8)
	unsetps1 
	;;
9)
	break
	;;
*)
	echo -e "\e[1;31m输入错误,请输入正确的数字(1-9)!\e[0m"
	;;
esac	
done
}

PS3="请选择相应的编号(1-7):"
MENU=" 
Ubuntu设置vimrc配置文件
Ubuntu设置阿里APT源
Ubuntu_Minimal安装建议安装软件
Ubuntu1-3全执行
Ubuntu设置PS1(请进入选择颜色)
重启系统
退出
"

select menu in $MENU;do
case $REPLY in
1)
	set_vimrc
	;;
2)
        set_apt
        ;;
3)
        ubuntu_minimal_install
        ;;

4)
	set_vimrc
	set_apt
	ubuntu_minimal_install
        ;;
5)
	set_ubuntups1
	;;
6)
	reboot
	;;
7)
	break
	;;
*)
	echo -e "\e[1;31m输入错误,请输入正确的数字(1-7)!\e[0m"
	;;
esac
done

4、在CentOS 8上编译安装apache 2.4.43源码包,并启动此服务

http://httpd.apache.org/

[root@centos8 cmatrix]# yum info httpd
Last metadata expiration check: 2:38:48 ago on Wed 02 Dec 2020 04:34:36 PM CST.
Installed Packages
Name         : httpd
Version      : 2.4.37
Release      : 21.module_el8.2.0+494+1df74eae
Architecture : x86_64
Size         : 4.9 M
Source       : httpd-2.4.37-21.module_el8.2.0+494+1df74eae.src.rpm
Repository   : @System
From repo    : Appstream
Summary      : Apache HTTP Server
URL          : https://httpd.apache.org/
License      : ASL 2.0
Description  : The Apache HTTP Server is a powerful, efficient, and extensible

[root@centos8 ~]# wget https://mirrors.bfsu.edu.cn/apache//httpd/httpd-2.4.46.tar.bz2 -P /usr/local/src

[root@centos8 ~]# cd /usr/local/src
[root@centos8 src]# ls
cmatrix  cmatrix-v2.0-Butterscotch.tar  httpd-2.4.46.tar.bz2  tree-1.8.0.tgz

[root@centos8 src]# tar xf httpd-2.4.46.tar.bz2 
tar (child): lbzip2: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
[root@centos8 src]# dnf -y install bzip2

[root@centos8 src]# cd httpd-2.4.46
[root@centos8 httpd-2.4.46]# ls
ABOUT_APACHE     BuildAll.dsp    configure.in  include         LICENSE        README            test
acinclude.m4     BuildBin.dsp    docs          INSTALL         Makefile.in    README.cmake      VERSIONING
Apache-apr2.dsw  buildconf       emacs-style   InstallBin.dsp  Makefile.win   README.platforms
Apache.dsw       CHANGES         httpd.dep     LAYOUT          modules        ROADMAP
apache_probes.d  CMakeLists.txt  httpd.dsp     libhttpd.dep    NOTICE         server
ap.d             config.layout   httpd.mak     libhttpd.dsp    NWGNUmakefile  srclib
build            configure       httpd.spec    libhttpd.mak    os             support

[root@centos8 httpd-2.4.46]# cat README
#README  告诉你软件怎么用的

[root@centos8 httpd-2.4.46]# cat INSTALL 
#INSTALL  安装方法

[root@centos8 httpd-2.4.46]# ./configure --help
`configure' configures this package to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local/apache2]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, `make install' will install all the files in
`/usr/local/apache2/bin', `/usr/local/apache2/lib' etc.  You can specify
an installation prefix other than `/usr/local/apache2' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/PACKAGE]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]

System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  --target=TARGET   configure for building compilers for TARGET [HOST]

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --enable-layout=LAYOUT
  --enable-dtrace         Enable DTrace probes
  --enable-hook-probes    Enable APR hook probes
  --enable-exception-hook Enable fatal exception hook
  --enable-load-all-modules
                          Load all modules
  --enable-maintainer-mode
                          Turn on debugging and compile time warnings and load
                          all compiled modules
  --enable-debugger-mode  Turn on debugging and compile time warnings and turn
                          off optimization
  --enable-pie            Build httpd as a Position Independent Executable
  --enable-modules=MODULE-LIST
                          Space-separated list of modules to enable | "all" |
                          "most" | "few" | "none" | "reallyall"
  --enable-mods-shared=MODULE-LIST
                          Space-separated list of shared modules to enable |
                          "all" | "most" | "few" | "reallyall"
  --enable-mods-static=MODULE-LIST
                          Space-separated list of static modules to enable |
                          "all" | "most" | "few" | "reallyall"
  --disable-authn-file    file-based authentication control
  --enable-authn-dbm      DBM-based authentication control
  --enable-authn-anon     anonymous user authentication control
  --enable-authn-dbd      SQL-based authentication control
  --enable-authn-socache  Cached authentication control
  --disable-authn-core    core authentication module
  --disable-authz-host    host-based authorization control
  --disable-authz-groupfile
                          'require group' authorization control
  --disable-authz-user    'require user' authorization control
  --enable-authz-dbm      DBM-based authorization control
  --enable-authz-owner    'require file-owner' authorization control
  --enable-authz-dbd      SQL based authorization and Login/Session support
  --disable-authz-core    core authorization provider vector module
  --enable-authnz-ldap    LDAP based authentication
  --enable-authnz-fcgi    FastCGI authorizer-based authentication and
                          authorization
  --disable-access-compat mod_access compatibility
  --disable-auth-basic    basic authentication
  --enable-auth-form      form authentication
  --enable-auth-digest    RFC2617 Digest authentication
  --enable-allowmethods   restrict allowed HTTP methods
  --enable-isapi          isapi extension support
  --enable-file-cache     File cache
  --enable-cache          dynamic file caching. At least one storage
                          management module (e.g. mod_cache_disk) is also
                          necessary.
  --enable-cache-disk     disk caching module
  --enable-cache-socache  shared object caching module
  --enable-socache-shmcb  shmcb small object cache provider
  --enable-socache-dbm    dbm small object cache provider
  --enable-socache-memcache
                          memcache small object cache provider
  --enable-socache-redis  redis small object cache provider
  --enable-socache-dc     distcache small object cache provider
  --enable-so             DSO capability. This module will be automatically
                          enabled unless you build all modules statically.
  --enable-watchdog       Watchdog module
  --enable-macro          Define and use macros in configuration files
  --enable-dbd            Apache DBD Framework
  --enable-bucketeer      buckets manipulation filter. Useful only for
                          developers and testing purposes.
  --enable-dumpio         I/O dump filter
  --enable-echo           ECHO server
  --enable-example-hooks  Example hook callback handler module
  --enable-case-filter    Example uppercase conversion filter
  --enable-case-filter-in Example uppercase conversion input filter
  --enable-example-ipc    Example of shared memory and mutex usage
  --enable-buffer         Filter Buffering
  --enable-data           RFC2397 data encoder
  --enable-ratelimit      Output Bandwidth Limiting
  --disable-reqtimeout    Limit time waiting for request from client
  --enable-ext-filter     external filter module
  --enable-request        Request Body Filtering
  --enable-include        Server Side Includes
  --disable-filter        Smart Filtering
  --enable-reflector      Reflect request through the output filter stack
  --enable-substitute     response content rewrite-like filtering
  --enable-sed            filter request and/or response bodies through sed
  --disable-charset-lite  character set translation. Enabled by default only
                          on EBCDIC systems.
  --enable-charset-lite   character set translation. Enabled by default only
                          on EBCDIC systems.
  --enable-deflate        Deflate transfer encoding support
  --enable-xml2enc        i18n support for markup filters
  --enable-proxy-html     Fix HTML Links in a Reverse Proxy
  --enable-brotli         Brotli compression support
  --enable-http           HTTP protocol handling. The http module is a basic
                          one that enables the server to function as an HTTP
                          server. It is only useful to disable it if you want
                          to use another protocol module instead. Don't
                          disable this module unless you are really sure what
                          you are doing. Note: This module will always be
                          linked statically.
  --disable-mime          mapping of file-extension to MIME. Disabling this
                          module is normally not recommended.
  --enable-ldap           LDAP caching and connection pooling services
  --disable-log-config    logging configuration. You won't be able to log
                          requests to the server without this module.
  --enable-log-debug      configurable debug logging
  --enable-log-forensic   forensic logging
  --enable-logio          input and output logging
  --enable-lua            Apache Lua Framework
  --enable-luajit         Enable LuaJit Support
  --disable-env           clearing/setting of ENV vars
  --enable-mime-magic     automagically determining MIME type
  --enable-cern-meta      CERN-type meta files
  --enable-expires        Expires header control
  --disable-headers       HTTP header control
  --enable-ident          RFC 1413 identity check
  --enable-usertrack      user-session tracking
  --enable-unique-id      per-request unique ids
  --disable-setenvif      basing ENV vars on headers
  --disable-version       determining httpd version in config files
  --enable-remoteip       translate header contents to an apparent client
                          remote_ip
  --enable-proxy          Apache proxy module
  --enable-proxy-connect  Apache proxy CONNECT module. Requires
                          --enable-proxy.
  --enable-proxy-ftp      Apache proxy FTP module. Requires --enable-proxy.
  --enable-proxy-http     Apache proxy HTTP module. Requires --enable-proxy.
  --enable-proxy-fcgi     Apache proxy FastCGI module. Requires
                          --enable-proxy.
  --enable-proxy-scgi     Apache proxy SCGI module. Requires --enable-proxy.
  --enable-proxy-uwsgi    Apache proxy UWSGI module. Requires --enable-proxy.
  --enable-proxy-fdpass   Apache proxy to Unix Daemon Socket module. Requires
                          --enable-proxy.
  --enable-proxy-wstunnel Apache proxy Websocket Tunnel module. Requires
                          --enable-proxy.
  --enable-proxy-ajp      Apache proxy AJP module. Requires --enable-proxy.
  --enable-proxy-balancer Apache proxy BALANCER module. Requires
                          --enable-proxy.
  --enable-proxy-express  mass reverse-proxy module. Requires --enable-proxy.
  --enable-proxy-hcheck   reverse-proxy health-check module. Requires
                          --enable-proxy and --enable-watchdog.
  --enable-session        session module
  --enable-session-cookie session cookie module
  --enable-session-crypto session crypto module
  --enable-session-dbd    session dbd module
  --enable-slotmem-shm    slotmem provider that uses shared memory
  --enable-slotmem-plain  slotmem provider that uses plain memory
  --enable-ssl            SSL/TLS support (mod_ssl)
  --enable-ssl-staticlib-deps
                          link mod_ssl with dependencies of OpenSSL's static
                          libraries (as indicated by "pkg-config --static").
                          Must be specified in addition to --enable-ssl.
  --enable-optional-hook-export
                          example optional hook exporter
  --enable-optional-hook-import
                          example optional hook importer
  --enable-optional-fn-import
                          example optional function importer
  --enable-optional-fn-export
                          example optional function exporter
  --enable-dialup         rate limits static files to dialup modem speeds
  --enable-static-support Build a statically linked version of the support
                          binaries
  --enable-static-htpasswd
                          Build a statically linked version of htpasswd
  --enable-static-htdigest
                          Build a statically linked version of htdigest
  --enable-static-rotatelogs
                          Build a statically linked version of rotatelogs
  --enable-static-logresolve
                          Build a statically linked version of logresolve
  --enable-static-htdbm   Build a statically linked version of htdbm
  --enable-static-ab      Build a statically linked version of ab
  --enable-static-checkgid
                          Build a statically linked version of checkgid
  --enable-static-htcacheclean
                          Build a statically linked version of htcacheclean
  --enable-static-httxt2dbm
                          Build a statically linked version of httxt2dbm
  --enable-static-fcgistarter
                          Build a statically linked version of fcgistarter
  --enable-http2          HTTP/2 protocol handling in addition to HTTP
                          protocol handling. Implemented by mod_http2. This
                          module requires a libnghttp2 installation. See
                          --with-nghttp2 on how to manage non-standard
                          locations. This module is usually linked shared and
                          requires loading.
  --enable-nghttp2-staticlib-deps
                          link mod_http2 with dependencies of libnghttp2's
                          static libraries (as indicated by "pkg-config
                          --static"). Must be specified in addition to
                          --enable-http2.
  --enable-proxy-http2    HTTP/2 proxy module. This module requires a
                          libnghttp2 installation. See --with-nghttp2 on how
                          to manage non-standard locations. Also requires
                          --enable-proxy.
  --enable-md             Managed Domain handling
  --enable-jansson-staticlib-deps
                          link mod_md with dependencies of libjansson's static
                          libraries (as indicated by "pkg-config --static").
                          Must be specified in addition to --enable-md.
  --enable-curl-staticlib-deps
                          link mod_md with dependencies of libcurl's static
                          libraries (as indicated by "pkg-config --static").
                          Must be specified in addition to --enable-md.
  --enable-lbmethod-byrequests
                          Apache proxy Load balancing by request counting
  --enable-lbmethod-bytraffic
                          Apache proxy Load balancing by traffic counting
  --enable-lbmethod-bybusyness
                          Apache proxy Load balancing by busyness
  --enable-lbmethod-heartbeat
                          Apache proxy Load balancing from Heartbeats
  --enable-mpms-shared=MPM-LIST
                          Space-separated list of MPM modules to enable for
                          dynamic loading. MPM-LIST=list | "all"
  --enable-unixd          unix specific support
  --enable-privileges     Per-virtualhost Unix UserIDs and enhanced security
                          for Solaris
  --enable-systemd        Systemd support
  --enable-heartbeat      Generates Heartbeats
  --enable-heartmonitor   Collects Heartbeats
  --enable-dav            WebDAV protocol handling. --enable-dav also enables
                          mod_dav_fs
  --disable-status        process/thread monitoring
  --disable-autoindex     directory listing
  --enable-asis           as-is filetypes
  --enable-info           server information
  --enable-suexec         set uid and gid for spawned processes
  --enable-cgid           CGI scripts. Enabled by default with threaded MPMs
  --enable-cgi            CGI scripts. Enabled by default with non-threaded
                          MPMs
  --enable-dav-fs         DAV provider for the filesystem. --enable-dav also
                          enables mod_dav_fs.
  --enable-dav-lock       DAV provider for generic locking
  --enable-vhost-alias    mass virtual hosting module
  --enable-negotiation    content negotiation
  --disable-dir           directory request handling
  --enable-imagemap       server-side imagemaps
  --enable-actions        Action triggering on requests
  --enable-speling        correct common URL misspellings
  --enable-userdir        mapping of requests to user-specific directories
  --disable-alias         mapping of requests to different filesystem parts
  --enable-rewrite        rule based URL manipulation
  --enable-suexec-capabilities
                          Use Linux capability bits not setuid root suexec
  --enable-v4-mapped      Allow IPv6 sockets to handle IPv4 connections

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-included-apr     Use bundled copies of APR/APR-Util
  --with-apr=PATH         prefix for installed APR or the full path to
                             apr-config
  --with-apr-util=PATH    prefix for installed APU or the full path to
                             apu-config
  --with-pcre=PATH        Use external PCRE library
  --with-port=PORT        Port on which to listen (default is 80)
  --with-sslport=SSLPORT  Port on which to securelisten (default is 443)
  --with-distcache=PATH   Distcache installation directory
  --with-z=PATH           use a specific zlib library
  --with-libxml2=PATH     location for libxml2
  --with-brotli=PATH      Brotli installation directory
  --with-lua=PATH         Path to the Lua 5.3/5.2/5.1 prefix
  --with-ssl=PATH         OpenSSL installation directory
  --with-nghttp2=PATH     nghttp2 installation directory
  --with-jansson=PATH     jansson installation directory
  --with-curl=PATH        curl installation directory
  --with-mpm=MPM          Choose the process model for Apache to use by
                          default. MPM={event|worker|prefork|winnt} This will
                          be statically linked as the only available MPM
                          unless --enable-mpms-shared is also specified.
  --with-module=module-type:module-file
                          Enable module-file in the modules/<module-type>
                          directory.
  --with-program-name     alternate executable name
  --with-suexec-bin       Path to suexec binary
  --with-suexec-caller    User allowed to call SuExec
  --with-suexec-userdir   User subdirectory
  --with-suexec-docroot   SuExec root directory
  --with-suexec-uidmin    Minimal allowed UID
  --with-suexec-gidmin    Minimal allowed GID
  --with-suexec-logfile   Set the logfile
  --with-suexec-syslog    Use syslog for suexec logging
  --with-suexec-safepath  Set the safepath
  --with-suexec-umask     umask for suexec'd process

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CPP         C preprocessor

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to the package provider.


[root@centos8 httpd-2.4.46]# ./configure --prefix=/apps/httpd --enable-ssl
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... no
configure: error: APR not found.  Please read the documentation.
#提示缺失 APR

[root@centos8 httpd-2.4.46]# dnf -y install apr-devel 

[root@centos8 httpd-2.4.46]# ./configure --prefix=/apps/httpd --enable-ssl
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... yes
  setting CC to "gcc"
  setting CPP to "gcc -E"
  setting CFLAGS to "  -pthread"
  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
  setting LDFLAGS to " "
configure: 
configure: Configuring Apache Portable Runtime Utility library...
configure: 
checking for APR-util... no
configure: error: APR-util not found.  Please read the documentation.
#提示缺少 APR-util

[root@centos8 httpd-2.4.46]# dnf -y install apr-util-devel

[root@centos8 httpd-2.4.46]# ./configure --prefix=/apps/httpd --enable-ssl
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... yes
  setting CC to "gcc"
  setting CPP to "gcc -E"
  setting CFLAGS to "  -pthread"
  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
  setting LDFLAGS to " "
configure: 
configure: Configuring Apache Portable Runtime Utility library...
configure: 
checking for APR-util... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for gcc option to accept ISO C99... none needed
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
#提示缺少 PCRE

[root@centos8 httpd-2.4.46]# dnf -y install pcre-devel

[root@centos8 httpd-2.4.46]# ./configure --prefix=/apps/httpd --enable-ssl
...
configure: WARNING: OpenSSL version is too old
no
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
#提示缺少 mod-ssl,这就是openssl

[root@centos8 httpd-2.4.46]# dnf -y install openssl-devel


[root@centos8 httpd-2.4.46]# ./configure --prefix=/apps/httpd --enable-ssl

[root@centos8 httpd-2.4.46]# make -j 2 && make install
...
gcc: error: /usr/lib/rpm/redhat/redhat-hardened-ld: No such file or directory
make[4]: *** [/usr/local/src/httpd-2.4.46/modules/aaa/modules.mk:2: mod_authn_file.la] Error 1
make[4]: *** Waiting for unfinished jobs....
gcc: error: /usr/lib/rpm/redhat/redhat-hardened-ld: No such file or directory
make[4]: *** [/usr/local/src/httpd-2.4.46/modules/aaa/modules.mk:4: mod_authn_dbm.la] Error 1
make[4]: Leaving directory '/usr/local/src/httpd-2.4.46/modules/aaa'
make[3]: *** [/usr/local/src/httpd-2.4.46/build/rules.mk:117: shared-build-recursive] Error 1
make[3]: Leaving directory '/usr/local/src/httpd-2.4.46/modules/aaa'
make[2]: *** [/usr/local/src/httpd-2.4.46/build/rules.mk:117: shared-build-recursive] Error 1
make[2]: Leaving directory '/usr/local/src/httpd-2.4.46/modules'
make[1]: *** [/usr/local/src/httpd-2.4.46/build/rules.mk:117: shared-build-recursive] Error 1
make[1]: Leaving directory '/usr/local/src/httpd-2.4.46'
#提示 缺少redhat/redhat-hardened-ld文件

[root@centos8 httpd-2.4.46]# yum provides *redhat-hardened-ld*
Last metadata expiration check: 0:03:39 ago on Wed 02 Dec 2020 07:35:03 PM CST.
redhat-rpm-config-122-1.el8.noarch : CentOS specific rpm configuration files
Repo        : Appstream
Matched from:
Other       : *redhat-hardened-ld*


[root@centos8 httpd-2.4.46]# dnf -y install redhat-rpm-config-122-1.el8.noarch


[root@centos8 httpd-2.4.46]# make -j 2 && make install


[root@centos8 httpd-2.4.46]# tree /apps/httpd/

[root@centos8 httpd-2.4.46]# /apps/httpd/bin/apachectl start
#启动程序

[root@centos8 httpd-2.4.46]# echo 'PATH=/apps/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
[root@centos8 httpd-2.4.46]# . /etc/profile.d/httpd.sh
#加入变量

[root@centos8 httpd-2.4.46]# apachectl stop
#关闭服务

[root@centos8 httpd-2.4.46]# apachectl
#启动服务

[root@centos8 httpd-2.4.46]# ps aux
...
daemon     39478  0.0  0.4 1337052 7688 ?        Sl   19:47   0:00 /apps/httpd/bin/httpd
daemon     39479  0.0  0.5 1337052 9728 ?        Sl   19:47   0:00 /apps/httpd/bin/httpd
daemon     39480  0.0  0.7 1337052 13808 ?       Sl   19:47   0:00 /apps/httpd/bin/httpd
root       39565  0.0  0.2  57820  3928 pts/0    R+   19:49   0:00 ps aux
#程序还以daemon 身份运行 

[root@centos8 httpd-2.4.46]# useradd -r -s /sbin/nologin apache

[root@centos8 httpd-2.4.46]# vim /apps/httpd/conf/httpd.conf 
#把下面两行
User daemon                                                                                                     
Group daemon
#改成下面内容User apache
Group apache 
:wq

[root@centos8 httpd-2.4.46]# apachectl restart
#重新启动服务

[root@centos8 httpd-2.4.46]# ps aux |grep apache
apache     39579  0.0  0.4 1337052 7728 ?        Sl   19:53   0:00 /apps/httpd/bin/httpd
apache     39580  0.0  0.6 1337052 11808 ?       Sl   19:53   0:00 /apps/httpd/bin/httpd
apache     39581  0.0  0.5 1337052 9768 ?        Sl   19:53   0:00 /apps/httpd/bin/httpd
root       39666  0.0  0.0  12108  1064 pts/0    S+   19:54   0:00 grep --color=auto apache

5、一键编译安装httpd

[root@centos8 ~]#  cat centos8_install_httpd_2.4.46.sh
#!/bin/bash
#
#*************************************************************
#Author:          zhanghui
#QQ:              19661891
#Date:            2020-12-02
#FileName:        centos8_install_httpd_2.4.46.sh
#URL:             www.neteagles.cn
#Description:     The test script
#Copyright (C):   2020 All rights reserved
#*************************************************************
URL=https://mirrors.bfsu.edu.cn/apache//httpd/
FILE=httpd-2.4.46.tar.bz2
INSTALL_DIR=/apps/httpd24

SUFFIX=`echo $FILE | sed -rn 's/.*\.([^.]+)$/\1/p'`
PACKAGE=`echo $FILE | sed -rn 's/^(.*[0-9.]+)\.[[:alpha:]]+.*$/\1/p'`
SUBDIR=`basename $INSTALL_DIR`

echo -e "\033[1;31mStart install httpd 2.4.46\033[0m"
sleep 5
yum install -y wget bzip2 gcc make apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config
cd /usr/local/src/
wget $URL$FILE

case $SUFFIX in
gz|bz2|xz)
    tar xf $FILE
    ;;
zip)
    unzip $FILE
    ;;
*)
    echo "不支持此后缀:$SUFFIX"
    exit 10
esac

cd $PACKAGE/
./configure \
--prefix=$INSTALL_DIR \
--sysconfdir=/etc/$SUBDIR \
--enable-ssl \
--enable-so
make && make install
echo 'PATH=$INSTALL_DIR/bin:$PATH' > /etc/profile.d/$SUBDIR.sh
source /etc/profile.d/$SUBDIR.sh
useradd -r -s /sbin/nologin apache
sed -i -e 's/^User.*/User apache/' -e 's/^Group.*/Group apache/' /etc/$SUBDIR/httpd.conf 
sed -ri 's@(^.*<h1>)(.*)(</h1>.*$)@\1welcome to www.neteagles.cn\3@' $INSTALL_DIR/htdocs/index.html 
apachectl start
echo -e "\033[1;31mhttpd2.4.46 is installed\033[0m"

root@ubuntu18:~# cat ubuntu_install_httpd_2.4.46.sh
#!/bin/bash
#
#*************************************************************
#Author:          zhanghui
#QQ:              19661891
#Date:            2020-11-22
#FileName:        ubuntu_install_httpd_2.4.46.sh
#URL:             www.neteagles.cn
#Description:     The test script
#Copyright (C):   2020 All rights reserved
#*************************************************************
URL=https://mirrors.bfsu.edu.cn/apache//httpd/
FILE=httpd-2.4.46.tar.bz2
INSTALL_DIR=/apps/httpd24

SUFFIX=`echo $FILE | sed -rn 's/.*\.([^.]+)$/\1/p'`
PACKAGE=`echo $FILE | sed -rn 's/^(.*[0-9.]+)\.[[:alpha:]]+.*$/\1/p'`
SUBDIR=`basename $INSTALL_DIR`

echo -e "\033[1;31mStart install httpd 2.4.46\033[0m"
sleep 5
apt -y install gcc make libapr1-dev libaprutil1-dev libpcre3 libpcre3-dev libssl-dev
cd /usr/local/src/
wget $URL$FILE

case $SUFFIX in
gz|bz2|xz)
    tar xf $FILE
    ;;
zip)
    unzip $FILE
    ;;
*)
    echo "不支持此后缀:$SUFFIX"
    exit 10
esac

cd $PACKAGE/
./configure \
--prefix=$INSTALL_DIR \
--sysconfdir=/etc/$SUBDIR \
--enable-ssl \
--enable-so
make && make install
echo 'PATH=$INSTALL_DIR/bin:$PATH' > /etc/profile.d/$SUBDIR.sh
source /etc/profile.d/$SUBDIR.sh
useradd -r -s /sbin/nologin apache
sed -i -e 's/^User.*/User apache/' -e 's/^Group.*/Group apache/' /etc/$SUBDIR/httpd.conf 
sed -ri 's@(^.*<h1>)(.*)(</h1>.*$)@\1welcome to www.neteagles.cn\3@' $INSTALL_DIR/htdocs/index.html 
apachectl start
echo -e "\033[1;31mhttpd2.4.46 is installed\033[0m"
posted @ 2020-12-02 20:46  网络之鹰  阅读(967)  评论(0编辑  收藏  举报