运维利器之yum部署开源项目实战
  zZHnZavbRDNq 2023年11月02日 27 0


linux之利用yum部署开源项目实战

最近咱的媳妇问了我一个问题,说linux上面的yum命令好使不(媳妇是研发人员),“好使,相当的好用”,媳妇这边也是在网上的一篇文档中看到的yum这个相当的强大,无奈之下,自己也是搜集了一下yum相关的资料,在晚上为媳妇深深的上了一课。

运维利器之yum部署开源项目实战_服务器

rpm安装:主要是通过下载rpm包,进行安装,但是这个rpm包安装可以保证一个小量的安装,也就是说可以控制包的安装数量,唯一不足的就是还得一个一个的rpm安装所需要的依赖包
yum安装:这个比较省事,安装起来也是比较的方便,可以自动的安装所需要的依赖包
编译安装:相对来说还是比较麻烦,先下载下来源码包,再进行编译,最后再进行安装,但是有点好处就是针对所需的服务可以自定义安装模块,确保系统的最小化安装。

什么是yum

Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装(百度全科)

yum的配置文件

运维利器之yum部署开源项目实战_lamp_02

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ll
总用量 32
-rw-r--r--. 1 root root 1664 4月  29 2018 CentOS-Base.repo   网络yum源的配置文件
-rw-r--r--. 1 root root 1309 4月  29 2018 CentOS-CR.repo
-rw-r--r--. 1 root root  649 4月  29 2018 CentOS-Debuginfo.repo   内核相关的更新包
-rw-r--r--. 1 root root  314 4月  29 2018 CentOS-fasttrack.repo  Yum的快速通道
-rw-r--r--. 1 root root  630 4月  29 2018 CentOS-Media.repo  本地Yum源配置文件
-rw-r--r--. 1 root root 1331 4月  29 2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 4768 4月  29 2018 CentOS-Vault.repo   最近版本加入老版本的yum

配置阿里yum源

为什么要配置Yum的阿里源,主要是因为使用阿里云的Yum源替代掉默认的yum源,下载软件速度可由得到保证

第一步:备份默认源

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak

运维利器之yum部署开源项目实战_lamp_03

第二步:下载阿里Yum源

[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2021-11-09 16:21:54--  http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 111.63.182.234, 111.63.182.236, 111.63.53.221, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|111.63.182.234|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”

100%[=======================================================================================================>] 2,523       --.-K/s 用时 0s      

2021-11-09 16:21:54 (539 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])


含义:使用阿里云的yum源代替默认的yum源,下载软件更快

运维利器之yum部署开源项目实战_lamp_04

第三步:清除所有缓存

[root@localhost yum.repos.d]# yum clean all 
已加载插件:fastestmirror
正在清理软件源: base extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors

运维利器之yum部署开源项目实战_运维_05

第四步: 重新生成缓存

[root@localhost yum.repos.d]# yum makecache
已加载插件:fastestmirror
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                      | 3.6 kB  00:00:00     
extras                                                                                                                    | 2.9 kB  00:00:00     
updates                                                                                                                   | 2.9 kB  00:00:00     
(1/10): base/7/x86_64/group_gz                                                                                            | 153 kB  00:00:00     
(2/10): extras/7/x86_64/filelists_db                                                                                      | 259 kB  00:00:00     
(3/10): base/7/x86_64/other_db                                                                                            | 2.6 MB  00:00:00     
(4/10): extras/7/x86_64/other_db                                                                                          | 145 kB  00:00:00     
(5/10): updates/7/x86_64/filelists_db                                                                                     | 6.5 MB  00:00:00     
(6/10): updates/7/x86_64/other_db                                                                                         | 830 kB  00:00:00     
(7/10): updates/7/x86_64/primary_db                                                                                       |  12 MB  00:00:01     
base/7/x86_64/primary_db       FAILED                                          
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/6d0c3a488c282fe537794b5946b01e28c7f44db79097bb06826e1c0c88bad5ef-primary.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
正在尝试其它镜像。
base/7/x86_64/filelists_db     FAILED                                          ===================             ] 220 kB/s |  26 MB  00:00:43 ETA 
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/d6d94c7d406fe7ad4902a97104b39a0d8299451832a97f31d71653ba982c955b-filelists.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
正在尝试其它镜像。
(8/10): base/7/x86_64/primary_db                                                                                          | 6.1 MB  00:00:00     
extras/7/x86_64/primary_db     FAILED                                          
http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/db1c88508275ffebdc6cd8686da08745d2552e5b219b2e6f4cbde7b8afd3b1a3-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
正在尝试其它镜像。
(9/10): extras/7/x86_64/primary_db                                                                                        | 243 kB  00:00:00     
(10/10): base/7/x86_64/filelists_db                                                                                       | 7.2 MB  00:00:00     
元数据缓存已建立

注意:http://mirrors.aliyun.com/repo/选择不同centos版本的yum源

运维利器之yum部署开源项目实战_yum_06

yum命令的一些基本操作

下面将使用yum来安装firefox,做一个例子

yum的查询操作
[root@localhost yum.repos.d]# yum search firefox
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
============================================================= N/S matched: firefox ==============================================================
firefox.i686 : Mozilla Firefox Web browser
firefox.x86_64 : Mozilla Firefox Web browser

  名称和简介匹配 only,使用“search all”试试。

运维利器之yum部署开源项目实战_服务器_07

yum的安装操作
[root@localhost yum.repos.d]# yum -y installl firefox       ###其中-y代表的是一路确定
已加载插件:fastestmirror
没有该命令:installl。请使用 /usr/bin/yum --help
[root@localhost yum.repos.d]# yum -y install firefox
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
省略好多
已安装:
  firefox.x86_64 0:91.3.0-1.el7.centos                                                                                                           

作为依赖被安装:
  adwaita-cursor-theme.noarch 0:3.28.0-1.el7      adwaita-icon-theme.noarch 0:3.28.0-1.el7       at-spi2-atk.x86_64 0:2.26.2-1.el7             
  at-spi2-core.x86_64 0:2.28.0-1.el7              atk.x86_64 0:2.28.1-2.el7                      avahi-libs.x86_64 0:0.6.31-20.el7             
  cairo.x86_64 0:1.15.12-4.el7                    cairo-gobject.x86_64 0:1.15.12-4.el7           centos-indexhtml.noarch 0:7-9.el7.centos      
  colord-libs.x86_64 0:1.3.4-2.el7                cups-libs.x86_64 1:1.6.3-51.el7                dconf.x86_64 0:0.28.0-4.el7                   
  dejavu-fonts-common.noarch 0:2.33-6.el7         dejavu-sans-fonts.noarch 0:2.33-6.el7          fontconfig.x86_64 0:2.13.0-4.3.el7            
  fontpackages-filesystem.noarch 0:1.44-8.el7     fribidi.x86_64 0:1.0.2-1.el7_7.1               gdk-pixbuf2.x86_64 0:2.36.12-3.el7            
  glib-networking.x86_64 0:2.56.1-1.el7           gnutls.x86_64 0:3.3.29-9.el7_6                 graphite2.x86_64 0:1.3.10-1.el7_3             
  gsettings-desktop-schemas.x86_64 0:3.28.0-3.el7 gtk-update-icon-cache.x86_64 0:3.22.30-6.el7   gtk3.x86_64 0:3.22.30-6.el7                   
  harfbuzz.x86_64 0:1.7.5-2.el7                   hicolor-icon-theme.noarch 0:0.12-7.el7         jasper-libs.x86_64 0:1.900.1-33.el7           
  jbigkit-libs.x86_64 0:2.0-11.el7                json-glib.x86_64 0:1.4.2-2.el7                 lcms2.x86_64 0:2.6-3.el7                      
  libICE.x86_64 0:1.0.9-9.el7                     libSM.x86_64 0:1.2.2-2.el7                     libX11.x86_64 0:1.6.7-4.el7_9                 
  libX11-common.noarch 0:1.6.7-4.el7_9            libXau.x86_64 0:1.0.8-2.1.el7                  libXcomposite.x86_64 0:0.4.4-4.1.el7          
  libXcursor.x86_64 0:1.1.15-1.el7                libXdamage.x86_64 0:1.1.4-4.1.el7              libXext.x86_64 0:1.3.3-3.el7                  
  libXfixes.x86_64 0:5.0.3-1.el7                  libXft.x86_64 0:2.3.2-2.el7                    libXi.x86_64 0:1.7.9-1.el7                    
  libXinerama.x86_64 0:1.1.3-2.1.el7              libXrandr.x86_64 0:1.5.1-2.el7                 libXrender.x86_64 0:0.9.10-1.el7              
  libXt.x86_64 0:1.1.5-3.el7                      libXtst.x86_64 0:1.2.3-1.el7                   libXxf86vm.x86_64 0:1.1.4-1.el7               
  libepoxy.x86_64 0:1.5.2-1.el7                   liberation-fonts-common.noarch 1:1.07.2-16.el7 liberation-sans-fonts.noarch 1:1.07.2-16.el7  
  libglvnd.x86_64 1:1.0.1-0.8.git5baa1e5.el7      libglvnd-egl.x86_64 1:1.0.1-0.8.git5baa1e5.el7 libglvnd-glx.x86_64 1:1.0.1-0.8.git5baa1e5.el7
  libgusb.x86_64 0:0.2.9-1.el7                    libjpeg-turbo.x86_64 0:1.2.90-8.el7            libmodman.x86_64 0:2.0.1-8.el7                
  libpng.x86_64 2:1.5.13-8.el7                    libproxy.x86_64 0:0.4.11-11.el7                libsoup.x86_64 0:2.62.2-2.el7                 
  libthai.x86_64 0:0.1.14-9.el7                   libtiff.x86_64 0:4.0.3-35.el7                  libusbx.x86_64 0:1.0.21-1.el7                 
  libwayland-client.x86_64 0:1.15.0-1.el7         libwayland-cursor.x86_64 0:1.15.0-1.el7        libwayland-egl.x86_64 0:1.15.0-1.el7          
  libwayland-server.x86_64 0:1.15.0-1.el7         libxcb.x86_64 0:1.13-1.el7                     libxkbcommon.x86_64 0:0.7.1-3.el7             
  libxshmfence.x86_64 0:1.2-1.el7                 mesa-libEGL.x86_64 0:18.3.4-12.el7_9           mesa-libGL.x86_64 0:18.3.4-12.el7_9           
  mesa-libgbm.x86_64 0:18.3.4-12.el7_9            mesa-libglapi.x86_64 0:18.3.4-12.el7_9         mozilla-filesystem.x86_64 0:1.9-11.el7        
  nettle.x86_64 0:2.7.1-9.el7_9                   pango.x86_64 0:1.42.4-4.el7_7                  pixman.x86_64 0:0.34.0-1.el7                  
  rest.x86_64 0:0.8.1-2.el7                       trousers.x86_64 0:0.3.14-2.el7                 xkeyboard-config.noarch 0:2.24-1.el7          

作为依赖被升级:
  freetype.x86_64 0:2.8-14.el7_9.1             glib2.x86_64 0:2.56.1-9.el7_9                nspr.x86_64 0:4.32.0-1.el7_9                       
  nss.x86_64 0:3.67.0-3.el7_9                  nss-softokn.x86_64 0:3.67.0-3.el7_9          nss-softokn-freebl.x86_64 0:3.67.0-3.el7_9         
  nss-sysinit.x86_64 0:3.67.0-3.el7_9          nss-tools.x86_64 0:3.67.0-3.el7_9            nss-util.x86_64 0:3.67.0-1.el7_9                   

完毕!
yum的卸载操作

这里需要注意的是,yum卸载的时候不卸载之前安装的依赖的哟

[root@localhost yum.repos.d]# yum -y remove firefox
已加载插件:fastestmirror
正在解决依赖关系
--> 正在检查事务
---> 软件包 firefox.x86_64.0.91.3.0-1.el7.centos 将被 删除
--> 解决依赖关系完成

依赖关系解决

=================================================================================================================================================
 Package                        架构                          版本                                         源                               大小
=================================================================================================================================================
正在删除:
 firefox                        x86_64                        91.3.0-1.el7.centos                          @updates                        265 M

事务概要
=================================================================================================================================================
移除  1 软件包

安装大小:265 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在删除    : firefox-91.3.0-1.el7.centos.x86_64                                                                                           1/1 
  验证中      : firefox-91.3.0-1.el7.centos.x86_64                                                                                           1/1 

删除:
  firefox.x86_64 0:91.3.0-1.el7.centos                                                                                                           

完毕!

运维利器之yum部署开源项目实战_yum_08

yum的更新操作

[root@localhost yum.repos.d]# yum -y update       ###后面如果不指定软件名称的话,默认是更新整个系统(全局更新,也包含内核)
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 GeoIP.x86_64.0.1.5.0-11.el7 将被 升级
---> 软件包 GeoIP.x86_64.0.1.5.0-14.el7 将被 更新
--> 正在处理依赖关系 geoipupdate,它被软件包 GeoIP-1.5.0-14.el7.x86_64 需要
---> 软件包 NetworkManager.x86_64.1.1.10.2-13.el7 将被 升级
---> 软件包 NetworkManager.x86_64.1.1.18.8-2.el7_9 将被 更新
---> 软件包 NetworkManager-libnm.x86_64.1.1.10.2-13.el7 将被 升级
---> 软件包 NetworkManager-libnm.x86_64.1.1.18.8-2.el7_9 将被 更新
---> 软件包 NetworkManager-team.x86_64.1.1.10.2-13.el7 将被 升级
---> 软件包 NetworkManager-team.x86_64.1.1.18.8-2.el7_9 将被 更新
---> 软件包 NetworkManager-tui.x86_64.1.1.10.2-13.el7 将被 升级
---> 软件包 NetworkManager-tui.x86_64.1.1.18.8-2.el7_9 将被 更新
---> 软件包 acl.x86_64.0.2.2.51-14.el7 将被 升级
---> 软件包 acl.x86_64.0.2.2.51-15.el7 将被 更新
---> 软件包 alsa-lib.x86_64.0.1.1.4.1-2.el7 将被 升级
---> 软件包 alsa-lib.x86_64.0.1.1.8-1.el7 将被 更新
---> 软件包 audit.x86_64.0.2.8.1-3.el7 将被 升级
---> 软件包 audit.x86_64.0.2.8.5-4.el7 将被 更新

省略n多

[root@localhost yum.repos.d]# yum -y update wget
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
No packages marked for update

运维利器之yum部署开源项目实战_运维_09

什么是LAMP

Linux常用的几种架构
  • LAMP:Linux + Apache + MySQL + PHP LAMP 架构(组合)
  • LNMP:Linux + Nginx + MySQL + php-fpm LNMP 架构(组合)
  • LNMPA:Linux + Nginx(80) + MySQL + PHP + Apache Nginx 代理方式

其中:

  • Linux:Linux系统
  • Apache:Apache是世界使用排名第一的Web服务器软件。
  • PHP:一种专门用于Web开发的编程语言。
  • MySQL:MySQL是一个关系型数据库管理系统,主要用于永久存储项目数据。
LAMP环境准备

运维利器之yum部署开源项目实战_项目架构_10

部署LAMP环境
部署前的环境准备
关闭防火墙和selinux
[root@localhost ~]# setenforce 0				####临时关闭selinux
    
[root@localhost ~]# getenforce
Permissive     ###当前是正常运行的状态,查看当前是否关闭了selinux
  
##编辑selinux配置文件,永久关闭  
[root@localhost ~]# vim /etc/selinux/config       ####修改完配置文件,需要重启服务器,来使配置文件生效
[root@localhost ~]# cat /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled     #将这个位置改成disabled的
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

Connecting to 192.168.211.186:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

Last login: Tue Nov  9 16:14:29 2021 from 192.168.211.1
[root@localhost ~]# getenforce       #重启完成之后,显示selinux是关闭的状态
Disabled
[root@localhost ~]# systemctl stop firewalld  关闭防火墙
查询当前服务器是否安装Apache
[root@localhost ~]# rpm -qa | grep httpd
查询当前服务器是否安装MySQL
[root@localhost ~]# rpm -qa | grep mysql
查询当前服务器是否安装PHP
[root@localhost ~]# rpm -qa | grep php

运维利器之yum部署开源项目实战_项目架构_11

LAMP环境之Apache安装
使用yum命令安装httpd软件包
[root@localhost ~]# yum -y install httpd
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-97.el7.centos.1 将被 安装
--> 正在处理依赖关系 httpd-tools = 2.4.6-97.el7.centos.1,它被软件包 httpd-2.4.6-97.el7.centos.1.x86_64 需要
--> 正在处理依赖关系 /etc/mime.types,它被软件包 httpd-2.4.6-97.el7.centos.1.x86_64 需要
--> 正在处理依赖关系 libaprutil-1.so.0()(64bit),它被软件包 httpd-2.4.6-97.el7.centos.1.x86_64 需要
--> 正在处理依赖关系 libapr-1.so.0()(64bit),它被软件包 httpd-2.4.6-97.el7.centos.1.x86_64 需要
--> 正在检查事务
---> 软件包 apr.x86_64.0.1.4.8-7.el7 将被 安装
---> 软件包 apr-util.x86_64.0.1.5.2-6.el7 将被 安装
---> 软件包 httpd-tools.x86_64.0.2.4.6-97.el7.centos.1 将被 安装
---> 软件包 mailcap.noarch.0.2.1.41-2.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=====================================================================
 Package        架构      版本                      源          大小
=====================================================================
正在安装:
 httpd          x86_64    2.4.6-97.el7.centos.1     updates    2.7 M
为依赖而安装:
 apr            x86_64    1.4.8-7.el7               base       104 k
 apr-util       x86_64    1.5.2-6.el7               base        92 k
 httpd-tools    x86_64    2.4.6-97.el7.centos.1     updates     93 k
 mailcap        noarch    2.1.41-2.el7              base        31 k

事务概要
=====================================================================
安装  1 软件包 (+4 依赖软件包)

总下载量:3.0 M
安装大小:10 M
Downloading packages:
(1/5): apr-util-1.5.2-6.el7.x86_64.rpm          |  92 kB   00:00     
(2/5): httpd-tools-2.4.6-97.el7.centos.1.x86_64 |  93 kB   00:00     
(3/5): apr-1.4.8-7.el7.x86_64.rpm               | 104 kB   00:00     
(4/5): httpd-2.4.6-97.el7.centos.1.x86_64.rpm   | 2.7 MB   00:00     
(5/5): mailcap-2.1.41-2.el7.noarch.rpm          |  31 kB   00:00     
---------------------------------------------------------------------
总计                                    3.0 MB/s | 3.0 MB  00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : apr-1.4.8-7.el7.x86_64                           1/5 
  正在安装    : apr-util-1.5.2-6.el7.x86_64                      2/5 
  正在安装    : httpd-tools-2.4.6-97.el7.centos.1.x86_64         3/5 
  正在安装    : mailcap-2.1.41-2.el7.noarch                      4/5 
  正在安装    : httpd-2.4.6-97.el7.centos.1.x86_64               5/5 
  验证中      : apr-1.4.8-7.el7.x86_64                           1/5 
  验证中      : mailcap-2.1.41-2.el7.noarch                      2/5 
  验证中      : httpd-2.4.6-97.el7.centos.1.x86_64               3/5 
  验证中      : apr-util-1.5.2-6.el7.x86_64                      4/5 
  验证中      : httpd-tools-2.4.6-97.el7.centos.1.x86_64         5/5 

已安装:
  httpd.x86_64 0:2.4.6-97.el7.centos.1                               

作为依赖被安装:
  apr.x86_64 0:1.4.8-7.el7                                           
  apr-util.x86_64 0:1.5.2-6.el7                                      
  httpd-tools.x86_64 0:2.4.6-97.el7.centos.1                         
  mailcap.noarch 0:2.1.41-2.el7                                      

完毕!

配置/etc/httpd/conf/httpd.conf文件

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf 

# as error documents.  e.g. admin@your-domain.com
#
ServerAdmin root@localhost

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName www.example.com:80
ServerName localhost:80       #这一行需要手动添加上去

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other 
# <Directory> blocks below.
#
<Directory />
    AllowOverride none
    Require all denied
</Directory>

运维利器之yum部署开源项目实战_服务器_12

使用systemctl命令重启httpd服务,使用ss -ntlp命令,查看是否有80端口监听
[root@localhost ~]# syatemctl restart httpd
[root@localhost ~]# ss -ntlp|grep httpd
LISTEN     0      128         :::80                      :::*                   users:(("httpd",pid=1366,fd=4),("httpd",pid=1365,fd=4),("httpd",pid=1364,fd=4),("httpd",pid=1363,fd=4),("httpd",pid=1362,fd=4),("httpd",pid=1361,fd=4))

设置httpd服务开机启动

[root@localhost ~]# systemctl enable httpd        ###开启httpd的开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

[root@localhost ~]# systemctl status httpd    ###查看httpd当前的状态
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2021-11-09 17:14:01 CST; 2min 1s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 1361 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─1361 /usr/sbin/httpd -DFOREGROUND
           ├─1362 /usr/sbin/httpd -DFOREGROUND
           ├─1363 /usr/sbin/httpd -DFOREGROUND
           ├─1364 /usr/sbin/httpd -DFOREGROUND
           ├─1365 /usr/sbin/httpd -DFOREGROUND
           └─1366 /usr/sbin/httpd -DFOREGROUND

11月 09 17:14:01 localhost.localdomain systemd[1]: Starting The A...
11月 09 17:14:01 localhost.localdomain systemd[1]: Started The Ap...
Hint: Some lines were ellipsized, use -l to show in full.

运维利器之yum部署开源项目实战_项目架构_13

查看本机的IP地址
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:18:85:96 brd ff:ff:ff:ff:ff:ff
    inet 192.168.211.186/24 brd 192.168.211.255 scope global noprefixroute dynamic ens33
       valid_lft 1523sec preferred_lft 1523sec
    inet6 fe80::12ce:59d6:ca98:3ebb/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
在浏览器中,输入本机IP地址,如下图所示:

运维利器之yum部署开源项目实战_yum_14

LAMP环境之MySQL安装
下载mysql的yum源

由于yum源上默认没有mysql-server。所以必须去官网下载后在安装

[root@localhost ~]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
--2021-11-09 17:20:53--  http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
正在解析主机 dev.mysql.com (dev.mysql.com)... 137.254.60.11
正在连接 dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 301 Moved Permanently
位置:https://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm [跟随至新的 URL]
--2021-11-09 17:20:54--  https://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
正在连接 dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:https://repo.mysql.com//mysql-community-release-el7-5.noarch.rpm [跟随至新的 URL]
--2021-11-09 17:20:55--  https://repo.mysql.com//mysql-community-release-el7-5.noarch.rpm
正在解析主机 repo.mysql.com (repo.mysql.com)... 23.45.53.26
正在连接 repo.mysql.com (repo.mysql.com)|23.45.53.26|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:6140 (6.0K) [application/x-redhat-package-manager]
正在保存至: “mysql-community-release-el7-5.noarch.rpm”

100%[=======================================================================================================>] 6,140       --.-K/s 用时 0s      

2021-11-09 17:20:55 (939 MB/s) - 已保存 “mysql-community-release-el7-5.noarch.rpm” [6140/6140])
添加mysql的yum源存储库
[root@localhost ~]#  rpm -ivh mysql-community-release-el7-5.noarch.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-release-el7-5    ################################# [100%]

运维利器之yum部署开源项目实战_服务器_15

安装MYSQL
[root@localhost ~]# yum -y install mysql-community-server
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
mysql-connectors-community                                                                                                | 2.6 kB  00:00:00     
mysql-tools-community                                                                                                     | 2.6 kB  00:00:00     
mysql56-community                                                                                                         | 2.6 kB  00:00:00     
(1/3): mysql-connectors-community/x86_64/primary_db                                                                       |  87 kB  00:00:00     
(2/3): mysql-tools-community/x86_64/primary_db                                                                            |  92 kB  00:00:00     
(3/3): mysql56-community/x86_64/primary_db                                                                                | 297 kB  00:00:01     
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-server.x86_64.0.5.6.51-2.el7 将被 安装
--> 正在处理依赖关系 mysql-community-common(x86-64) = 5.6.51-2.el7,它被软件包 mysql-community-server-5.6.51-2.el7.x86_64 需要
--> 正在处理依赖关系 mysql-community-client(x86-64) >= 5.6.10,它被软件包 mysql-community-server-5.6.51-2.el7.x86_64 需要
--> 正在处理依赖关系 net-tools,它被软件包 mysql-community-server-5.6.51-2.el7.x86_64 需要
--> 正在处理依赖关系 perl(DBI),它被软件包 mysql-community-server-5.6.51-2.el7.x86_64 需要
--> 正在处理依赖关系 perl(Data::Dumper),它被软件包 mysql-community-server-5.6.51-2.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mysql-community-client.x86_64.0.5.6.51-2.el7 将被 安装
--> 正在处理依赖关系 mysql-community-libs(x86-64) >= 5.6.10,它被软件包 mysql-community-client-5.6.51-2.el7.x86_64 需要
---> 软件包 mysql-community-common.x86_64.0.5.6.51-2.el7 将被 安装
---> 软件包 net-tools.x86_64.0.2.0-0.25.20131004git.el7 将被 安装


下面步骤省略


已安装:
  mysql-community-libs.x86_64 0:5.6.51-2.el7                             mysql-community-server.x86_64 0:5.6.51-2.el7                            

作为依赖被安装:
  mysql-community-client.x86_64 0:5.6.51-2.el7    mysql-community-common.x86_64 0:5.6.51-2.el7    net-tools.x86_64 0:2.0-0.25.20131004git.el7   
  perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7    perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7     perl-DBI.x86_64 0:1.627-4.el7                 
  perl-Data-Dumper.x86_64 0:2.145-3.el7           perl-IO-Compress.noarch 0:2.061-2.el7           perl-Net-Daemon.noarch 0:0.48-5.el7           
  perl-PlRPC.noarch 0:0.2020-14.el7              

替代:
  mariadb-libs.x86_64 1:5.5.56-2.el7
启动mysql
[root@localhost ~]# systemctl restart mysqld.service
[root@localhost ~]# ss -antup | grep mysql
tcp    LISTEN     0      80       :::3306                 :::*                   users:(("mysqld",pid=1756,fd=10))
[root@localhost ~]#
初始化数据库
[root@localhost ~]# mysql_secure_installation



NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 	设置超级管理员root密码,注:默认为空,直接回车即可
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Sorry, passwords do not match.

New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y   移除匿名账户:
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n    不禁用root远程连接:
 ... skipping.

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n   不移除默认数据库(测试用例):
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y   
 ... Success!




All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


Cleaning up...
把mysqld添加到开机启动
默认已经开机启动,这里可以跳过
连接MySQL数据库
[root@localhost ~]# mysql -u root -p123456 -h 127.0.0.1
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.6.51 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>    可以进入到数据库代表以成完成

运维利器之yum部署开源项目实战_yum_16


查看数据库
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
含义:显示所有数据库
注意:命令结尾要有“;”
退出mysql
mysql> exit
Bye
[root@localhost ~]#
LAMP环境之PHP安装
使用yum命令安装php
[root@localhost ~]# yum -y install php
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 php.x86_64.0.5.4.16-48.el7 将被 安装
--> 正在处理依赖关系 php-common(x86-64) = 5.4.16-48.el7,它被软件包 php-5.4.16-48.el7.x86_64 需要
--> 正在处理依赖关系 php-cli(x86-64) = 5.4.16-48.el7,它被软件包 php-5.4.16-48.el7.x86_64 需要
--> 正在检查事务
---> 软件包 php-cli.x86_64.0.5.4.16-48.el7 将被 安装
---> 软件包 php-common.x86_64.0.5.4.16-48.el7 将被 安装
--> 正在处理依赖关系 libzip.so.2()(64bit),它被软件包 php-common-5.4.16-48.el7.x86_64 需要
--> 正在检查事务
---> 软件包 libzip.x86_64.0.0.10.1-8.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=================================================================================================================================================
Package                             架构                            版本                                    源                             大小
=================================================================================================================================================
正在安装:
php                                 x86_64                          5.4.16-48.el7                           base                          1.4 M
为依赖而安装:
libzip                              x86_64                          0.10.1-8.el7                            base                           48 k
php-cli                             x86_64                          5.4.16-48.el7                           base                          2.7 M
php-common                          x86_64                          5.4.16-48.el7                           base                          565 k

事务概要
=================================================================================================================================================
安装  1 软件包 (+3 依赖软件包)

总下载量:4.7 M
安装大小:17 M
Downloading packages:
(1/4): libzip-0.10.1-8.el7.x86_64.rpm                                                                                     |  48 kB  00:00:00     
(2/4): php-5.4.16-48.el7.x86_64.rpm                                                                                       | 1.4 MB  00:00:00     
(3/4): php-common-5.4.16-48.el7.x86_64.rpm                                                                                | 565 kB  00:00:00     
(4/4): php-cli-5.4.16-48.el7.x86_64.rpm                                                                                   | 2.7 MB  00:00:00     
-------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                             4.0 MB/s | 4.7 MB  00:00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 正在安装    : libzip-0.10.1-8.el7.x86_64                                                                                                   1/4 
 正在安装    : php-common-5.4.16-48.el7.x86_64                                                                                              2/4 
 正在安装    : php-cli-5.4.16-48.el7.x86_64                                                                                                 3/4 
 正在安装    : php-5.4.16-48.el7.x86_64                                                                                                     4/4 
 验证中      : php-5.4.16-48.el7.x86_64                                                                                                     1/4 
 验证中      : libzip-0.10.1-8.el7.x86_64                                                                                                   2/4 
 验证中      : php-cli-5.4.16-48.el7.x86_64                                                                                                 3/4 
 验证中      : php-common-5.4.16-48.el7.x86_64                                                                                              4/4 

已安装:
 php.x86_64 0:5.4.16-48.el7                                                                                                                     

作为依赖被安装:
 libzip.x86_64 0:0.10.1-8.el7                 php-cli.x86_64 0:5.4.16-48.el7                 php-common.x86_64 0:5.4.16-48.el7                

完毕!
重启httpd服务
[root@localhost ~]# systemctl restart httpd
切记只要改动php,就一定要重启httpd服务
测试LAMP环境是否可以使用

第一步:使用cd命令进入/var/www/html目录

[root@localhost ~]# cd /var/www/html/      #该目录为httpd网页的默认的根目录

第二步:使用vim命令创建index.php文件

[root@localhost html]# vim index.php

第三步:编写php代码

<?php
  echo 'hello world';
?>

运维利器之yum部署开源项目实战_运维_17

在浏览器,输入服务器IP,如下图所示:

运维利器之yum部署开源项目实战_yum_18

部署Discuz!论坛

Discuz!论坛概述

Discuz!是一套开源的社区论坛软件系统,总之开源使我们强大。

下载源代码

下载地址:https://gitee.com/ComsenzDiscuz/DiscuzX

上传代码
安装lrzsz命令将源码上传到服务器上

还有好多的文件传输工具,这个看自己个人的喜好了哈,我这边就选择lrzsz这个服务了哈,简单又方便

[root@localhost ~]# yum -y install lrzsz
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 lrzsz.x86_64.0.0.12.20-36.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=======================================================================
 Package      架构          版本                     源           大小
=======================================================================
正在安装:
 lrzsz        x86_64        0.12.20-36.el7           base         78 k

事务概要
=======================================================================
安装  1 软件包

总下载量:78 k
安装大小:181 k
Downloading packages:
lrzsz-0.12.20-36.el7.x86_64.rpm                   |  78 kB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : lrzsz-0.12.20-36.el7.x86_64                        1/1 
  验证中      : lrzsz-0.12.20-36.el7.x86_64                        1/1 

已安装:
  lrzsz.x86_64 0:0.12.20-36.el7                                        

完毕!

运维利器之yum部署开源项目实战_项目架构_19

[root@localhost ~]# ls
anaconda-ks.cfg  discuz.zip  mysql-community-release-el7-5.noarch.rpm
[root@localhost ~]#
安装unzip命令并且解压缩论坛代码
[root@localhost ~]# yum -y install unzip
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 unzip.x86_64.0.6.0-22.el7_9 将被 安装
--> 解决依赖关系完成

依赖关系解决

=======================================================================
 Package      架构          版本                  源              大小
=======================================================================
正在安装:
 unzip        x86_64        6.0-22.el7_9          updates        171 k

事务概要
=======================================================================
安装  1 软件包

总下载量:171 k
安装大小:365 k
Downloading packages:
unzip-6.0-22.el7_9.x86_64.rpm                     | 171 kB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : unzip-6.0-22.el7_9.x86_64                          1/1 
  验证中      : unzip-6.0-22.el7_9.x86_64                          1/1 

已安装:
  unzip.x86_64 0:6.0-22.el7_9                                          

完毕!

[root@localhost ~]# unzip discuz.zip
[root@localhost ~]# cd discuz
[root@localhost discuz]# ls
admin.php    crossdomain.xml  index.php   portal.php  uc_client
api          data             install     robots.txt  uc_server
api.php      favicon.ico      m           search.php
archiver     forum.php        member.php  source
config       group.php        misc.php    static
connect.php  home.php         plugin.php  template
将网站代码拷贝到/var/www/html下
[root@localhost discuz]# cp -r ./* /var/www/html/
[root@localhost discuz]# ll /var/www/html/
总用量 68
-rw-r--r--  1 root root 2748 11月  9 20:30 admin.php
drwxr-xr-x 10 root root  149 11月  9 20:30 api
-rw-r--r--  1 root root  727 11月  9 20:30 api.php
drwxr-xr-x  2 root root   23 11月  9 20:30 archiver
drwxr-xr-x  2 root root   90 11月  9 20:30 config
-rw-r--r--  1 root root 1017 11月  9 20:30 connect.php
-rw-r--r--  1 root root  106 11月  9 20:30 crossdomain.xml
drwxr-xr-x 12 root root  202 11月  9 20:30 data
-rw-r--r--  1 root root 5558 11月  9 20:30 favicon.ico
-rw-r--r--  1 root root 2245 11月  9 20:30 forum.php
-rw-r--r--  1 root root  821 11月  9 20:30 group.php
-rw-r--r--  1 root root 1280 11月  9 20:30 home.php
-rw-r--r--  1 root root 5890 11月  9 20:30 index.php
drwxr-xr-x  5 root root   64 11月  9 20:30 install
drwxr-xr-x  2 root root   23 11月  9 20:30 m
-rw-r--r--  1 root root 1025 11月  9 20:30 member.php
-rw-r--r--  1 root root 2435 11月  9 20:30 misc.php
-rw-r--r--  1 root root 1788 11月  9 20:30 plugin.php
-rw-r--r--  1 root root  977 11月  9 20:30 portal.php
-rw-r--r--  1 root root  582 11月  9 20:30 robots.txt
-rw-r--r--  1 root root 1155 11月  9 20:30 search.php
drwxr-xr-x 10 root root  168 11月  9 20:30 source
drwxr-xr-x  7 root root   86 11月  9 20:30 static
drwxr-xr-x  3 root root   38 11月  9 20:30 template
drwxr-xr-x  7 root root  106 11月  9 20:30 uc_client
drwxr-xr-x 14 root root  256 11月  9 20:30 uc_server
使用服务器IP地址访问论坛

看到下面的页面表示访问成功,点击我同意

运维利器之yum部署开源项目实战_服务器_20

设置目录权限

如上图所示,系统提示很多文件没有可写权限,设置如下:

运维利器之yum部署开源项目实战_项目架构_21

[root@localhost discuz]# chmod -R a+w /var/www/html/     ##这个是偷懒写法,生产环境如果你这样搞,就尴尬了,建议见上图不可写的目录逐个添加相应的权限
重新刷新,如下图所示:

运维利器之yum部署开源项目实战_服务器_22

安装PHP扩展

如上图所示:以上结果代表系统缺少php-mysqli扩展,安装后即可解决。

使用yum命令安装php-mysqli扩展
[root@localhost discuz]# yum -y install php-mysqli
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 php-mysql.x86_64.0.5.4.16-48.el7 将被 安装
--> 正在处理依赖关系 php-pdo(x86-64) = 5.4.16-48.el7,它被软件包 php-mysql-5.4.16-48.el7.x86_64 需要
--> 正在检查事务
---> 软件包 php-pdo.x86_64.0.5.4.16-48.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=======================================================================
 Package          架构          版本                 源           大小
=======================================================================
正在安装:
 php-mysql        x86_64        5.4.16-48.el7        base        102 k
为依赖而安装:
 php-pdo          x86_64        5.4.16-48.el7        base         99 k

事务概要
=======================================================================
安装  1 软件包 (+1 依赖软件包)

总下载量:201 k
安装大小:424 k
Downloading packages:
(1/2): php-pdo-5.4.16-48.el7.x86_64.rpm           |  99 kB   00:00     
(2/2): php-mysql-5.4.16-48.el7.x86_64.rpm         | 102 kB   00:02     
-----------------------------------------------------------------------
总计                                       69 kB/s | 201 kB  00:02     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : php-pdo-5.4.16-48.el7.x86_64                       1/2 
  正在安装    : php-mysql-5.4.16-48.el7.x86_64                     2/2 
  验证中      : php-pdo-5.4.16-48.el7.x86_64                       1/2 
  验证中      : php-mysql-5.4.16-48.el7.x86_64                     2/2 

已安装:
  php-mysql.x86_64 0:5.4.16-48.el7                                     

作为依赖被安装:
  php-pdo.x86_64 0:5.4.16-48.el7                                       

完毕!
重启httpd服务
[root@localhost discuz]# systemctl restart httpd
重新刷新网页,如下图所示:

运维利器之yum部署开源项目实战_运维_23

设置运行环境
开始安装页面已经没有任何报错,点击下一步,进入设置运行环境页面

运维利器之yum部署开源项目实战_lamp_24

设置数据库信息与管理员信息

运维利器之yum部署开源项目实战_项目架构_25

运维利器之yum部署开源项目实战_yum_26

访问安装后的论坛

运维利器之yum部署开源项目实战_yum_27

进入论坛首页,如下图所示:

运维利器之yum部署开源项目实战_lamp_28

打完收工!

其他yum实战

运维利器之yum及yum偷包的实战

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
zZHnZavbRDNq