1、自建yum仓库,分别为网络源和本地源
CentOS 本地光盘源配置
cd /etc/yum.repos.d/
mkdir back-repo
mv *.repo back-repo
#rm -rf C*
mount /dev/cdrom /mnt
ls /mnt
vim /etc/fstab 永久性挂载配置
#永久挂载
/dev/cdrom /mnt iso9660 defaults 0 0
#mount /dev/cdrom /mnt
vim CentOS-local.repo
[bace-local]
name=CentOS-local
baseurl=file:///mnt
enabled=1
gpgcheck=1
gpgkey=file:///mnt/RPM-GPG-CentOS-7
yum clean all
yum makecache
yum repolist
ubuntu光盘源搭建
#老提示缺少文件,待后面处理
apt install dpkg-dev -y
#apt-get install apt-mirror
#vim /etc/apt/sources.list
mount /dev/cdrom /mnt
cp /etc/apt/sources.list /etc/apt/sources.list.bak
vim /etc/apt/sources.list
deb file:////mnt xenial main restricted
cd repository
apt-ftparchive packages . > Packages
apt-ftparchive release . > Release
gpg --clearsign -o InRelease Release # 生成签名
#签名配置
gpg --gen-key
apt-get update
#此方法配置时会报错
网络源配置
或 wget 换成 curl
centos 6
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
centos 7
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
CentOS 8
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
yum clean all
yum makecache
yum repolist
手动配置网络源
cp /etc/yum.repos.d/CentOS-Base.repo CentOS-Base.repo.bak
vim /etc/yum.repos.d/CentOS-Base.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
#
yum clean all
yum makecache
yum repolist
ubuntu
grep -v '^#' /etc/apt/sources.list
#cp /etc/apt/sources.list /etc/apt/sources.list.bak
sed -i.bak /xxx.xxx.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list
或
sed -ri.bak 's#(.*//).*\.ubuntu\.com#\1mirrors.aliyun.com#g /etc/apt/sources.list
sudo apt-get update #更新安装包列表
局域网网络源搭建
#server01
#
yum install -y httpd
firewall-cmd --add-service=http
mkdir /apps/httpd/htdocs/westos #使用的编译安装
mount /dev/cdrom /apps/httpd/htdocs/westos
vim /etc/fstab
/dev/cdrom /apps/httpd/htdocs/westos iso9660 defaults 0 0
apachectl #启动网站
#server02
#
cp /etc/yum.repos.d/CentOS-Base.repo CentOS-Base.repo.bak
vim /etc/yum.repos.d/CentOS-Base.repo
#
[base]
name=CentOS-Base
baseurl=http://10.0.0.151/westos/
gpgcheck=1
gpgkey=http://10.0.0.151/westos/RPM-GPG-KEY-CentOS-7
2、编译安装http2.4,实现可以正常访问,并将编译步骤和结果提交。
yum info httpd #查看 httpd 信息
yum -y install wget #确保能够 wget 功能
mkdir /data/httpd #创建下载目录
#wget -P /data/httpd https://dlcdn.apache.org//httpd/httpd-2.4.52.tar.gz
wget -P /data/httpd https://dlcdn.apache.org//httpd/httpd-2.4.52.tar.gz --no-check-certificate #下载文件
cd /data/httpd/ #进入目录
tar xf httpd-2.4.52.tar.gz #解压
cd httpd-2.4.52 #进入解压目录
[root@localhost httpd]# ls
httpd-2.4.52 httpd-2.4.52.tar.gz
[root@localhost httpd]# cd httpd-2.4.52
[root@localhost httpd-2.4.52]# ls
ABOUT_APACHE BuildAll.dsp configure httpd.spec libhttpd.mak os srclib
acinclude.m4 BuildBin.dsp configure.in include LICENSE README support
Apache-apr2.dsw buildconf docs INSTALL Makefile.in README.CHANGES test
Apache.dsw CHANGES emacs-style InstallBin.dsp Makefile.win README.cmake VERSIONING
apache_probes.d changes-entries httpd.dep LAYOUT modules README.platforms
ap.d CMakeLists.txt httpd.dsp libhttpd.dep NOTICE ROADMAP
build config.layout httpd.mak libhttpd.dsp NWGNUmakefile server
cat INSTALL #查看安装方法
#安装过程
$ ./configure --prefix=PREFIX
$ make
$ make install
$ PREFIX/bin/apachectl start #启动
#查看configure支持选项及功能
./configure --help
#指定配置文件安装目录并启用ssl
./configure --prefix=/apps/httpd \
--sysconfdir=/etc/httpd/ \
--enable-ssl
#./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd/ --enable-ssl
[root@localhost httpd-2.4.52]# ./configure --prefix=/apps/httpd \
> --sysconfdir=/etc/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.
yum install -y apr-devel
./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd/ --enable-ssl
configure: Configuring Apache Portable Runtime Utility library...
configure:
checking for APR-util... no
configure: error: APR-util not found. Please read the documentatio
yum install -y apr-util-devel
./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd/ --enable-ssl
checking for APR-util... yes
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/data/httpd/httpd-2.4.52':
configure: error: C compiler cannot create executables
See `config.log' for more details
cat config.log
.........
configure:5459: checking for gcc
configure:5491: result: gcc
configure:5844: checking for C compiler version
configure:5853: gcc --version >&5
./configure: line 5855: gcc: command not found
configure:5864: $? = 127
configure:5853: gcc -v >&5
./configure: line 5855: gcc: command not found
configure:5864: $? = 127
configure:5853: gcc -V >&5
./configure: line 5855: gcc: command not found
configure:5864: $? = 127
configure:5853: gcc -qversion >&5
./configure: line 5855: gcc: command not found
configure:5864: $? = 127
configure:5853: gcc -version >&5
./configure: line 5855: gcc: command not found
........
yum install -y gcc
./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd/ --enable-ssl
......
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
yum install -y pcre-devel
./configure --prefix=/apps/httpd --sysconfdir=/etc/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
yum install -y openssl-devel
./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd/ --enable-ssl
configure: summary of build options:
Server Version: 2.4.52
Install prefix: /apps/httpd
C compiler: gcc -std=gnu11
CFLAGS: -pthread
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
LDFLAGS:
LIBS:
C preprocessor: gcc -E
[root@localhost httpd-2.4.52]# echo $?
0
#查看CPU核数
lscpu |grep CPU
CPU op-mode(s): 32-bit, 64-bit
CPU(s): 2
make -j 2
make install
ls /apps/httpd
ls /etc/httpd
[root@localhost httpd-2.4.52]# curl 127.0.0.1
curl: (7) Failed connect to 127.0.0.1:80; Connection refused
# PREFIX/bin/apachectl start #启动
/apps/httpd/bin/apachectl start
curl 127.0.0.1
<html><body><h1>It works!</h1></body></html>
/apps/httpd/bin/apachectl stop
#加入到PATH
echo 'PATH=/apps/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
. /etc/profile.d/httpd.sh
echo $PATH #确认变量加入到PATH
apachectl
apachectl stop
重新整理后
yum install -y wget apr-devel apr-util-devel gcc pcre-devel openssl-devel
wget -P /data/httpd https://dlcdn.apache.org//httpd/httpd-2.4.52.tar.gz --no-check-certificate
./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd/ --enable-ssl
make -j 2
make install
echo 'PATH=/apps/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
. /etc/profile.d/httpd.sh
apachectl
apachectl stop
3、利用sed 取出ifconfig命令中本机的IPv4地址
#ip a |sed -n '/\/24/p' |sed 's/inet.//g' |sed 's/brd.*$//g'
yum install net-tools -y
ifconfig eth0 |sed -n '/mask/p'|sed 's/.inet//g'|sed -s 's/ //g'|sed 's/netmask.*$//g'
或
ifconfig eth0 |sed -n '/mask/p'|sed 's/ /\n/g' |sed '/^$/d'|sed -n '2p'
[root@localhost ~]# ifconfig eth0 |sed -n '/mask/p'|sed 's/.inet//g'|sed -s 's/ //g'|sed 's/netmask.*$//g'
10.0.0.151
4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
cat /etc/fstab|sed '/^#/d'|sed '/^$/d' //
5、处理/etc/fstab路径,使用sed命令取出其目录名和基名
ls /etc/fstab |sed 's#/#\n#g'|sed -n '$p'
#或
ls /etc/fstab |sed 's/^.*\///g'
#basename /etc/fstab
6、列出ubuntu软件管理工具apt的一些用法(自由总结)
#安装包
sudo apt install [package name1] [package-name2] [package-name3] -y
#卸载包
sudo apt remove [package name]
#清除安装包残余
sudo apt --purge remove [package-name]
#删除孤立安装包
sudo apt autoremove
#更新APT储存库
sudo apt update
#升级系统软件包(非关键软件包)
sudo apt upgrade
#升级系统软件包 (完整的)
sudo apt full-upgrade
#搜索包
sudo apt search [keyword]
附录YUM用法
1. 列出所有可更新的软件清单命令:yum check-update
2. 更新所有软件命令:yum update
3. 仅安装指定的软件命令:yum install <package_name>
4. 仅更新指定的软件命令:yum update <package_name>
5. 列出所有可安裝的软件清单命令:yum list
6. 删除软件包命令:yum remove <package_name>
7. 查找软件包命令:yum search <keyword>
8. 清除缓存命令:
yum clean packages: 清除缓存目录下的软件包
yum clean headers: 清除缓存目录下的 headers
yum clean oldheaders: 清除缓存目录下旧的 headers
yum clean, yum clean all (= yum clean packages; yum clean oldheaders) :清除缓存目录下的软件包及旧的 headers
yum install pam-devel 安装
yum remove pam-devel 移除
yum list pam* 列出