[root@localhost ~]# cd /etc/yum.repos.d
##yum源的配置文件夹,yum如果想能用, 必须放在/etc/yum.repos.d的文件夹下,才能生效,yum配置文件必须.repo结尾的
[root@localhost yum.repos.d]# ls
redhat.repo
[root@localhost yum.repos.d]# df
##df命令用于显示目前在Linux系统上的文件系统的磁盘使用情况统计。
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 17811456 3714540 14096916 21% /
devtmpfs 996932 0 996932 0% /dev
tmpfs 1014056 0 1014056 0% /dev/shm
tmpfs 1014056 10708 1003348 2% /run
tmpfs 1014056 0 1014056 0% /sys/fs/cgroup
/dev/sda1 1038336 168076 870260 17% /boot
tmpfs 202812 4 202808 1% /run/user/42
tmpfs 202812 24 202788 1% /run/user/1000
/dev/sr0 4391278 4391278 0 100% /run/media/cxg/RHEL-7.6 Server.x86_64
##最下面这个/run/media/cxg/RHEL-7.6 Server.x86_64,是软件的安装源在的位置,我们这块安装源在光盘上,可以通过虚拟机右下角的第二个右键设置查看位置,我们的软件都挂载在这个位置
[root@localhost yum.repos.d]# cd /run/media/cxg/RHEL-7.6 Server.x86_64
##这个命令我们显示错误了,是因为复制的上面的路径中7.6和server中间有空格,是特殊字符,我们需要用转译字符、把他连接
-bash: cd: /run/media/cxg/RHEL-7.6: No such file or directory
[root@localhost yum.repos.d]# cd /run/media/cxg/RHEL-7.6\ Server.x86_64
##加入、就好了
[root@localhost RHEL-7.6 Server.x86_64]# ls
addons EFI EULA extra_files.json GPL images isolinux LiveOS media.repo Packages repodata RPM-GPG-KEY-redhat-beta RPM-GPG-KEY-redhat-release TRANS.TBL
[root@localhost RHEL-7.6 Server.x86_64]# cd
[root@localhost ~]# mount /dev/cdrom /media/
##这个mount命令是挂载分区和设备用的,cdrom是光驱,整个命令是把光驱挂载到根的media的目录下作为挂载点
mount: block device /dev/sr0 is write-protected, mounting read-only
##虚拟机挂着光驱光驱时提示只读,我们必须让他变为读写的权限
[root@localhost ~]# mount -o remount,rw /dev/cdrom /media/
mount 命令 [-t 文件系统] [-L 卷标名] [-o 特殊选项] 设备文件名 挂载点
-l 查询系统中已经挂载的设备,-l 会显示卷标 -a 依据配置文件/etc/fstab的内容,自动挂载 -t 系统文件,加入系统类型指定挂载类型,可以ext3,ext4, iso9660等系统文件 -L 卷标名:挂载指定分区,而不是设备文件名挂载 -o 特殊选择:可以指定挂载额外选项 atime/noatime 更新访问时间/不更新访问时间。访问分区时,是否更新文件的访问时间,默认更新 async/sync 异步/同步 默认异步 auto/noauto 自动/手动 mount -a命令执行时,是否会自动安装/etc/fstab 文件内容挂载,默认自动 defaults 定义默认值,相当于rw、suid、dev、exec、auto、nouser、async这七个选择 exec/noexec 执行/不执行,设定师傅允许文件系统中执行可执行文件,默认是exec允许 remount 重新挂载已经挂载的文件系统,一般用于修改特殊权限 rw/ro 读写/只读,文件系统挂载时,是否有读写的权限,默认rw suid/nosuid 具有/不具有SUID权限,设定文件系统是否具有SUID权限,默认具有 user/nouser 允许/不允许普通用户挂载,设定文件系统是否允许普通用户挂载,默认不允许,只有root可以挂载分区 usrquata 写入代表文件系统支持用户磁盘配额,默认不支持 grpquata 写入代表文件系统支持组磁盘配额,默认不允许
[root@localhost ~]# cd /media
##进入media
[root@localhost media]# ls
##可以看到已经挂载完成
addons EFI EULA extra_files.json GPL images isolinux LiveOS media.repo Packages repodata RPM-GPG-KEY-redhat-beta RPM-GPG-KEY-redhat-release TRANS.TBL
##linux支持把设备挂载到多个路径,所以从cd /media/可以访问输出的路径,cd /run/media/cxg/RHEL-7.6\ Server.x86_64这个也可以访问相同的输出路径
[root@localhost media]# cd Packages
##进入软件包
[root@localhost Packages]# ls | wc -l
##统计Packages的行数
5153
[root@localhost media]# cd addons/
##进入扩展包
[root@localhost addons]# ls
HighAvailability ResilientStorage
##这些都属于架构类使用的
[root@localhost addons]# cd ..
[root@localhost Packages]# cd Packages/
[root@localhost Packages]# ls |wc -l
5153
[root@localhost Packages]# ll httpd-2.4.6-88.el7.x86_64.rpm
##“httpd"为软件包名字,”2.4.6-88“为他的版本,”.e17“为发行版本”.×86-64“为体系结构,还有32位体系结构的”。rpm“为软件的后缀名
-r--r--r--. 1 cxg cxg 1243836 Jun 22 2018 httpd-2.4.6-88.el7.x86_64.rpm
##怎么把软件包都进行安装
[root@localhost Packages]# cd ..
[root@localhost media]# cd
[root@localhost ~]# cd /etc/yum.repos.d/
##进入yum资源配置文件
[root@localhost yum.repos.d]# ls
redhat.repo
[root@localhost yum.repos.d]# pwd
##一定要确保是在etc下的/yum.repos.d文件目录下创建的才行
/etc/yum.repos.d
[root@localhost yum.repos.d]# vim dvd.repo
##我们用vim编辑的时候也必须加上后缀repo,不然系统不会读取,新建dvd文件
[dvd]
name=rhel7.6
baseur1=file:///media
gpgcheck=0
##这是个vim编辑器填写的内容:
第一行的【dvd】是软件源的名字,自己定一个dvd的软件源,名称描述
第二行的name=rhel7.6,就是随便起一个名字,起这个名字我们就想让人知道这个软件源是所属红帽7.6版本的
第三行这个是#YUM地址,“file"//”这个是本机的意思,‘/media’是光盘的挂载点media(也就是软件包都在哪个位置)
第四行是#检查GPG-KEY,0为不检查,1为检查,如果我们这块的0改为1,则必须再加一行命令:gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Centos-6
#gpgcheck=0时无须配置
ps:目前的方法每次都需要重新挂载一次(media),后续我们会学习只挂载一次就可以的方法
[root@localhost yum.repos.d]# cd /media
[root@localhost media]# cd Packages
##进入软件包
[root@localhost Packages]# rpm -qpl httpd-2.4.6-88.el7.x86_64.rpm
##这个指令是查看软件包的安装路径(列出RPM软件包内的文件信息[Query Package list];),其中每个rpm文件都有自己固定的位置,不需要我们想windows系统一样,下载东西的时候可以设置安装或者下载路径,
warning: httpd-2.4.6-88.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
/etc/httpd
/etc/httpd/conf
/etc/httpd/conf.d
/etc/httpd/conf.d/README
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
/etc/httpd/conf.modules.d/00-lua.conf
/etc/httpd/conf.modules.d/00-mpm.conf
/etc/httpd/conf.modules.d/00-proxy.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/etc/httpd/conf.modules.d/01-cgi.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/httpd/logs
/etc/httpd/modules
/etc/httpd/run
/etc/logrotate.d/httpd
/etc/sysconfig/htcacheclean
/etc/sysconfig/httpd
/run/httpd
/run/httpd/htcacheclean
/usr/lib/systemd/system/htcacheclean.service
/usr/lib/systemd/system/httpd.service
/usr/lib/tmpfiles.d/httpd.conf
/usr/lib64/httpd
/usr/lib64/httpd/modules
/usr/lib64/httpd/modules/mod_access_compat.so
/usr/lib64/httpd/modules/mod_actions.so
/usr/lib64/httpd/modules/mod_alias.s
##这个也只是部分他的安装路径
[root@localhost Packages]# rpm -qp --scripts httpd-2.4.6-88.el7.x86_64.rpm
##这个指令是查看我们让软件包的脚本(其中 第二个代码 -q代表查询的意思,-p是针对没有安装的软件包查询,因为我们的软件包还都在镜像里面)
##查询一个包是否安装:rpm -q 包名即可
##查询所有已经安装的包:rpm -qa | wc -l
##查看一个已经安装包信息:rpm -qi 包名
##查看一个未安装包的信息: rpm -qp 包全名
##查看一个已经安装包的文件安装位置:rpm -ql 包名
warning: httpd-2.4.6-88.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
preinstall scriptlet (using /bin/sh):
# Add the "apache" group and user
/usr/sbin/groupadd -g 48 -r apache 2> /dev/null || :
/usr/sbin/useradd -c "Apache" -u 48 -g apache \
-s /sbin/nologin -r -d /usr/share/httpd apache 2> /dev/null || :
postinstall scriptlet (using /bin/sh):
if [ $1 -eq 1 ] ; then
# Initial installation
systemctl preset httpd.service htcacheclean.service >/dev/null 2>&1 || :
fi
preuninstall scriptlet (using /bin/sh):
if [ $1 -eq 0 ] ; then
# Package removal, not upgrade
systemctl --no-reload disable httpd.service htcacheclean.service > /dev/null 2>&1 || :
systemctl stop httpd.service htcacheclean.service > /dev/null 2>&1 || :
fi
postuninstall scriptlet (using /bin/sh):
systemctl daemon-reload >/dev/null 2>&1 || :
# Trigger for conversion from SysV, per guidelines at:
# https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Systemd
posttrans scriptlet (using /bin/sh):
test -f /etc/sysconfig/httpd-disable-posttrans || \
/bin/systemctl try-restart httpd.service htcacheclean.service >/dev/null 2>&1 || :
####这是都需要运行的脚本
preinstall scriptlet (using /bin/sh):
# Add the "apache" group and user
/usr/sbin/groupadd -g 48 -r apache 2> /dev/null || :
/usr/sbin/useradd -c "Apache" -u 48 -g apache \
-s /sbin/nologin -r -d /usr/share/httpd apache 2> /dev/null || :
##preinstall scriptlet这是安装之前需要运行的脚本,里面的preuninstall scriptlet (using /bin/sh):是卸载之前运行的脚本,postinstall scriptlet (using /bin/sh):这是卸载后运行的脚本,这个旧系统显示了,这个软件包在各个时期都会运行什么命令
##例如:上面的安装之前运行的脚本我们可以看到/usr/sbin/groupadd
创建一个组,/usr/sbin/useradd
创建一个用户
##接下来安装我们的软件
[root@localhost Packages]# cd
[root@localhost Packages]# cd /etc/yum.repos.d/
dvd.repo redhat.repo
[root@localhost yum.repos.d]
#### yum repolist##校验可用性
里面显示dvd里面有5152个软件包
[root@localhost yum.repos.d]# yum list httpd
##可以在安装之前列一下有没有要安装的http软件包
[root@localhost yum.repos.d]# yum install -y httpd
##安装阿帕奇这个软件包
[root@localhost yum.repos.d]# yum search httped
##查询软件源里面都那些软件包
[root@localhost yum.repos.d]# yum list httpd
##查看软件包是否都安装上
[root@localhost yum.repos.d]#rpm -qa |wc - l
##查看系统上所以已经装过的软件包
有1300多个软件包
[root@localhost yum.repos.d]# systemctl start httpd
##重新启动下httpd
我们试一试用浏览器浏览 192.168.0.100,发现无法浏览,推测应该是防火墙的问题
[root@localhost yum.repos.d]# iptables-L
##进入后发现tcp dpt:sshctstate New,发现防火墙限制了
[root@localhost yum.repos.d]# stop firewalld
##停止防火墙运行
[root@localhost yum.repos.d]#disable firwalled
##禁止他开机自动启动(方便下次电脑重新启动后,防火墙再次打开,导致网页进不去)
##这下在输入192.168.0.100就好了,如下图
##我们现在构建一个网站(本地的样源)
[root@localhost yum.repos.d]# vim index.html
<h1>wwww.westos.org</h1>
``
##输入网站192.168.0.100 ##可以看到下面网站显示的内容就是我们编辑的内容
##输入网站https://developer.aliyun.com/mirror/(这是我们的外部样源,阿里的云镜像)
##我们找到eqel样源(对这个样源的rhel7进行下载)
[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
##复制上面的地址输入
--2020-05-03 06:48:39-- http://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 111.19.233.240, 111.19.233.248, 111.19.233.229, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|111.19.233.240|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 664 [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/epel.repo’
100%[======================================>] 664 --.-K/s in 0s
2020-05-03 06:48:39 (78.1 MB/s) - ‘/etc/yum.repos.d/epel.repo’ saved [664/664]
##可以看到样源已经下载了,可以看到默认输出的位置为:/etc/yum.repos.d/epel.repo
[root@localhost ~]# cd /etc/yum.repos.d/
##进入我们的输出
[root@localhost yum.repos.d]# ls
dvd.repo epel.repo media redhat.repo
[root@localhost yum.repos.d]# cat epel.repo
##查看下载的epel,这也是生成的epel源
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
[root@localhost yum.repos.d]# vim epel.repo
##这个里面enabled=1代表服务启动 =0代表不激活,我们只使用epel功能,不使用[epel-debuginfo]所以下面的enabled都是等于0,并且gpgcheck=0代表不检测
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
[root@localhost yum.repos.d]# yum repolist
##进行安装后查看这个软件包的可用性,我们可以看到下面repolist已经达到13248,有增加,所以可用
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
epel/x86_64 | 4.7 kB 00:00:00
epel/x86_64/group_gz | 95 kB 00:00:00
epel/x86_64/updateinfo | 1.0 MB 00:00:00
epel/x86_64/primary_db | 6.8 MB 00:00:00
repo id repo name status
dvd rhel7.6 0
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,248
repolist: 13,248
##yum文件我们在research的时候不是实时检索的,而是读取的是他的索引信息,就是缓存,下面我们查看缓存相关信息
[root@localhost var]# cd /var/cache/
##缓存都存在这个文件下的文件
[root@localhost cache]# ls
abrt-di cups gdm ibus ldconfig libvirt man PackageKit realmd yum
[root@localhost cache]# cd yum
[root@localhost yum]# ls
x86_64
[root@localhost yum]# cd x86_64
[root@localhost x86_64]# ls
7Server
[root@localhost x86_64]# cd 7Server
[root@localhost 7Server]# pwd
##可以看到我们的缓存保存的路径在下面
/var/cache/yum/x86_64/7Server
[root@localhost 7Server]# ls
##可以看到dvd epel的缓存目录
dvd epel timedhosts
[root@localhost 7Server]# cd epel
[root@localhost epel]# ls
##可以看到epel软件包的缓存信息
8ad50ece096df7ace3a2343ae6bf10e21496681664b278a878c46e7675a4b220-updateinfo.xml.bz2 gen
cachecookie packages
d65d89a048295fe170daf6f3823f584b8b8d383d254ea8827801078e855550ec-comps-Everything.x86_64.xml.gz repomd.xml
e220ecdddca852ec5e5e5b3b1c5065c47906519bb55eae9d9ababc98d065d1bd-primary.sqlite.bz2
[root@localhost epel]# yum clean all
##我们现在给缓存清理了
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Cleaning repos: dvd epel
[root@localhost epel]# ll
##可以看到已经清理了
total 0
[root@localhost epel]# yum repolist
##我们现在重新进行加载,他们的缓存信息就会又回来了
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
epel/x86_64 | 4.7 kB 00:00:00
epel/x86_64/group_gz | 95 kB 00:00:00
epel/x86_64/updateinfo | 1.0 MB 00:00:00
epel/x86_64/primary_db | 6.8 MB 00:00:00
repo id repo name status
dvd rhel7.6 0
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,248
repolist: 13,248
[root@localhost epel]# ls
8ad50ece096df7ace3a2343ae6bf10e21496681664b278a878c46e7675a4b220-updateinfo.xml.bz2 gen
cachecookie packages
d65d89a048295fe170daf6f3823f584b8b8d383d254ea8827801078e855550ec-comps-Everything.x86_64.xml.gz repomd.xml
e220ecdddca852ec5e5e5b3b1c5065c47906519bb55eae9d9ababc98d065d1bd-primary.sqlite.bz2
##这个对缓存信息的清理和重新加载一般是针对服务端软件包有更新的时候,本地的服务端也要更新,不然无法查询到信息,同时重新更新检索的内容的情况下使用
[root@localhost ~]# cd /media/
[root@localhost media]# cd repodata/
##这个是我们本地使用源数据的,在没有真正发出数据传输的时候research的本地repodata下的信息
[root@localhost media]# cd /etc/yum yum.repos.d/
[root@localhost yum]# ls
fssnap.d pluginconf.d protected.d vars version-groups.conf
###总结:我们在刚刚已经演示了如果下载我们本地的源和外部的源,下面我们可以针对需要的源进行安装
[root@localhost yum]# cd /etc/yum.repos.d
yum源的配置文件夹,yum如果想能用, 必须放在/etc/yum.repos.d的文件夹下,才能生效
[root@localhost yum.repos.d]# ls
dvd.repo epel.repo media redhat.repo
[root@localhost yum.repos.d]# yum list ansible
##列出我们想用的软件包ansible的信息,可以看到已经列出来
[root@localhost yum.repos.d]# yum --help
##查看yum命令的具体内容都有什么
List of Commands:
check Check for problems in the rpmdb
check-update Check for available package updates
clean Remove cached data
deplist List a package's dependencies
distribution-synchronization Synchronize installed packages to the latest available versions
downgrade downgrade a package
erase Remove a package or packages from your system
fs Acts on the filesystem data of the host, mainly for removing docs/lanuages for minimal hosts.
fssnapshot Creates filesystem snapshots, or lists/deletes current snapshots.
groups Display, or use, the groups information
help Display a helpful usage message
history Display, or use, the transaction history
info Display details about a package or group of packages
install Install a package or packages on your system
langavailable Check available languages
langinfo List languages information
langinstall Install appropriate language packs for a language
langlist List installed languages
langremove Remove installed language packs for a language
list List a package or groups of packages
load-transaction load a saved transaction from filename
makecache Generate the metadata cache
provides Find what package provides the given value
reinstall reinstall a package
repo-pkgs Treat a repo. as a group of packages, so we can install/remove all of them
repolist Display the configured software repositories
search Search package details for the given string
shell Run an interactive yum shell
swap Simple way to swap packages, instead of using shell
update Update a package or packages on your system
update-minimal Works like upgrade, but goes to the 'newest' package match which fixes a problem that affects your system
updateinfo Acts on repository update information
upgrade Update packages taking obsoletes into account
version Display a version for the machine and/or available repos.
Options:
-h, --help show this help message and exit
-t, --tolerant be tolerant of errors
-C, --cacheonly run entirely from system cache, don't update cache
-c [config file], --config=[config file]
config file location
-R [minutes], --randomwait=[minutes]
maximum command wait time
-d [debug level], --debuglevel=[debug level]
debugging output level
--showduplicates show duplicates, in repos, in list/search commands
-e [error level], --errorlevel=[error level]
error output level
--rpmverbosity=[debug level name]
debugging output level for rpm
-q, --quiet quiet operation
-v, --verbose verbose operation
-y, --assumeyes answer yes for all questions
--assumeno answer no for all questions
--version show Yum version and exit
--installroot=[path] set install root
--enablerepo=[repo] enable one or more repositories (wildcards allowed)
--disablerepo=[repo] disable one or more repositories (wildcards allowed)
-x [package], --exclude=[package]
exclude package(s) by name or glob
--disableexcludes=[repo]
disable exclude from main, for a repo or for
everything
--disableincludes=[repo]
disable includepkgs for a repo or for everything
--obsoletes enable obsoletes processing during updates
--noplugins disable Yum plugins
--nogpgcheck disable gpg signature checking
--disableplugin=[plugin]
disable plugins by name
--enableplugin=[plugin]
enable plugins by name
--skip-broken skip packages with depsolving problems
--color=COLOR control whether color is used
--releasever=RELEASEVER
set value of $releasever in yum config and repo files
--downloadonly don't update, just download
--downloaddir=DLDIR specifies an alternate directory to store packages
--setopt=SETOPTS set arbitrary config and repo options
--bugfix Include bugfix relevant packages, in updates
--security Include security relevant packages, in updates
--advisory=ADVS, --advisories=ADVS
Include packages needed to fix the given advisory, in
updates
--bzs=BZS Include packages needed to fix the given BZ, in
updates
--cves=CVES Include packages needed to fix the given CVE, in
updates
--sec-severity=SEVS, --secseverity=SEVS
Include security relevant packages matching the
severity, in updates
##可以看到里面updata,upgrade,都代表更新,reinstall重装,provides查询源信息,info查询软件包的信息,showduplicates查看软件包的各个版本
[root@localhost yum.repos.d]# yum list --showduplicates ansible
##列出ansible软件包的所有版本信息,可以看到我们当前只有一个版本
[root@localhost yum.repos.d]# yum install ansible
##安装ansible软件包,可以看到我们的软件包有些是从dvd本地下载安装,有些是从epel外部互联网里面下载(其中 y,d,n 分别代表 自动安装,只下载,不安装三个选项)
[root@localhost yum.repos.d]# yum list ansible
##列出后,文件最后有一个completes,显示安装完成
##刚刚一直用的rpm包,我们现在尝试用tar.gz源码进行使用
[root@localhost yum.repos.d]# cd
[root@localhost ~]# pwd
/root
##我们在nginx.org的download下载源码包,然后使用securecrt的映射功能把下载的niginx.org 映射到超户主目录(root)下
[root@localhost ~]# ls
##可以看到我们的nginx.org已经移动到linux系统了
anaconda-ks.cfg initial-setup-ks.cfg nginx-1.18.0.tar.gz westos
[root@localhost ~]# tar zxf nginx-1.18.0.tar.gz
##tar打头的文件,z表示z结尾的文件,意思就是这个压缩包,x表示释放,f指定我的一个压缩包
[root@localhost ~]# ls
##可以看看到我们的nginx-1.18.0是解压后的文件
anaconda-ks.cfg initial-setup-ks.cfg nginx-1.18.0 nginx-1.18.0.tar.gz westos
[root@localhost ~]# cd nginx-1.18.0/
##进入(但是这个是源码,不能直接使用,不同于rpm包 直接yum install就可以使用了)
[root@localhost nginx-1.18.0]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
[root@localhost nginx-1.18.0]# ./configure
checking for OS
+ Linux 3.10.0-957.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
##发现缺少gcc编译器,进行安装
[root@localhost nginx-1.18.0]# yum list gcc
[root@localhost nginx-1.18.0]# yum install -y gcc
##安装完后发现还缺少pcre
[root@localhost nginx-1.18.0]# yum install -y pcre-devel
##安装pcre
[root@localhost nginx-1.18.0]# ./configure
##继续检测当前环境,发现还缺少zlib
[root@localhost nginx-1.18.0]# yum install -y zlib-devel
##继续安装devel
[root@localhost nginx-1.18.0]# ./configure
##继续检测当前环境,发现已经没有任何问题了
###上面这个只是三部曲的第一步检测环境,对于初学者我们建议使用rpm包,因为源码更加可定制,出现的问题也更多
接下来进行第二步:[root@localhost nginx-1.18.0]# make
[root@localhost nginx-1.18.0]# yum list nginx
[root@localhost nginx-1.18.0]# make install
##安装
[root@localhost nginx-1.18.0]# cd/usr/local/nginx
##可以看到我们的nginx就安装在这个目录下
[root@localhost nginx-1.18.0]# netstart -antlp
##看下服务器是否有被授权的端口,但是我们前面对httpd设置的是80占用了80端口,因此我们先停掉httpd
[root@localhost nginx-1.18.0]# systemctl stop httpd
[root@localhost nginx-1.18.0]# netstart -antlp
##再次查看发现没有问题,我们接下来就启动nginx
[root@localhost nginx-1.18.0]# cd
[root@localhost root]# cd sbin/
##这个就是sbin的运行目录
[root@localhost sbin]# 。/nginx
##运行nginx
##然后再用网页进入192.168.0.100发现welcome to nginx
##完成
##如果我们要运行jsp页面的话,nginx已经不能使用了,需要tomcat
因此我们进入http://tomcat.apache.org/进行下载
我们这里选择核心core下载版本7
然后再使用secureFX把他扔进linux的root下
[root@localhost ~]# ls
anaconda-ks.cfg apache-tomcat-7.0.103.tar.gz initial-setup-ks.cfg nginx-1.18.0 nginx-1.18.0.tar.gz westos
##apach-tomacat已经在root下了
[root@localhost ~]# [root@localhost ~]# tar zxf apache-tomcat-7.0.103.tar.gz
##进行解压
[root@localhost ~]# cd apache-tomcat-7.0.103/
##进入tomcat
[root@localhost apache-tomcat-7.0.103]# ls
##可以看到这里面可以直接运行,因为他是二进制的程序(类似于rpm)
bin BUILDING.txt conf CONTRIBUTING.md lib LICENSE logs NOTICE README.md RELEASE-NOTES RUNNING.txt temp webapps work
[root@localhost ~]# mv apache-tomcat-7.0.103 /usr/local/
##移动tomcat到usr下的local,为了方便权限管理,在超级用户下很多权限不方便
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
apache-tomcat-7.0.103 bin etc games include lib lib64 libexec sbin share src
[root@localhost local]# ln -s apache-tomcat-7.0.103/ tomcat
##ln -s就是在做一个软链接,名字为tomcat
[root@localhost local]# ls
apache-tomcat-7.0.103 bin etc games include lib lib64 libexec sbin share src tomcat
[root@localhost local]# ll
total 0
drwxr-xr-x. 9 root root 220 May 4 00:17 apache-tomcat-7.0.103
drwxr-xr-x. 2 root root 6 Dec 15 2017 bin
drwxr-xr-x. 2 root root 6 Dec 15 2017 etc
drwxr-xr-x. 2 root root 6 Dec 15 2017 games
drwxr-xr-x. 2 root root 6 Dec 15 2017 include
drwxr-xr-x. 2 root root 6 Dec 15 2017 lib
drwxr-xr-x. 2 root root 6 Dec 15 2017 lib64
drwxr-xr-x. 2 root root 6 Dec 15 2017 libexec
drwxr-xr-x. 2 root root 6 Dec 15 2017 sbin
drwxr-xr-x. 5 root root 49 Mar 31 18:09 share
drwxr-xr-x. 2 root root 6 Dec 15 2017 src
lrwxrwxrwx. 1 root root 22 May 4 00:24 tomcat -> apache-tomcat-7.0.103/
###进入tomcat相当于进入 apache-tomcat-7.0.103/可以从上面看到
[root@localhost local]# cd tomcat
##因为软连接,所以我们cd tomcat相当于cd apache-tomcat-7.0.103/
[root@localhost tomcat]# ls
bin BUILDING.txt conf CONTRIBUTING.md lib LICENSE logs NOTICE README.md RELEASE-NOTES RUNNING.txt temp webapps work
[root@localhost tomcat]# pwd
##可以看到我们的位置
/usr/local/tomcat
[root@localhost tomcat]# cd bin/
##bin文件运行一些基本的程序其中就包括tomcat
[root@localhost bin]# ./startup.sh
##启动tomcat
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@localhost bin]# netstat -antlp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:6000 0.0.0.0:* LISTEN 7827/X
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 7872/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 7585/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 7592/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7847/master
tcp 0 0 192.168.0.100:22 192.168.0.103:57261 ESTABLISHED 9203/sshd: root@pts
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::8080 :::* LISTEN 10153/java
tcp6 0 0 :::6000 :::* LISTEN 7827/X
tcp6 0 0 :::22 :::* LISTEN 7585/sshd
tcp6 0 0 ::1:631 :::* LISTEN 7592/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 7847/master
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 10153/java
[root@localhost tomcat]# cd work
[root@localhost work]# ls
##work是他的tomcat的工作目录
Catalina
[root@localhost work]# cd ..
[root@localhost tomcat]# cd webapps/
[root@localhost webapps]# cd ROOT/
##这个是默认的发目录
[root@localhost ROOT]# cat index.jsp
##查看默认情况下的index。jsp
<%--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--%>
<%@ page session="false" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy");
request.setAttribute("year", sdf.format(new java.util.Date()));
request.setAttribute("tomcatUrl", "https://tomcat.apache.org/");
request.setAttribute("tomcatDocUrl", "/docs/");
request.setAttribute("tomcatExamplesUrl", "/examples/");
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title><%=request.getServletContext().getServerInfo() %></title>
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link href="tomcat.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="navigation" class="curved container">
<span id="nav-home"><a href="${tomcatUrl}">Home</a></span>
<span id="nav-hosts"><a href="${tomcatDocUrl}">Documentation</a></span>
<span id="nav-config"><a href="${tomcatDocUrl}config/">Configuration</a></span>
<span id="nav-examples"><a href="${tomcatExamplesUrl}">Examples</a></span>
<span id="nav-wiki"><a href="https://wiki.apache.org/tomcat/FrontPage">Wiki</a></span>
<span id="nav-lists"><a href="${tomcatUrl}lists.html">Mailing Lists</a></span>
<span id="nav-help"><a href="${tomcatUrl}findhelp.html">Find Help</a></span>
<br class="separator" />
</div>
<div id="asf-box">
<h1>${
pageContext.servletContext.serverInfo}</h1>
</div>
<div id="upper" class="curved container">
<div id="congrats" class="curved container">
<h2>If you're seeing this, you've successfully installed Tomcat. Congratulations!</h2>
</div>
<div id="notice">
<img src="tomcat.png" alt="[tomcat logo]" />
<div id="tasks">
<h3>Recommended Reading:</h3>
<h4><a href="${tomcatDocUrl}security-howto.html">Security Considerations How-To</a></h4>
<h4><a href="${tomcatDocUrl}manager-howto.html">Manager Application How-To</a></h4>
<h4><a href="${tomcatDocUrl}cluster-howto.html">Clustering/Session Replication How-To</a></h4>
</div>
</div>
<div id="actions">
<div class="button">
<a class="container shadow" href="/manager/status"><span>Server Status</span></a>
</div>
<div class="button">
<a class="container shadow" href="/manager/html"><span>Manager App</span></a>
</div>
<div class="button">
<a class="container shadow" href="/host-manager/html"><span>Host Manager</span></a>
</div>
</div>
<br class="separator" />
</div>
<div id="middle" class="curved container">
<h3>Developer Quick Start</h3>
<div class="col25">
<div class="container">
<p><a href="${tomcatDocUrl}setup.html">Tomcat Setup</a></p>
<p><a href="${tomcatDocUrl}appdev/">First Web Application</a></p>
</div>
</div>
<div class="col25">
<div class="container">
<p><a href="${tomcatDocUrl}realm-howto.html">Realms & AAA</a></p>
<p><a href="${tomcatDocUrl}jndi-datasource-examples-howto.html">JDBC DataSources</a></p>
</div>
</div>
<div class="col25">
<div class="container">
<p><a href="${tomcatExamplesUrl}">Examples</a></p>
</div>
</div>
<div class="col25">
<div class="container">
<p><a href="https://wiki.apache.org/tomcat/Specifications">Servlet Specifications</a></p>
<p><a href="https://wiki.apache.org/tomcat/TomcatVersions">Tomcat Versions</a></p>
</div>
</div>
<br class="separator" />
</div>
<div id="lower">
<div id="low-manage" class="">
<div class="curved container">
<h3>Managing Tomcat</h3>
<p>For security, access to the <a href="/manager/html">manager webapp</a> is restricted.
Users are defined in:</p>
<pre>$CATALINA_HOME/conf/tomcat-users.xml</pre>
<p>In Tomcat 7.0 access to the manager application is split between
different users. <a href="${tomcatDocUrl}manager-howto.html">Read more...</a></p>
<br />
<h4><a href="${tomcatDocUrl}RELEASE-NOTES.txt">Release Notes</a></h4>
<h4><a href="${tomcatDocUrl}changelog.html">Changelog</a></h4>
<h4><a href="${tomcatUrl}migration.html">Migration Guide</a></h4>
<h4><a href="${tomcatUrl}security.html">Security Notices</a></h4>
</div>
</div>
<div id="low-docs" class="">
<div class="curved container">
<h3>Documentation</h3>
<h4><a href="${tomcatDocUrl}">Tomcat 7.0 Documentation</a></h4>
<h4><a href="${tomcatDocUrl}config/">Tomcat 7.0 Configuration</a></h4>
<h4><a href="https://wiki.apache.org/tomcat/FrontPage">Tomcat Wiki</a></h4>
<p>Find additional important configuration information in:</p>
<pre>$CATALINA_HOME/RUNNING.txt</pre>
<p>Developers may be interested in:</p>
<ul>
<li><a href="https://tomcat.apache.org/bugreport.html">Tomcat 7.0 Bug Database</a></li>
<li><a href="${tomcatDocUrl}api/index.html">Tomcat 7.0 JavaDocs</a></li>
<li><a href="https://github.com/apache/tomcat/tree/7.0.x">Tomcat 7.0 Git Repository at GitHub</a></li>
</ul>
</div>
</div>
<div id="low-help" class="">
<div class="curved container">
<h3>Getting Help</h3>
<h4><a href="${tomcatUrl}faq/">FAQ</a> and <a href="${tomcatUrl}lists.html">Mailing Lists</a></h4>
<p>The following mailing lists are available:</p>
<ul>
<li id="list-announce"><strong><a href="${tomcatUrl}lists.html#tomcat-announce">tomcat-announce</a><br />
Important announcements, releases, security vulnerability notifications. (Low volume).</strong>
</li>
<li><a href="${tomcatUrl}lists.html#tomcat-users">tomcat-users</a><br />
User support and discussion
</li>
<li><a href="${tomcatUrl}lists.html#taglibs-user">taglibs-user</a><br />
User support and discussion for <a href="${tomcatUrl}taglibs/">Apache Taglibs</a>
</li>
<li><a href="${tomcatUrl}lists.html#tomcat-dev">tomcat-dev</a><br />
Development mailing list, including commit messages
</li>
</ul>
</div>
</div>
<br class="separator" />
</div>
<div id="footer" class="curved container">
<div class="col20">
<div class="container">
<h4>Other Downloads</h4>
<ul>
<li><a href="${tomcatUrl}download-connectors.cgi">Tomcat Connectors</a></li>
<li><a href="${tomcatUrl}download-native.cgi">Tomcat Native</a></li>
<li><a href="${tomcatUrl}taglibs/">Taglibs</a></li>
<li><a href="${tomcatDocUrl}deployer-howto.html">Deployer</a></li>
</ul>
</div>
</div>
<div class="col20">
<div class="container">
<h4>Other Documentation</h4>
<ul>
<li><a href="${tomcatUrl}connectors-doc/">Tomcat Connectors</a></li>
<li><a href="${tomcatUrl}connectors-doc/">mod_jk Documentation</a></li>
<li><a href="${tomcatUrl}native-doc/">Tomcat Native</a></li>
<li><a href="${tomcatDocUrl}deployer-howto.html">Deployer</a></li>
</ul>
</div>
</div>
<div class="col20">
<div class="container">
<h4>Get Involved</h4>
<ul>
<li><a href="${tomcatUrl}getinvolved.html">Overview</a></li>
<li><a href="${tomcatUrl}source.html">Source Repositories</a></li>
<li><a href="${tomcatUrl}lists.html">Mailing Lists</a></li>
<li><a href="https://wiki.apache.org/tomcat/FrontPage">Wiki</a></li>
</ul>
</div>
</div>
<div class="col20">
<div class="container">
<h4>Miscellaneous</h4>
<ul>
<li><a href="${tomcatUrl}contact.html">Contact</a></li>
<li><a href="${tomcatUrl}legal.html">Legal</a></li>
<li><a href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li>
<li><a href="https://www.apache.org/foundation/thanks.html">Thanks</a></li>
</ul>
</div>
</div>
<div class="col20">
<div class="container">
<h4>Apache Software Foundation</h4>
<ul>
<li><a href="${tomcatUrl}whoweare.html">Who We Are</a></li>
<li><a href="${tomcatUrl}heritage.html">Heritage</a></li>
<li><a href="https://www.apache.org">Apache Home</a></li>
<li><a href="${tomcatUrl}resources.html">Resources</a></li>
</ul>
</div>
</div>
<br class="separator" />
</div>
<p class="copyright">Copyright ©1999-${
year} Apache Software Foundation. All Rights Reserved</p>
</div>
</body>
</html>
[root@localhost ROOT]# vim test.jsp
<%=new java.util.Date()%>
网页上输入 192.168.0.100:8080/test.jsp
root@localhost ~]# vim /etc/hosts/##在这个里面加上www.westos.org这个解析
##client->firefox->nginx:80->tomcat:8080->nginx->firefox##这个是通过客户端传输到firefox浏览器,再传到nginx,如果nginx无法处理,就传输到tomcat,在返回ngix和浏览器
##访问www.westos.org
[root@localhost ~]# cd /usr/local/nginx
[root@localhost ~]# cd conf/
[root@localhost ~]# vim nginx.conf
[root@localhost ~]# netstat -antlp
##红色的就是加的内容,第一行针对jps文件 proxy-pass反向代理到本机的127.0.0.1:8080,代理到本机的8080上,意思就是:所有的jsp文件都将被转化为本机的8080端口处理
[root@localhost ~]# cd sbin/
[root@localhost ~]# ls
[root@localhost ~]# ./nginx -s reload##运行nginx,让他重新加载下
这个时候我们输入wwww.westos.org.test.jps
##这是因为我们所有的jps文件都转为成8080的nginx,前面的www.westos.org实质上就相当于192.168.0.100,这个相当于省掉了输入:8080这个步骤
##nginx在生产环节主要充当的一个入口的策略