33、程序包管理之四-编译安装

33.1 程序包编译安装流程

        testapp-VERSION-release.src.rpmà安装后,使用rpmbuild命令制作成二进制格式的rpm包,而后再安装

        源代码à预处理à编译(gcc)à汇编à链接à执行

33.2 源代码组织格式:

        多文件:文件中的代码之间,很可能存在跨文件依赖关系;

        C,C++:make(configureàMakefile.inàmakefile)

        java:maven

33.3 编译安装三步骤

        1、./configure:

                (1)通过选项传递参数,指定启用特性,安装路径等;执行时会参考用户的指定以及makefile.in文件生成makefile

                (2)检查依赖到的外部环境

        2、make:

                根据makefile文件,构建应用程序

        3、makeinstall:

        4、开发工具:

                autoconf:生成configure脚本

                automake:生成Makefile.in

33.4 开源程序源代码的获取:

        官方自建站点:

                apache.org(ASF)

                mariadb.org

                …

        代码托管:

                SourceForge

                Github.com

                code.google.com

        C/C++:gcc(GNU C Complier)

33.5 编译C源代码:

        1、前提:提供开发工具及开发环境

                开发工具:make,gcc等,

                开发环境:开发库,头文件

                        glibc:标准库

                通过“包组”提供开发组件

                        CentOS6:“Development Tools”,“Server Platform Development”

        2、配置步骤

        第一步:configure脚本

                选项:指定安装位置,指定启用的特性

                –help:获取其支持使用的选项

                        选项分类:

                                安装路径设定:

                                        –prefix=/PATH/TO/SOMEWHERE:指定默认安装路径

                                        –sysconfigdir=/PATH/TO/SOMEWHERE:配置文件安装位置

                                System types:

                                Optional Features:可选特性

                                        –disable-FEATURE

                                        –enable-FEATURE[=ARG]

                                Optional Packages:可选包

                                        –with-PACKAGE[=ARG]

                                        –without-PACKAGE

        第二步:make

        第三步:make install

        3、安装后的配置:

                (1)导出二进制程序目录至PATH环境变量中;

                        编辑文件/etc/profile.d/NAME.sh

                                export PATH=/PATH/TO/BIN:$PATH

                (2)导出库文件路径

                        编辑/etc/ld.so.conf.d/NAME.conf

                                添加新的库文件所在目录至此文件中

                        让系统重新生成缓存:

                                ldconfig [-v]

                (3)导出头文件

                        基于链接的方式实现

                                ln -sv

                (4)导出帮助手册

                        编辑/etc/man.config文件

                                添加一个MANPATH

联系:

        1、yum的配置和使用;包括yum repository的创建

        2、编译安装apache 2.2;启动此服务;

32、程序包管理之三-yum

32.1 yum简介

        CentOS:yum,dnf

        URL:yum仓库路径

        YUM:yellow dog,Yellowdog Update Modifier

32.2 repository

        1、yum repository: yum repo

                存储了众多的yum包,以及包的相关的元数据文件(放置于特定目录下:repodata);

        2、文件服务器

                ftp://

                http://

                nfs://

                file://

        3、yum 客户端:

                配置文件:

                        /etc/yum.conf:为所有仓库提供公共配置

                        /etc/yum.repos.d/*.repo:为仓库的指向提供配置

                [root@localhost cd-rom]# rpm -qc yum

                /etc/logrotate.d/yum

                /etc/yum.conf

                /etc/yum/version-groups.conf

                仓库指向的定义:

                [repositoryID]

                        name=Some name for this respository

                        baseurl=url://path/to/respository/

                        enabled={1|0}

                        gpgcheck={1|0}

                        gpgkey=URL

                        enablegroups={1|0}

                        failovermethod={roundrobin|priority}

                        默认为roundrobin,意为随机挑选;

                        cost=

                        默认为1000

        4、yum命令的用法

                yum [options] [command] package

        显示仓库列表

                yum repolist [all|enabled|disabled]:显示仓库列表

                [root@localhost cd-rom]# yum repolist all

                Loaded plugins: fastestmirror, langpacks

                Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                repo id                     repo name                    status

                C7.0.1406-base/x86_64       CentOS-7.0.1406 – Base       disabled

                C7.0.1406-centosplus/x86_64 CentOS-7.0.1406 – CentOSPlus disabled

                C7.0.1406-extras/x86_64     CentOS-7.0.1406 – Extras     disabled

                C7.0.1406-fasttrack/x86_64  CentOS-7.0.1406 – CentOSPlus disabled

                C7.0.1406-updates/x86_64    CentOS-7.0.1406 – Updates    disabled

                C7.1.1503-base/x86_64       CentOS-7.1.1503 – Base       disabled

                C7.1.1503-centosplus/x86_64 CentOS-7.1.1503 – CentOSPlus disabled

                C7.1.1503-extras/x86_64     CentOS-7.1.1503 – Extras     disabled

                C7.1.1503-fasttrack/x86_64  CentOS-7.1.1503 – CentOSPlus disabled

                C7.1.1503-updates/x86_64    CentOS-7.1.1503 – Updates    disabled

                C7.2.1511-base/x86_64       CentOS-7.2.1511 – Base       disabled

                C7.2.1511-centosplus/x86_64 CentOS-7.2.1511 – CentOSPlus disabled

                C7.2.1511-extras/x86_64     CentOS-7.2.1511 – Extras     disabled

                C7.2.1511-fasttrack/x86_64  CentOS-7.2.1511 – CentOSPlus disabled

                C7.2.1511-updates/x86_64    CentOS-7.2.1511 – Updates    disabled

                C7.3.1611-base/x86_64       CentOS-7.3.1611 – Base       disabled

                C7.3.1611-centosplus/x86_64 CentOS-7.3.1611 – CentOSPlus disabled

                C7.3.1611-extras/x86_64     CentOS-7.3.1611 – Extras     disabled

                C7.3.1611-fasttrack/x86_64  CentOS-7.3.1611 – CentOSPlus disabled

                C7.3.1611-updates/x86_64    CentOS-7.3.1611 – Updates    disabled

                !base/7/x86_64              CentOS-7 – Base              enabled: 10,072

                base-debuginfo/x86_64       CentOS-7 – Debuginfo         disabled

                base-source/7               CentOS-7 – Base Sources      disabled

                c7-media                    CentOS-7 – Media             disabled

                centosplus/7/x86_64         CentOS-7 – Plus              disabled

                centosplus-source/7         CentOS-7 – Plus Sources      disabled

                cr/7/x86_64                 CentOS-7 – cr                disabled

                !extras/7/x86_64            CentOS-7 – Extras            enabled:    476

                extras-source/7             CentOS-7 – Extras Sources    disabled

                fasttrack/7/x86_64          CentOS-7 – fasttrack         disabled

                !updates/7/x86_64           CentOS-7 – Updates           enabled:  2,189

                updates-source/7            CentOS-7 – Updates Sources   disabled

                repolist: 12,737

                [root@localhost cd-rom]# 

        显示程序包

                yum list [all|glob_exp]:显示所有程序包或者自定义的程序包

                yum list {avaliable|installed|updates} [glob_exp]

                [root@localhost cd-rom]# yum list all | head -20

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                Installed Packages

                GConf2.x86_64                               3.2.6-8.el7                @anaconda

                GeoIP.x86_64                                1.5.0-11.el7               @anaconda

                ModemManager.x86_64                         1.6.0-2.el7                @anaconda

                ModemManager-glib.x86_64                    1.6.0-2.el7                @anaconda

                NetworkManager.x86_64                       1:1.8.0-9.el7              @anaconda

                NetworkManager-adsl.x86_64                  1:1.8.0-9.el7              @anaconda

                NetworkManager-glib.x86_64                  1:1.8.0-9.el7              @anaconda

                NetworkManager-libnm.x86_64                 1:1.8.0-9.el7              @anaconda

                NetworkManager-libreswan.x86_64             1.2.4-2.el7                @anaconda

                NetworkManager-libreswan-gnome.x86_64       1.2.4-2.el7                @anaconda

                NetworkManager-ppp.x86_64                   1:1.8.0-9.el7              @anaconda

                NetworkManager-team.x86_64                  1:1.8.0-9.el7              @anaconda

                NetworkManager-tui.x86_64                   1:1.8.0-9.el7              @anaconda

                NetworkManager-wifi.x86_64                  1:1.8.0-9.el7              @anaconda

                Exiting on Broken Pipe

                [root@localhost cd-rom]# 

        安装程序包

                yum install package

                yum reinstall package重新安装

                [root@localhost cd-rom]# yum reinstall zsh

                Loaded plugins: fastestmirror, langpacks

                No Match for argument: zsh

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                Package(s) zsh available, but not installed.

                Error: Nothing to do

                [root@localhost cd-rom]# yum install zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                Resolving Dependencies

                –> Running transaction check

                —> Package zsh.x86_64 0:5.0.2-34.el7_8.2 will be installed

                –> Finished Dependency Resolution

                Dependencies Resolved

                ===============================================================================================================================================================

                 Package                          Arch                                Version                                          Repository                         Size

                ===============================================================================================================================================================

                Installing:

                 zsh                              x86_64                              5.0.2-34.el7_8.2                                 base                              2.4 M

                Transaction Summary

                ===============================================================================================================================================================

                Install  1 Package

                Total download size: 2.4 M

                Installed size: 5.6 M

                Is this ok [y/d/N]: y

                Downloading packages:

                zsh-5.0.2-34.el7_8.2.x86_64.rpm                                                                                                         | 2.4 MB  00:00:03     

                Running transaction check

                Running transaction test

                Transaction test succeeded

                Running transaction

                  Installing : zsh-5.0.2-34.el7_8.2.x86_64                                                                                                                 1/1 

                  Verifying  : zsh-5.0.2-34.el7_8.2.x86_64                                                                                                                 1/1 

                Installed:

                  zsh.x86_64 0:5.0.2-34.el7_8.2                                                                                                                                

                Complete!

                [root@localhost cd-rom]# 

        升级程序包

                yum update package

                yum downgrade package降级程序包

                [root@localhost cd-rom]# yum update zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                No packages marked for update

                [root@localhost cd-rom]# yum downgrade zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                Nothing to do

                [root@localhost cd-rom]# 

        检查可用升级

                yum check-update package

                [root@localhost cd-rom]# yum check-update python

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                python.x86_64                                  2.7.5-90.el7                                  updates

                [root@localhost cd-rom]# 

        卸载程序包

                yum remove|erase package

                [root@localhost cd-rom]# yum remove zsh.x86_64 

                Loaded plugins: fastestmirror, langpacks

                Resolving Dependencies

                –> Running transaction check

                —> Package zsh.x86_64 0:5.0.2-34.el7_8.2 will be erased

                –> Finished Dependency Resolution

                Dependencies Resolved

                ====================================================================================================

                 Package           Arch                 Version                           Repository           Size

                ====================================================================================================

                Removing:

                 zsh               x86_64               5.0.2-34.el7_8.2                  @base               5.6 M

                Transaction Summary

                ====================================================================================================

                Remove  1 Package

                Installed size: 5.6 M

                Is this ok [y/N]: y

                Downloading packages:

                Running transaction check

                Running transaction test

                Transaction test succeeded

                Running transaction

                  Erasing    : zsh-5.0.2-34.el7_8.2.x86_64                                                      1/1 

                  Verifying  : zsh-5.0.2-34.el7_8.2.x86_64                                                      1/1 

                Removed:

                  zsh.x86_64 0:5.0.2-34.el7_8.2                                                                     

                Complete!

                [root@localhost cd-rom]# 

        查看程序包information

                yum info package

                [root@localhost cd-rom]# yum info zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                Installed Packages

                Name        : zsh

                Arch        : x86_64

                Version     : 5.0.2

                Release     : 34.el7_8.2

                Size        : 5.6 M

                Repo        : installed

                From repo   : base

                Summary     : Powerful interactive shell

                URL         : http://zsh.sourceforge.net/

                License     : MIT

                Description : The zsh shell is a command interpreter usable as an interactive login

                            : shell and as a shell script command processor.  Zsh resembles the ksh

                            : shell (the Korn shell), but includes many enhancements.  Zsh supports

                            : command line editing, built-in spelling correction, programmable

                            : command completion, shell functions (with autoloading), a history

                            : mechanism, and more.

                [root@localhost cd-rom]# 

        查看指定的特性(可以是某文件)是由哪个程序包所提供

                yum provides|whatprovides package

                [root@localhost cd-rom]# yum provides zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                zsh-5.0.2-34.el7_8.2.x86_64 : Powerful interactive shell

                Repo        : base

                zsh-5.0.2-34.el7_8.2.x86_64 : Powerful interactive shell

                Repo        : @base

                [root@localhost cd-rom]# yum whatprovides zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.ustc.edu.cn

                zsh-5.0.2-34.el7_8.2.x86_64 : Powerful interactive shell

                Repo        : base

                zsh-5.0.2-34.el7_8.2.x86_64 : Powerful interactive shell

                Repo        : @base

                [root@localhost cd-rom]# 

        清理本地缓存

                yum clean all|packages|metadate…

                [root@localhost cd-rom]# yum clean all

                Loaded plugins: fastestmirror, langpacks

                Cleaning repos: 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

                [root@localhost cd-rom]# yum clean zsh

                Loaded plugins: fastestmirror, langpacks

                Error: invalid clean argument: ‘zsh’

                 Mini usage:

                clean [headers|packages|metadata|dbcache|plugins|expire-cache|all]

                Remove cached data

                [root@localhost cd-rom]# yum clean packages 

                Loaded plugins: fastestmirror, langpacks

                Cleaning repos: base extras updates

                0 package files removed

                [root@localhost cd-rom]# 

        构建缓存

                yum makecache

                [root@localhost cd-rom]# yum makecache

                Loaded plugins: fastestmirror, langpacks

                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/primary_db                                             | 6.1 MB  00:00:00     

                (2/10): base/7/x86_64/group_gz                                               | 153 kB  00:00:01     

                (3/10): extras/7/x86_64/filelists_db                                         | 235 kB  00:00:00     

                (4/10): updates/7/x86_64/filelists_db                                        | 5.5 MB  00:00:00     

                (5/10): updates/7/x86_64/primary_db                                          | 9.5 MB  00:00:00     

                (6/10): extras/7/x86_64/primary_db                                           | 242 kB  00:00:00     

                (7/10): updates/7/x86_64/other_db                                            | 681 kB  00:00:00     

                (8/10): extras/7/x86_64/other_db                                             | 143 kB  00:00:01     

                (9/10): base/7/x86_64/other_db                                               | 2.6 MB  00:00:03     

                (10/10): base/7/x86_64/filelists_db                                          | 7.2 MB  00:00:07     

                Determining fastest mirrors

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.163.com

                Metadata Cache Created

                [root@localhost cd-rom]# 

        搜索

                yum search string

                以指定的关键字搜索程序包名及summary信息

                [root@localhost cd-rom]# yum search zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.163.com

                ========================================= N/S matched: zsh =========================================

                zsh-html.x86_64 : Zsh shell manual in html format

                zsh.x86_64 : Powerful interactive shell

                  Name and summary matches only, use “search all” for everything.

                [root@localhost cd-rom]# 

        查看指定报名所依赖的compabilities;

                yum deplist package

                [root@localhost cd-rom]# yum deplist zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.163.com

                package: zsh.x86_64 5.0.2-34.el7_8.2

                  dependency: /bin/sh

                   provider: bash.x86_64 4.2.46-34.el7

                  dependency: /sbin/install-info

                   provider: info.x86_64 5.1-5.el7

                  dependency: coreutils

                   provider: coreutils.x86_64 8.22-24.el7_9.2

                  dependency: grep

                   provider: grep.x86_64 2.20-3.el7

                  dependency: libc.so.6(GLIBC_2.15)(64bit)

                   provider: glibc.x86_64 2.17-324.el7_9

                  dependency: libdl.so.2()(64bit)

                   provider: glibc.x86_64 2.17-324.el7_9

                  dependency: libdl.so.2(GLIBC_2.2.5)(64bit)

                   provider: glibc.x86_64 2.17-324.el7_9

                  dependency: libm.so.6()(64bit)

                   provider: glibc.x86_64 2.17-324.el7_9

                  dependency: libm.so.6(GLIBC_2.2.5)(64bit)

                   provider: glibc.x86_64 2.17-324.el7_9

                  dependency: libncursesw.so.5()(64bit)

                   provider: ncurses-libs.x86_64 5.9-14.20130511.el7_4

                  dependency: librt.so.1()(64bit)

                   provider: glibc.x86_64 2.17-324.el7_9

                  dependency: librt.so.1(GLIBC_2.2.5)(64bit)

                   provider: glibc.x86_64 2.17-324.el7_9

                  dependency: libtinfo.so.5()(64bit)

                   provider: ncurses-libs.x86_64 5.9-14.20130511.el7_4

                  dependency: rtld(GNU_HASH)

                   provider: glibc.x86_64 2.17-324.el7_9

                   provider: glibc.i686 2.17-324.el7_9

                [root@localhost cd-rom]# 

        查看yum事务历史

                yum history

                [root@localhost cd-rom]# yum history 

                Loaded plugins: fastestmirror, langpacks

                ID     | Login user               | Date and time    | Action(s)      | Altered

                ——————————————————————————-

                     9 | root <root>              | 2021-08-02 23:39 | Install        |    1   

                     8 | root <root>              | 2021-08-02 23:38 | Erase          |    1   

                     7 | root <root>              | 2021-08-02 23:35 | Install        |    1   

                     6 | root <root>              | 2021-08-02 23:35 | Erase          |    1 E<

                     5 |  <oracle>                | 2021-05-26 00:05 | Install        |    1 > 

                     4 |  <oracle>                | 2021-05-25 23:48 | Install        |    1   

                     3 |  <oracle>                | 2021-05-25 22:58 | I, U           |   11   

                     2 | daniel <daniel>          | 2021-05-25 22:26 | I, U           |   41 EE

                     1 | System <unset>           | 2021-05-19 21:06 | Install        | 1255   

                history list

                [root@localhost cd-rom]# 

        安装及升级本地程序包

                yum localinstall rpmfile

                yum localupdate rpmfile

                [root@localhost cd-rom]# yum localinstall ./Packages/zsh-5.0.2-28.el7.x86_64.rpm 

                Loaded plugins: fastestmirror, langpacks

                Examining ./Packages/zsh-5.0.2-28.el7.x86_64.rpm: zsh-5.0.2-28.el7.x86_64

                Marking ./Packages/zsh-5.0.2-28.el7.x86_64.rpm to be installed

                Resolving Dependencies

                –> Running transaction check

                —> Package zsh.x86_64 0:5.0.2-28.el7 will be installed

                –> Finished Dependency Resolution

                Dependencies Resolved

                ====================================================================================================

                 Package        Arch              Version                 Repository                           Size

                ====================================================================================================

                Installing:

                 zsh            x86_64            5.0.2-28.el7            /zsh-5.0.2-28.el7.x86_64            5.6 M

                Transaction Summary

                ====================================================================================================

                Install  1 Package

                Total size: 5.6 M

                Installed size: 5.6 M

                Is this ok [y/d/N]: y

                Downloading packages:

                Running transaction check

                Running transaction test

                Transaction test succeeded

                Running transaction

                  Installing : zsh-5.0.2-28.el7.x86_64                                                          1/1 

                  Verifying  : zsh-5.0.2-28.el7.x86_64                                                          1/1 

                Installed:

                  zsh.x86_64 0:5.0.2-28.el7                                                                         

                Complete!

                [root@localhost cd-rom]# 

        包组管理的相关命令

                groupinstall

                groupupdate

                grouplist

                groupremove

                groupinfo

                [root@localhost cd-rom]# yum grouplist

                Loaded plugins: fastestmirror, langpacks

                There is no installed groups file.

                Maybe run: yum groups mark convert (see man yum)

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.163.com

                Available Environment Groups:

                   Minimal Install

                   Compute Node

                   Infrastructure Server

                   File and Print Server

                   Basic Web Server

                   Virtualization Host

                   Server with GUI

                   GNOME Desktop

                   KDE Plasma Workspaces

                   Development and Creative Workstation

                Available Groups:

                   Compatibility Libraries

                   Console Internet Tools

                   Development Tools

                   Graphical Administration Tools

                   Legacy UNIX Compatibility

                   Scientific Support

                   Security Tools

                   Smart Card Support

                   System Administration Tools

                   System Management

                Done

                [root@localhost cd-rom]# yum groupinstall “Basic Web Server”

                Loaded plugins: fastestmirror, langpacks

                There is no installed groups file.

                Maybe run: yum groups mark convert (see man yum)

                Loading mirror speeds from cached hostfile

                 * base: mirrors.cn99.com

                 * extras: mirrors.cn99.com

                 * updates: mirrors.163.com

                Resolving Dependencies

                –> Running transaction check

                —> Package bpftool.x86_64 0:3.10.0-1160.36.2.el7 will be installed

                —> Package crypto-utils.x86_64 0:2.4.1-42.el7 will be installed

                –> Processing Dependency: perl(Newt) for package: crypto-utils-2.4.1-42.el7.x86_64

                –> Processing Dependency: kernel(___ratelimit) = 0x155f4108 for package: kmod-kvdo-6.1.3.23-5.el7.x86_64

                –> Processing Dependency: kernel >= 3.10.0-1133.el7 for package: kmod-kvdo-6.1.3.23-5.el7.x86_64

                —> Package lshw.x86_64 0:B.02.18-17.el7 will be installed

                —> Package mod_fcgid.x86_64 0:2.3.9-6.el7 will be installed

                —> Package libselinux-utils.x86_64 0:2.5-15.el7 will be an update

                –> Processing Dependency: libselinux(x86-64) = 2.5-15.el7 for package: libselinux-utils-2.5-15.el7.x86_64

                —> Package libsemanage.x86_64 0:2.5-8.el7 will be updated

                –> Processing Dependency: libsemanage = 2.5-8.el7 for package: libsemanage-python-2.5-11.el7.x86_64

                —> Package libselinux.x86_64 0:2.5-15.el7 will be an update

                —> Package libsemanage-python.x86_64 0:2.5-8.el7 will be updated

                —> Package libsemanage-python.x86_64 0:2.5-14.el7 will be an update

                —> Package setools-libs.x86_64 0:3.3.8-1.1.el7 will be updated

                —> Package setools-libs.x86_64 0:3.3.8-4.el7 will be an update

                –> Running transaction check

                —> Package libselinux-python.x86_64 0:2.5-11.el7 will be updated

                —> Package libselinux-python.x86_64 0:2.5-15.el7 will be an update

                –> Finished Dependency Resolution

                Dependencies Resolved

                ====================================================================================================

                 Package                       Arch         Version                             Repository     Size

                ====================================================================================================

                64       2.4.6-97.el7.centos                 updates        93 k

                 libyaml                       x86_64       0.1.4-11.el7_0                      base           55 k

                 mailcap                       noarch       2.1.41-2.el7                        base           31 k

                 perl-Newt                     x86_64       1.08-36.el7                         base           64 k

                Updating for dependencies:

                 libselinux                    x86_64       2.5-15.el7                          base          162 k

                 libselinux-python             x86_64       2.5-15.el7                          base          236 k

                 libselinux-utils              x86_64       2.5-15.el7                          base          151 k

                 libsemanage                   x86_64       2.5-14.el7                          base          151 k

                 libsemanage-python            x86_64       2.5-14.el7                          base          113 k

                 libsepol                      x86_64       2.5-10.el7                          base          297 k

                 linux-firmware                noarch       20200421-80.git78c0348.el7_9        updates        80 M

                 policycoreutils               x86_64       2.5-34.el7                          base          917 k

                 policycoreutils-python        x86_64       2.5-34.el7                          base          457 k

                 python                        x86_64       2.7.5-90.el7                        updates        96 k

                 python-libs                   x86_64       2.7.5-90.el7                        updates       5.6 M

                 selinux-policy                noarch       3.13.1-268.el7_9.2                  updates       498 k

                 setools-libs                  x86_64       3.3.8-4.el7                         base          620 k

                 sg3_utils-libs                x86_64       1:1.37-19.el7                       base           65 k

                Transaction Summary

                ====================================================================================================

                Install  11 Packages (+ 7 Dependent packages)

                Upgrade   1 Package  (+14 Dependent packages)

                Total download size: 162 M

                Is this ok [y/d/N]: 

32.3 本地yum仓库配置

        1、如何使用光盘当作本地yum仓库:

                (1)挂载光盘至某目录,例如/media/cdrom

                        [root@localhost /]# mkdir /media/cdrom

                        [root@localhost /]# mount -r -t iso9660 /dev/cdrom /media/cdrom

                (2)创建配置文件

                        [base]

                        name=CentOSlocal

                        #mirrorlist=file:///opt/yum.repo/

                        baseurl=file:///media/cdrom

                        gpgcheck=1

                        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

        2、yum的命令行选项

                –nogpgcheck:禁止进行gpg check

                –y:自动回复yes

                –q:静默模式

                –disablerepo=repoidglob:临时禁用此处指定的repo;

                –enablerepo=repoidglob:临时禁用此处指定的repo;

                –noplugins:禁用所有插件

        3、yum的repo配置文件中可用的变量

                $releasesever:当前OS的发行版的主版本号

                $arch:平台

                $basearch:基础平台

                $YUM0-$YUM9

        4、创建yum仓库

                createrepo [options] <directory>

                repo格式

                        [base]

                        name=CentOS-$releasever – test

                        #mirrorlist=file:///opt/yum.repo

                        baseurl=file:///opt/yum.repo

                        gpgcheck=1

                        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

                [root@localhost yum.repo]# createrepo /opt/yum.repo/

                Spawning worker 0 with 974 pkgs

                Spawning worker 1 with 974 pkgs

                Spawning worker 2 with 973 pkgs

                Spawning worker 3 with 973 pkgs

                Workers Finished

                Saving Primary metadata

                Saving file lists metadata

                Saving other metadata

                Generating sqlite DBs

                Sqlite DBs complete

                [root@localhost yum.repo]# yum clean all

                Loaded plugins: fastestmirror, langpacks

                Cleaning repos: base

                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

                [root@localhost yum.repo]# rm -rf /var/cache/yum

                [root@localhost yum.repo]# vim /etc/yum.repos.d/CentOS-Base.repo 

                [root@localhost yum.repo]# yum repolist 

                Loaded plugins: fastestmirror, langpacks

                base                                                                                                                                    | 2.9 kB  00:00:00     

                base/primary_db                                                                                                                         | 3.0 MB  00:00:00     

                Determining fastest mirrors

                repo id                                                                 repo name                                                                        status

                base                                                                    CentOS-7 – test                                                                  3,894

                repolist: 3,894

                [root@localhost yum.repo]# ll /opt/yum.repo/ | wc -l

                3897

                [root@localhost yum.repo]# yum install z

                zenity-3.22.0-1.el7.x86_64.rpm      zlib-devel-1.2.7-17.el7.x86_64.rpm  zsh.x86_64                          

                zip-3.0-11.el7.x86_64.rpm           zlib-devel.x86_64                   zziplib-0.13.62-5.el7.x86_64.rpm    

                zlib-1.2.7-17.el7.x86_64.rpm        zsh-5.0.2-28.el7.x86_64.rpm         zziplib.x86_64                      

                [root@localhost yum.repo]# yum install z

                zenity-3.22.0-1.el7.x86_64.rpm      zlib-devel-1.2.7-17.el7.x86_64.rpm  zsh.x86_64                          

                zip-3.0-11.el7.x86_64.rpm           zlib-devel.x86_64                   zziplib-0.13.62-5.el7.x86_64.rpm    

                zlib-1.2.7-17.el7.x86_64.rpm        zsh-5.0.2-28.el7.x86_64.rpm         zziplib.x86_64                      

                [root@localhost yum.repo]# yum install zsh

                Loaded plugins: fastestmirror, langpacks

                Loading mirror speeds from cached hostfile

                Resolving Dependencies

                –> Running transaction check

                —> Package zsh.x86_64 0:5.0.2-28.el7 will be installed

                –> Finished Dependency Resolution

                Dependencies Resolved

                ===============================================================================================================================================================

                 Package                           Arch                                 Version                                       Repository                          Size

                ===============================================================================================================================================================

                Installing:

                 zsh                               x86_64                               5.0.2-28.el7                                  base                               2.4 M

                Transaction Summary

                ===============================================================================================================================================================

                Install  1 Package

                Total download size: 2.4 M

                Installed size: 5.6 M

                Is this ok [y/d/N]: y

                Downloading packages:

                Running transaction check

                Running transaction test

                Transaction test succeeded

                Running transaction

                  Installing : zsh-5.0.2-28.el7.x86_64                                                                                                                     1/1 

                  Verifying  : zsh-5.0.2-28.el7.x86_64                                                                                                                     1/1 

                Installed:

                  zsh.x86_64 0:5.0.2-28.el7                                                                                                                                    

                Complete!

                [root@localhost yum.repo]# yum list | grep zsh

                zsh.x86_64                              5.0.2-28.el7                   @base    

                [root@localhost yum.repo]# 

31、程序包管理之二-rpm

31.1 Centos系统上使用rpm管理安装包

安装,卸载,更新,查询,校验,数据库维护

31.1.1 安装:

        rpm {-i|–install} [install options] package

                -v:verbos

                -vv:显示更多的详细信息

                -h:以#显示程序包管理执行进度,每#表示2%的进度

        rpm -ivh packagefile

                [install-option]

                        –test:测试安装,但不真正执行安装过程

                        –nodeps:忽略依赖关系

                        –replacepkgs:重新安装

                        –nosignature:不检查来源合法性

                        –nodigest:不检查包完整性;

                        –noscripts:不执行程序包脚本片段preun

                                %pre:安装前脚本      –nopre

                                %post:安装后脚本    –nopost1

                                %preun:卸载前脚本 –nopreun

                                %postun:卸载后脚本–nopostun

        [root@localhost ~]# rpm -qa | grep zsh

        [root@localhost ~]# cd /media/cd-rom/Packages/

        [root@localhost Packages]# rpm -ivh zsh-5.0.2-28.el7.x86_64.rpm –test

        Preparing…                          ################################# [

        [root@localhost Packages]# rpm -ivh zsh-5.0.2-28.el7.x86_64.rpm

        Preparing…                          ################################# [100%]

        Updating / installing…

           1:zsh-5.0.2-28.el7                 ################################# [100%]

        [root@localhost Packages]# rpm -ivh zsh-5.0.2-28.el7.x86_64.rpm –replace

        –replacefiles  –replacepkgs   

        [root@localhost Packages]# rpm -ivh zsh-5.0.2-28.el7.x86_64.rpm –replace

        –replacefiles  –replacepkgs   

        [root@localhost Packages]# rpm -ivh zsh-5.0.2-28.el7.x86_64.rpm –replacepkgs 

        Preparing…                          ################################# [100%]

        Updating / installing…

           1:zsh-5.0.2-28.el7                 ################################# [100%]

        [root@localhost Packages]# 

31.1.2 升级

        rpm {-U|–upgrade} [install options] package

        rpm {-F|–freshen} [install options] package

        upgrade:安装有旧版程序包,则升级;如果不存在旧版程序包,则安装

        freeshen:安装有旧版程序包,则升级;如果不存在旧版程序包,则不执行

        rpm -Uvh package

        rpm -fvh package

        –oldpackage:降级

        –force:强行升级

        [root@localhost Packages]# rpm -Uvh zsh-5.0.2-28.el7.x86_64.rpm

        Preparing…                          ################################# [100%]

            package zsh-5.0.2-28.el7.x86_64 is already installed

        [root@localhost Packages]# rpm -Fvh zsh-5.0.2-28.el7.x86_64.rpm

        [root@localhost Packages]# rpm -e zsh 

        [root@localhost Packages]# rpm -Fvh zsh-5.0.2-28.el7.x86_64.rpm

        [root@localhost Packages]# rpm -Uvh zsh-5.0.2-28.el7.x86_64.rpm

        Preparing…                          ################################# [100%]

        Updating / installing…

           1:zsh-5.0.2-28.el7                 ################################# [100%]

        [root@localhost Packages]# rpm -Uvh zsh-5.0.2-28.el7.x86_64.rpm –force

        Preparing…                          ################################# [100%]

        Updating / installing…

           1:zsh-5.0.2-28.el7                 ################################# [100%]

        [root@localhost Packages]# 

注意:(1)不要对内核做升级操作;linux支持多内核版本并存,因此直接安装新版本内核即可

        (2)如果对元程序包的配置文件安装后曾被修改,升级时,新版本提供的配置文件并不会直接覆盖旧版本的配置文件,而是把新版本的文件重命名后保存(filename.rpmnew)

31.1.3 查询

        rpm {-q|–query} [select options] [quire options]

                [select options]

                        -a:所有包

                        -f:查看指定文件由那个程序包安装生成

                        -p /PATH/TO/PACKAGE:针对尚未安装的程序文件做查询操作

                        –whatprovides CAPABILITY:查询指定的CAPABILITY由哪个包所提供

                        –whatrequires CAPABILITY:查询指定的CAPABILITY被哪个包所依赖

                [quire options]

                        –changelog:查询rpm包的changelog

                        -c:查询程序的配置文件

                        -d:查询程序的文档

                        -i:information

                        -l:查看指定程序包安装后生成的所有文件

                        –scripts:查看程序包自带的脚本片段

                        -R:查询指定的程序包所依赖的CAPABILITY

                        –provides:列出指定程序包所提供的CAPABILITY

        用法:

                -qi PACKAGE,-qc PACKAGE,-ql PACKAGE,-qd PACKAGE,

                -qf FILE,

                -qpi PACKAGE_FILE,-qpl PACKAGE_FILE,…

                -qa

        [root@localhost Packages]# rpm -qf zsh 

        error: file /media/cd-rom/Packages/zsh: No such file or directory

        [root@localhost Packages]# rpm -qi zsh 

        Name        : zsh

        Version     : 5.0.2

        Release     : 28.el7

        Architecture: x86_64

        Install Date: Mon 02 Aug 2021 11:11:00 PM EDT

        Group       : System Environment/Shells

        Size        : 5855982

        License     : MIT

        Signature   : RSA/SHA256, Thu 10 Aug 2017 04:28:17 PM EDT, Key ID 24c6a8a7f4a80eb5

        Source RPM  : zsh-5.0.2-28.el7.src.rpm

        Build Date  : Wed 02 Aug 2017 06:52:37 AM EDT

        Build Host  : c1bm.rdu2.centos.org

        Relocations : (not relocatable)

        Packager    : CentOS BuildSystem <http://bugs.centos.org>

        Vendor      : CentOS

        URL         : http://zsh.sourceforge.net/

        Summary     : Powerful interactive shell

        Description :

        The zsh shell is a command interpreter usable as an interactive login

        shell and as a shell script command processor.  Zsh resembles the ksh

        shell (the Korn shell), but includes many enhancements.  Zsh supports

        command line editing, built-in spelling correction, programmable

        command completion, shell functions (with autoloading), a history

        mechanism, and more.

        [root@localhost Packages]# rpm -qf /bin/zsh 

        zsh-5.0.2-28.el7.x86_64

        [root@localhost Packages]# rpm -qpi zsh-5.0.2-28.el7.x86_64.rpm 

        Name        : zsh

        Version     : 5.0.2

        Release     : 28.el7

        Architecture: x86_64

        Install Date: (not installed)

        Group       : System Environment/Shells

        Size        : 5855982

        License     : MIT

        Signature   : RSA/SHA256, Thu 10 Aug 2017 04:28:17 PM EDT, Key ID 24c6a8a7f4a80eb5

        Source RPM  : zsh-5.0.2-28.el7.src.rpm

        Build Date  : Wed 02 Aug 2017 06:52:37 AM EDT

        Build Host  : c1bm.rdu2.centos.org

        Relocations : (not relocatable)

        Packager    : CentOS BuildSystem <http://bugs.centos.org>

        Vendor      : CentOS

        URL         : http://zsh.sourceforge.net/

        Summary     : Powerful interactive shell

        Description :

        The zsh shell is a command interpreter usable as an interactive login

        shell and as a shell script command processor.  Zsh resembles the ksh

        shell (the Korn shell), but includes many enhancements.  Zsh supports

        command line editing, built-in spelling correction, programmable

        command completion, shell functions (with autoloading), a history

        mechanism, and more.

        [root@localhost Packages]# rpm -qa | head -3

        cups-pk-helper-0.2.6-2.el7.x86_64

        teamd-1.25-5.el7.x86_64

        ipxe-roms-qemu-20170123-1.git4e85b27.el7.noarch

        [root@localhost Packages]# 

31.1.4 卸载:

        rpm {-e|–erase} PACKAGE_NAME

        [root@localhost Packages]# rpm -e zsh 

        [root@localhost Packages]# rpm -qa | grep zsh

        [root@localhost Packages]# 

31.1.5 检验:

rpm {-V|–verify} [select-options] [verify-options]

        S file Size differs

        M Mode differs (includes permissions and file type)

        5 digest (formerly MD5 sum) differs

        D Device major/minor number mismatch

        L readLink(2) path mismatch

        U User ownership differs

        G Group ownership differs

        T mTime differs

        P caPabilities differ

[root@localhost Packages]# vim /usr/share/doc/zsh-5.0.2/MACHINES

[root@localhost Packages]# rpm -V zsh 

S.5….T.  d /usr/share/doc/zsh-5.0.2/MACHINES

missing   d /usr/share/man/man1/zshzle.1.gz

[root@localhost Packages]# 

31.1.6 包来源合法性及完整性验证

        完整性验证:SHA256

        来源合法性验证:RSA

         数据加密方法:

                (1)对称加密:加密和解密使用同一个密码

                (2)公钥加密(非对称加密):每个密码都成对儿出现,一个为私钥(secret key),一个为公钥(public key),一个用来加密,一个用来解密

                (3)单向加密,散列加密(可以由明文取得密文,但不能由密文取得明文):提取数据特征码,常用于数据完整性校验

            单向加密特点

                雪崩效应(蝴蝶效应):初始条件的微小改变会引起结果的巨大改变

                [root@Daniel-R480 ~]# cp /etc/inittab ./

                [root@Daniel-R480 ~]# md5sum inittab

                66a88d6c4d693170753ea3382f8bc150  inittab

                [root@Daniel-R480 ~]# vim inittab

                -bash: vim: command not found

                [root@Daniel-R480 ~]# vi inittab

                [root@Daniel-R480 ~]# md5sum inittab

                568c018aebe36cf208fc32c465e4b120  inittab

                定长输出

                    MD5:Message Digest, 128位定长输出

                    SHA1:Secure Hash Algorithm, 160位定长输出

                密码前面一般会有加上的杂质(salt),防止相同用户的密码显示的密文相同

31.1.7 导入所需要的公钥

        rpm -import /PATH/FROM/GPG-PUBKEY-FILE

        CentOS 7 发行版光盘提供的密钥文件:RPM-GPG-KEY-CentOS-7

        [root@localhost cd-rom]# rpm -import RPM-GPG-KEY-CentOS-7

        [root@localhost cd-rom]#

31.1.8 数据库重建

        rpm {–initdb|–rebuilddb}

                initdb:初始化

                        如果事先不存在数据库则新建之,否则,不执行任何操作

                rebuilddb:重建

                        无论当前存在与否,直接重新创建数据库;

        [root@localhost cd-rom]# rpm –initdb

        [root@localhost cd-rom]# rpm –rebuilddb 

        [root@localhost cd-rom]# 

30、程序包管理之一-程序及库简介

30.1 程序及库简介

30.1.1 POSIX

        API:Application Program Interface

        POSIX:Portable OS,定义了不同系统如何提供统一的API

30.1.2 程序运行流程

        程序源代码à预处理à编译à汇编à链接

                静态编译

                共享编译:.so

30.1.3 Windows和Linux程序兼容方式

        ABI:Application Binary Interface

                Windows与Linux的ABI不兼容

        库级别的虚拟化

                WINE:Windows库的虚拟化,让Windows程序可在Linux上运行

                cywin:Linux库的虚拟化,让Linux程序可在Windows上运行

30.1.4 应用程序开发

        系统级开发(面向底层进行开发)

                C,C++

        应用级开发(面向系统和库进行开发)

                java,python,phpdeb,perl,ruby

        二进制应用程序的组成部分:

                二进制文件,库文件,配置文件,帮助文件

30.2程序包管理

30.2.1 程序包管理器:

        debian:包名deb,包管理器dpt

        redhat:包名rpm,包管理器rpm(Redhat Package Manager)

                RPM is Package Manager(C语言研发)

        Gentoo

        Archlinux

30.2.2 程序源代码及rpm包

1、程序源代码:name-VERSION.tar.gz

        VERSION:major.monor.release

2、rpm包

        命名方式

                name-VERSION-ARCH.rpm

                        VERSION:major.monor.release

                        ARCH:release(rpm包的release).os(支持的linux型号).arch(支持的cpu型号)

                常见的arch:

                        x86:i386,i486,i586,i686

                        x86_64:x64,x86_64,amd64

                        powerpc:ppc

                        跟平台无关:noarch

        例:zlib-1.2.7-17.el7.x86_64.rpm

        程序包拆包

                testapp:

                        testapp-VERSION-ARCH.rpm:主包

                        testapp-devel-VERSION-RACH.rpm:支包

                        testapp-testing-VERSION-RACH.rpm

        依赖关系

                X依赖Y,Y依赖Z

        ldd + 程序:查看二进制程序的依赖关系

    [root@localhost ~]# ldd /bin/ls

        linux-vdso.so.1 =>  (0x00007fffb09b7000)

        libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f69482d3000)

        libcap.so.2 => /lib64/libcap.so.2 (0x00007f69480ce000)

        libacl.so.1 => /lib64/libacl.so.1 (0x00007f6947ec4000)

        libc.so.6 => /lib64/libc.so.6 (0x00007f6947af6000)

        libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f6947894000)

        libdl.so.2 => /lib64/libdl.so.2 (0x00007f694768f000)

        /lib64/ld-linux-x86-64.so.2 (0x000055807796f000)

        libattr.so.1 => /lib64/libattr.so.1 (0x00007f694748a000)

        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f694726e000)

        [root@localhost ~]# 

        管理及查看本机装载的库文件:

        ldconfig

                /sbin/ldconfig -p:显示本机已经缓存的所有可用库文件及文件路径映射

                配置文件为:/etc/ld.so.conf,/etc/ld.so.conf.d/*.conf

                缓存文件:/etc/ld.so.cache

        [root@localhost ~]# ldconfig -p | head -10

        1095 libs found in cache /etc/ld.so.cache

            p11-kit-trust.so (libc6,x86-64) => /lib64/p11-kit-trust.so

            libz.so.1 (libc6,x86-64) => /lib64/libz.so.1

            libyelp.so.0 (libc6,x86-64) => /lib64/libyelp.so.0

            libyajl.so.2 (libc6,x86-64) => /lib64/libyajl.so.2

            libxtables.so.10 (libc6,x86-64) => /lib64/libxtables.so.10

            libxslt.so.1 (libc6,x86-64) => /lib64/libxslt.so.1

            libxshmfence.so.1 (libc6,x86-64) => /lib64/libxshmfence.so.1

            libxml2.so.2 (libc6,x86-64) => /lib64/libxml2.so.2

            libxmlsec1.so.1 (libc6,x86-64) => /lib64/libxmlsec1.so.1

                [root@localhost ~]# 

30.2.3 包管理器的前端工具

        yum:rpm包管理器的前端工具,用于解决依赖关系,自动下载所需要的程序及其依赖包

        apt-get:deb包管理器前端工具

        zypper:suse上的rpm前端管理工具

        dnf:Fedora 22+ rpm包管理器的前端管理工具

30.2.4 程序包管理

        程序包管理:

                功能:将编译好的应用程序的各组成文件打包成一个或几个程序文件,从而方便快捷的实现程序的安装,卸载,查询,升级,校验等管理操作

                1、程序的组成清单(每个包独有)

                        文件清单

                        安装或卸载时运行的脚本

                2、数据库(公共)

                        程序包名称及版本

                        依赖关系;

                        功能说明;

                        安装生成的各文件的文件路径及校验码信息

        管理程序包的方式:

                使用包管理器:rpm

                使用前端工具:yum,dnf

        获取程序包的路径:

                1、系统发行版的光盘或者是官方的服务器

                CentOS镜像:

                        http://mirrors.aliyun.com

                        http://mirrors.sohu.com

                        http://mirrors.163.com

                2、项目官方站点

                3、第三方组织:

                        Fedora-EPEL

                        搜索引擎:

                                http://pkgs.org

                                http://rpmfind.net

                                http://rpm.pgone.net

                4、自己制作

        建议:检查其合法性

                来源合法性;程序包的完整性;

29、btrfs文件系统简介

29.1 Btrfs(B-tree,Butter FS,Better FS)

GPL,Oracle,2007,CoW;ext3/ext4,xfs

1、核心特性:

多物理卷支持:btrfs可由多个底层物理卷组成;支持RAID,以”联机添加“,“移除”,“修改”;

写时复制更新机制(CoW):复制、更新及替换指针,而非“就地”更新

数据及元数据校验码:checksum

子卷:sub_volume

快照:支持快照的快照

透明压缩

2、文件系统创建:

mkfs.btrfs

-L ‘LABEL’

-d <type>: raid0.raid1,raid5,raid6,raid10,single

-m <profile>:raid0,raid1,raid5,raid6,raid10,single,dup

属性查看:

btrfs filesystem show

挂载文件系统:

mount -t btrfs /dev/sdb MOUNT_POINT

透明压缩机制:

mount -o compress={lzo|zlib} DEVICE MOUNT_POINT

3、子命令:filesystem,device,balance,subvolume

btrfs-convert:将ext文件系统转换为btrfs或者将btrfs转换为ext文件系统

28、LVM2详解及until

28.1 LVM

Logical Volume Manager,Version: 2

28.1.1 DM和MD

cat /proc/filesystems : 查看当前内核所支持文件系统类型

RAID: 独立冗余磁盘阵列

Linux:硬件,软件

/dev/md#

Linux中两种不同的设备类型

MD: Multi Device, 多设备

MD, DM

/dev/md#

meta device

DM: Device Mapper,将一个或多个底层块设备组织成一个逻辑设备的模块

逻辑设备

RAID, LVM2(逻辑卷)

DM: 通常用于LVM2

/dev/dm-#

组件:

快照:将要改变的数据进行备份,实现数据的备份(数据备份:避免因为误操作或者文件删除的情况造成的损失)

多路径

物理卷(PE)-》卷组(VG)-》逻辑卷(LE)

28.2 PV,VG管理

28.2.1 PV管理工具

pvs:简要pv信息展示

pvdisplay:显示pv的详细信息

pvcreate /dev/DEVICE:创建PV

-v 显示创建过程

pvmove:pv移除,在vgreduce之前要先移除

[root@localhost ~]# pvs

  /dev/md0: read failed after 0 of 4096 at 0: Input/output error

  PV         VG     Fmt  Attr PSize   PFree

  /dev/sdb2  centos lvm2 a–  <99.00g 4.00m

[root@localhost ~]# pvdisplay

  /dev/md0: read failed after 0 of 4096 at 0: Input/output error

  — Physical volume —

  PV Name               /dev/sdb2

  VG Name               centos

  PV Size               <99.00 GiB / not usable 3.00 MiB

  Allocatable           yes 

  PE Size               4.00 MiB

  Total PE              25343

  Free PE               1

  Allocated PE          25342

  PV UUID               0R0BFP-witm-SfMZ-d9an-26rT-JDtg-XzwGqy

[root@localhost ~]# 

28.2.2 VG管理工具

vgcreate VG_NAME /PATH/TO/PV:创建vg

-v 显示过程

-s #: PE大小,默认为4MB

vgs:简要vg信息展示

vgdisplay:显示pv的详细信息

vgextend:扩展

vgreduce:vg缩减

vgremove:删除vg

28.3 lv逻辑卷配置

28.3.1 LV管理工具

lvs:简要lv信息展示

lvdisplay:显示lv的详细信息

lvcreate -n LV_NAME -L #[mMgGtT] VG_NAME:创建lv

-n:指明逻辑卷名称

-L:指定大小

-l:指定逻辑盘区的数量

lvremove:删除逻辑卷

创建分区:创建物理边界

创建文件系统:创建逻辑边界(紧贴着物理边界)

28.3.2 扩展逻辑卷;

lvextend:扩展逻辑卷物理边界

-L [+]#[mMgGtT] /dev/VG_NAME/LV_NAME

+可带可不带,不带的话代表的是扩展的目标大小

resize2fs:扩展文件系统边界(不指定大小则为使用分区所有大小)

resize2fs -p /PATH/TO/LV

28.3.3 缩减逻辑卷;

注意:1、不能在线缩减,必须先卸载;

  2、确保缩减后的空间大小依然能存储原有的所有数据;

  3、在缩减之前应该先强行检查文件,以确保文件系统处于一至性状态;

操作过程:

df -lh

umount

e2fsck -f         

resize2fs:缩减文件系统边界

resize2fs /PATH/TO/PV 3G

lvreduce -L [-]# /PATH/TO/LV(缩减逻辑卷物理边界)

mount重新挂载

[root@localhost ~]# umount /test

[root@localhost ~]# mount /test

mount: cant find /test in /etc/fstab

[root@localhost ~]# mount /dev/mypv/mvvg /test

mount: special device /dev/mypv/mvvg does not exist

[root@localhost ~]# mount /dev/mypv/myvg /test

mount: special device /dev/mypv/myvg does not exist

[root@localhost ~]# mount /dev/myvg/mylv /test

[root@localhost ~]# resize

resize2fs   resizecons  resizepart  

[root@localhost ~]# resize

resize2fs   resizecons  resizepart  

[root@localhost ~]# resize2fs /dev/myvg/mylv 

resize2fs 1.42.9 (28-Dec-2013)

Filesystem at /dev/myvg/mylv is mounted on /test; on-line resizing required

old_desc_blocks = 16, new_desc_blocks = 40

The filesystem on /dev/myvg/mylv is now 5242880 blocks long.

[root@localhost ~]# df -lh

Filesystem               Size  Used Avail Use% Mounted on

/dev/mapper/centos-root   50G  2.6G   48G   6% /

devtmpfs                 3.9G     0  3.9G   0% /dev

tmpfs                    3.9G     0  3.9G   0% /dev/shm

tmpfs                    3.9G  8.7M  3.9G   1% /run

tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup

/dev/sda1               1014M  143M  872M  15% /boot

/dev/mapper/centos-home   42G   33M   42G   1% /home

tmpfs                    781M     0  781M   0% /run/user/0

/dev/mapper/myvg-mylv    4.9G  3.2M  4.7G   1% /test

[root@localhost ~]# umount /dev/myvg/mylv

[root@localhost ~]# e2fsck -f /dev/myvg/mylv

e2fsck 1.42.9 (28-Dec-2013)

Pass 1: Checking inodes, blocks, and sizes

Pass 2: Checking directory structure

Pass 3: Checking directory connectivity

Pass 4: Checking reference counts

Pass 5: Checking group summary information

MYLV: 12/327680 files (0.0% non-contiguous), 119806/5242880 blocks

[root@localhost ~]# resize2fs /dev/myvg/mylv 3G

resize2fs 1.42.9 (28-Dec-2013)

Resizing the filesystem on /dev/myvg/mylv to 3145728 (1k) blocks.

The filesystem on /dev/myvg/mylv is now 3145728 blocks long.

[root@localhost ~]# lvreduce /dev/myvg/mylv 3G

  No command with matching syntax recognised.  Run ‘lvreduce –help’ for more information.

  Correct command syntax is:

  lvreduce -L|–size [-]Size[m|UNIT] LV

[root@localhost ~]# lvreduce /dev/myvg/mylv -L 3G

  WARNING: Reducing active logical volume to 3.00 GiB.

  THIS MAY DESTROY YOUR DATA (filesystem etc.)

Do you really want to reduce myvg/mylv? [y/n]: y

  Size of logical volume myvg/mylv changed from 5.00 GiB (1280 extents) to 3.00 GiB (768 extents).

  Logical volume myvg/mylv successfully resized.

[root@localhost ~]# mount /dev/myvg/mylv /test

[root@localhost ~]# df -lh

Filesystem               Size  Used Avail Use% Mounted on

/dev/mapper/centos-root   50G  2.6G   48G   6% /

devtmpfs                 3.9G     0  3.9G   0% /dev

tmpfs                    3.9G     0  3.9G   0% /dev/shm

tmpfs                    3.9G  8.7M  3.9G   1% /run

tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup

/dev/sda1               1014M  143M  872M  15% /boot

/dev/mapper/centos-home   42G   33M   42G   1% /home

tmpfs                    781M     0  781M   0% /run/user/0

/dev/mapper/myvg-mylv    3.0G  3.2M  2.8G   1% /test

[root@localhost ~]# 

28.3.4 快照卷(snapshot)

1、生命周期为整个数据时长;在这段时长内,数据的增长量不能超出快照卷大小;

2、快照卷应该是只读的;

3、跟原卷在同一卷组内;

创建过程

lvcreate

-s:创建快照卷

-p r|w:指定权限

lvcreate -L # -n SLV_NAME -p r /PATH/TO/LV

练习1:创建一个至少有两个PV组成的大小为20G的名为testvg的VG,要求PE大小为16MB,而后在卷组中创建大小为5G逻辑卷testlv,挂载至、users目录

[root@localhost ~]# pvcreate /dev/sdc

  Physical volume “/dev/sdc” successfully created.

[root@localhost ~]# pvs

  PV         VG     Fmt  Attr PSize   PFree 

  /dev/sda2  centos lvm2 a–  <99.00g  4.00m

  /dev/sdb          lvm2 —   20.00g 20.00g

  /dev/sdc          lvm2 —   20.00g 20.00g

[root@localhost ~]# vgcreate vg1 -s 16 /dev/sdb

  Volume group “vg1” successfully created

[root@localhost ~]# vgextend vg1 -s 16 /dev/sdc

vgextend: invalid option — ‘s’

  Error during parsing of command line.

[root@localhost ~]# vgextend vg1 /dev/sdc

  Volume group “vg1” successfully extended

[root@localhost ~]# vgdisplay 

  — Volume group —

  VG Name               centos

  System ID             

  Format                lvm2

  Metadata Areas        1

  Metadata Sequence No  4

  VG Access             read/write

  VG Status             resizable

  MAX LV                0

  Cur LV                3

  Open LV               3

  Max PV                0

  Cur PV                1

  Act PV                1

  VG Size               <99.00 GiB

  PE Size               4.00 MiB

  Total PE              25343

  Alloc PE / Size       25342 / 98.99 GiB

  Free  PE / Size       1 / 4.00 MiB

  VG UUID               fE3YOB-nPtn-bYfY-RZX4-moqi-3YMu-6deJXo

  — Volume group —

  VG Name               vg1

  System ID             

  Format                lvm2

  Metadata Areas        2

  Metadata Sequence No  2

  VG Access             read/write

  VG Status             resizable

  MAX LV                0

  Cur LV                0

  Open LV               0

  Max PV                0

  Cur PV                2

  Act PV                2

  VG Size               <39.97 GiB

  PE Size               16.00 MiB

  Total PE              2558

  Alloc PE / Size       0 / 0   

  Free  PE / Size       2558 / <39.97 GiB

  VG UUID               Qf0Sfr-gRzG-vmmJ-7mTK-NUln-LlRj-U2IYJ2

[root@localhost ~]# lvcreate -n testlv -L 5G vg1

WARNING: ext4 signature detected on /dev/vg1/testlv at offset 1080. Wipe it? [y/n]: y

  Wiping ext4 signature on /dev/vg1/testlv.

  Logical volume “testlv” created.

[root@localhost ~]# mkdir /users

[root@localhost ~]# mke2fs -t ext4 /dev/vg1/testlv 

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

327680 inodes, 1310720 blocks

65536 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=1342177280

40 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks: 

    32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done                            

Writing inode tables: done                            

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done 

[root@localhost ~]# mount /dev/vg1/testlv /users

[root@localhost ~]# mount

sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)

proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)

devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=3985976k,nr_inodes=996494,mode=755)

securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)

tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)

devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)

tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)

tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755)

cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)

pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)

cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)

cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)

cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)

cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)

cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)

cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)

cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)

cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)

cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)

cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)

configfs on /sys/kernel/config type configfs (rw,relatime)

/dev/mapper/centos-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)

systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=35,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=10884)

mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)

hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)

debugfs on /sys/kernel/debug type debugfs (rw,relatime)

/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

/dev/mapper/centos-home on /home type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=799408k,mode=700)

/dev/mapper/vg1-testlv on /users type ext4 (rw,relatime,seclabel,data=ordered)

练习2:新建用户archlinux,要求其家目录为/users/archlinux,而后su切换至archlinux用户,复制/etc/pam.d目录至自己的家目录,

[root@localhost ~]# man useradd

[1]+  Stopped                 man useradd

[root@localhost ~]# ls /

bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  test  tmp  users  usr  var

[root@localhost ~]# useradd -b /users archlinux

[root@localhost ~]# su – archlinux 

[archlinux@localhost ~]$ cp -a /etc/pam.d/ ~/

[archlinux@localhost ~]$ ls

pam.d

[archlinux@localhost ~]$ 

练习3:扩展testlv至7G,要求archlinux的文件不能丢失

[archlinux@localhost ~]$ lvextend -L 7G /dev/vg1/testlv

  WARNING: Running as a non-root user. Functionality may be unavailable.

  /run/lvm/lvmetad.socket: access failed: Permission denied

  WARNING: Failed to connect to lvmetad. Falling back to device scanning.

  /dev/mapper/control: open failed: Permission denied

  Failure to communicate with kernel device-mapper driver.

  Incompatible libdevmapper 1.02.140-RHEL7 (2017-05-03) and kernel driver (unknown version).

  /run/lock/lvm/V_vg1:aux: open failed: Permission denied

  Cant get lock for vg1

  Cannot process volume group vg1

[archlinux@localhost ~]$ umount /dev/vg1/testlv

umount: /users: umount failed: Operation not permitted

[archlinux@localhost ~]$ su – root

Password: 

Last login: Tue Jul 27 03:26:48 EDT 2021 from 192.168.77.2 on pts/0

[root@localhost ~]# umount /dev/vg1/testlv

umount: /users: target is busy.

        (In some cases useful info about processes that use

         the device is found by lsof(8) or fuser(1))

[root@localhost ~]# ps -ef | grep archlinux

root       1917   1463  0 04:01 pts/0    00:00:00 su – archlinux

root       1974   1953  0 04:21 pts/0    00:00:00 grep –color=auto archlinux

[root@localhost ~]# exit

logout

[archlinux@localhost ~]$ exit

logout

[root@localhost ~]# ps -ef | grep archlinux

root       1977   1463  0 04:22 pts/0    00:00:00 grep –color=auto archlinux

[root@localhost ~]# umount /dev/vg1/testlv

[root@localhost ~]# lvextend -L 7G /dev/vg1/testlv

  Size of logical volume vg1/testlv changed from 5.00 GiB (320 extents) to 7.00 GiB (448 extents).

  Logical volume vg1/testlv successfully resized.

[root@localhost ~]# resize2fs /dev/vg1/testlv 

resize2fs 1.42.9 (28-Dec-2013)

Please run ‘e2fsck -f /dev/vg1/testlv’ first.

[root@localhost ~]# e2fsck -f /dev/vg1/testlv

e2fsck 1.42.9 (28-Dec-2013)

Pass 1: Checking inodes, blocks, and sizes

Pass 2: Checking directory structure

Pass 3: Checking directory connectivity

Pass 4: Checking reference counts

Pass 5: Checking group summary information

/dev/vg1/testlv: 48/327680 files (0.0% non-contiguous), 58493/1310720 blocks

[root@localhost ~]# resize2fs /dev/vg1/testlv 

resize2fs 1.42.9 (28-Dec-2013)

Resizing the filesystem on /dev/vg1/testlv to 1835008 (4k) blocks.

The filesystem on /dev/vg1/testlv is now 1835008 blocks long.

[root@localhost ~]# mount /dev/vg1/testlv /users/

[root@localhost ~]# df -lh

Filesystem               Size  Used Avail Use% Mounted on

/dev/mapper/centos-root   50G  2.6G   48G   6% /

devtmpfs                 3.9G     0  3.9G   0% /dev

tmpfs                    3.9G     0  3.9G   0% /dev/shm

tmpfs                    3.9G  8.7M  3.9G   1% /run

tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup

/dev/sda1               1014M  143M  872M  15% /boot

/dev/mapper/centos-home   42G   33M   42G   1% /home

tmpfs                    781M     0  781M   0% /run/user/0

/dev/mapper/vg1-testlv   6.8G   23M  6.4G   1% /users

[root@localhost ~]# 

[root@localhost ~]# ls /users/archlinux/

pam.d

[root@localhost ~]# 

练习4:收缩testlv至3G,要求archlinux的文件不能丢失

[root@localhost ~]# df -lh

Filesystem               Size  Used Avail Use% Mounted on

/dev/mapper/centos-root   50G  2.6G   48G   6% /

devtmpfs                 3.9G     0  3.9G   0% /dev

tmpfs                    3.9G     0  3.9G   0% /dev/shm

tmpfs                    3.9G  8.6M  3.9G   1% /run

tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup

/dev/sda1               1014M  143M  872M  15% /boot

/dev/mapper/centos-home   42G   33M   42G   1% /home

tmpfs                    781M     0  781M   0% /run/user/0

/dev/mapper/vg1-testlv   6.8G   23M  6.4G   1% /users

[root@localhost ~]# umount /users 

[root@localhost ~]# e2fsck -f /dev/vg1/testlv

e2fsck 1.42.9 (28-Dec-2013)

Pass 1: Checking inodes, blocks, and sizes

Pass 2: Checking directory structure

Pass 3: Checking directory connectivity

Pass 4: Checking reference counts

Pass 5: Checking group summary information

/dev/vg1/testlv: 48/458752 files (0.0% non-contiguous), 67358/1835008 blocks

[root@localhost ~]# resize2fs /dev/vg1/testlv 3G

resize2fs 1.42.9 (28-Dec-2013)

Resizing the filesystem on /dev/vg1/testlv to 786432 (4k) blocks.

The filesystem on /dev/vg1/testlv is now 786432 blocks long.

[root@localhost ~]# lvreduce /dev/vg1/testlv 3G

  No command with matching syntax recognised.  Run ‘lvreduce –help’ for more information.

  Correct command syntax is:

  lvreduce -L|–size [-]Size[m|UNIT] LV

[root@localhost ~]# lvreduce /dev/vg1/testlv -L 3G

  WARNING: Reducing active logical volume to 3.00 GiB.

  THIS MAY DESTROY YOUR DATA (filesystem etc.)

Do you really want to reduce vg1/testlv? [y/n]: y

  Size of logical volume vg1/testlv changed from 7.00 GiB (448 extents) to 3.00 GiB (192 extents).

  Logical volume vg1/testlv successfully resized.

[root@localhost ~]# lvs

  LV     VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert

  home   centos -wi-ao—- <41.12g                                                    

  root   centos -wi-ao—-  50.00g                                                    

  swap   centos -wi-ao—-  <7.88g                                                    

  testlv vg1    -wi-a—–   3.00g                                                    

[root@localhost ~]# mount /test

mount: cant find /test in /etc/fstab

[root@localhost ~]# mount /dev/vg1/testlv /users

[root@localhost ~]# df -lh

Filesystem               Size  Used Avail Use% Mounted on

/dev/mapper/centos-root   50G  2.6G   48G   6% /

devtmpfs                 3.9G     0  3.9G   0% /dev

tmpfs                    3.9G     0  3.9G   0% /dev/shm

tmpfs                    3.9G  8.6M  3.9G   1% /run

tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup

/dev/sda1               1014M  143M  872M  15% /boot

/dev/mapper/centos-home   42G   33M   42G   1% /home

tmpfs                    781M     0  781M   0% /run/user/0

/dev/mapper/vg1-testlv   2.9G   16M  2.7G   1% /users

[root@localhost ~]# ls /users/archlinux/

pam.d

[root@localhost ~]# 

练习5:对testlv创建快照,并尝试基于快照备份数据,验证快照的功能

[root@localhost ~]# lvs

  LV     VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert

  home   centos -wi-ao—- <41.12g                                                    

  root   centos -wi-ao—-  50.00g                                                    

  swap   centos -wi-ao—-  <7.88g                                                    

  testlv vg1    -wi-ao—-   3.00g                                                    

[root@localhost ~]# cd /users/archlinux/

[root@localhost archlinux]# touch test

[root@localhost archlinux]# touch test1

[root@localhost archlinux]# ls

test  test1

[root@localhost archlinux]# lvcreate -s -n testlv-snap -p r -L 500M /dev/vg1/testlv

  Using default stripesize 64.00 KiB.

  Rounding up size to full physical extent 512.00 MiB

  Logical volume “testlv-snap” created.

[root@localhost archlinux]# mount /dev/vg1/testlv-snap /backup/

mount: /dev/mapper/vg1-testlv–snap is write-protected, mounting read-only

[root@localhost archlinux]# ls /backup/archlinux/

test  test1

[root@localhost archlinux]# rm -rf test

[root@localhost archlinux]# ls

test1

[root@localhost archlinux]# ls /backup/archlinux/

test  test1

[root@localhost archlinux]# 

28.4 脚本完成磁盘分区格式化

28.4.1脚本编程及until简介

1、控制结构

脚本编程控制结构:

顺序

选择

if

case

循环

for

while

until

2、while

while CONDITION; do

  statment

done

进入循环:条件满足

退出循环:条件不满足

3、until

until CONDITION; do

  statement

  …

done

进入循环:条件不满足

退出循环:条件满足

4、for的两种形式

for 变量 in 列表; do

循环体

done

for (( expr1 ; expr2 ; expr3 )); do {例for((i=1;i<10;i++));do}

  循环体

done

5、continue

写一个脚本:

1、通过ping命令测试192.168.0.151到192.168.0.254之间的所有主机是否在线,

如果在线,就显示”ip is up.”,其中的IP要换为真正的IP地址,且以绿色显示;

如果不在线,就显示”ip is down.”,其中的IP要换为真正的IP地址,且以红色显示;

要求:分别使用while,until和for(两种形式)循环实现。

ping

-c

-W

写一个脚本(前提:请为虚拟机新增一块硬盘,假设它为/dev/sdb),为指定的硬盘创建分区:

1、列出当前系统上所有的磁盘,让用户选择,如果选择quit则退出脚本;如果用户选择错误,就让用户重新选择;

2、当用户选择后,提醒用户确认接下来的操作可能会损坏数据,并请用户确认;如果用户选择y就继续,n就退出;否则,让用户重新选择;

3、抹除那块硬盘上的所有分区(提示,抹除所有分区后执行sync命令,并让脚本睡眠3秒钟后再分区);并为其创建三个主分区,第一个为20M,第二个为512M, 第三个为128M,且第三个为swap分区类型;(提示:将分区命令通过echo传送给fdisk即可实现)

fdisk -l |grep “

dd if=/dev/zero of=/dev/sdb bs=512 count=1

sync

sleep 3

RAID

LVM:

逻辑卷的缩减

扩展

快照卷

while CONDITION; do

  循环体

done

while [ $VAR != ‘quit’ ];do 

done

27、RAID及mdadm命令

27.1 文件系统基本概念

ext2: 文件系统块组组成:

超级块、GDT、block bitmap、inode bitmap、data blocks

驱动程序:将CPU的控制指令转换为特定设备要执行的操作(一般由硬件厂商提供)

控制器:直接继承的设备

适配器:非继承的

硬盘类型

IDE总线:速度133Mbps

SATA(1,2,3):300Mbps,600Mbps,6Gbps

USB 3.0:480Mbps

SCSI(Small Computer System Interface):有自己的CPU可以分担大CPU的存储负担(目前RAID常用)

SAS:(目前RAID常用)

27.2 RAID

RAID(Redundant Arrays of Inexpensive/Independent Disks )

廉价/独立冗余磁盘阵列(之前叫廉价,后来发现成本不低,就改成了独立)

Berkeley(美国加州大学伯克利分校的一位教授的论文):A case for Redundent Arrays of Inexpensive Disks RAID

提高I/O能力:

磁盘并行读写

提高耐用性:

磁盘冗余来实现

RAID实现的方式:

Hardware RAID

外接式磁盘阵列,通过扩展RAID卡实现外界磁盘阵列;

内接式RAID:主板集成RAID控制器

Software RAID:

RAID控制器:可以控制多个硬盘的控制器

RAID LEVEL

级别:仅代表磁盘组织方式不同,没有上下之分;

RAID10优于RAID01

RAID0: 条带

性能提升: 读,写

冗余能力(容错能力): 无

空间利用率:1*min(S1,S2…)

至少2块盘

RAID1: 镜像

性能表现:写性能略有下降,读性能提升

冗余能力:有

空间利用率:1*min(S1,S2…)

至少2块盘

RAID2

RAID3

RAID4:

校验码:硬件备份和冗余机制

校验码盘容易成为性能瓶颈:解决方案,轮换成为校验码盘

有一块专门的盘存储校验码(异或制,此块盘为性能瓶颈)

性能表现:读,写提升

冗余能力:有

空间利用率:(N-1)*min(S1,S2,…)

至少需要3块

RAID5:

性能表现:读,写提升

冗余能力:有(1块盘)

空间利用率:(N-1)*min(S1,S2,…)

至少需要3块

RAID6:

性能表现:读,写提升

冗余能力:有(2块盘)

空间利用率:(N-2)*min(S1,S2,…)

至少需要3块

RAID10:先作镜像再做条带(相对更可靠)

性能表现:读、写提升

冗余能力:有(每组镜像最多只能坏一块)

空间利用率:N*min(S1,S2,…)/2

至少需要4块

RAID01:先做条带再做镜像,

性能表现:读、写提升

冗余能力:有

空间利用率:N*min(S1,S2,…)/2

至少需要4块

RAID50:(先做RAID5,再做RAID0)

性能表现:读、写提升

冗余能力:有

空间利用率:(N-2)/N*min(S1,S2,…)/2

至少需要6块

RAID7

jbod:将多个小盘组成一个大盘

性能表现:无提升

冗余能力:无

空间利用率:100%(SUM(S1,S2…..))

至少需要2块

常用级别:RAID0,RAID1,RAID5,RAID10,RAID50,JBOD

27.3 RAID实现

27.3.1 硬件RAID

在主板上有个RAID控制器,通过BIOS进行控制更改

27.3.2 软件RAID

通过内核中的md模块来手动配置RAID

md:multi disks/devices

软RAID设备必须被标识为fd类型,避免系统崩溃以后RAID设备无法再访问

/proc/mdstat:显示当前系统所有启动的RAID

逻辑RIAD:

/dev/md0

/dev/md1

mdadm(md管理器):

将任何块设备做成RAID(同一块硬盘两个分区也可以做,但没有性能提升的意义)

支持的RAID级别:LINEAR,RAID0,RAID1,RAID4,RAID5,RAID6,RAID10等

模式化的命令:

创建模式

-C

专用选项:

-l: 指明要创建的RAID级别

-n #: 设备个数

-a {yes|no}: 是否自动为其创建设备文件

-c: 指定CHUNK(条带)大小, 2^n,默认为64K

-x #: 指定空闲盘个数

管理模式

-a:添加磁盘

-r:移除磁盘

-f:标记指定磁盘为损坏

–add, –remove, –fail

mdadm /dev/md# –fail /dev/sda7

监控模式

-F

增长模式

-G

装配模式

-A

查看RAID阵列的详细信息

-D /dev/md#

–detail

–scan > /etc/mdadm.conf(将当前RAID信息保存至配置文件,以便以后进行装配:)

停止阵列:

-S /dev/md#

–stop

例:创建一个10G可用空间的3块盘

[root@localhost ~]# mdadm -C /dev/md0 -a yes -n 3 -l 5 /dev/sda1 /dev/sda2 /dev/sda3

mdadm: Fail to create md0 when using /sys/module/md_mod/parameters/new_array, fallback to creation via node

mdadm: Defaulting to version 1.2 metadata

mdadm: array /dev/md0 started.

[root@localhost ~]# cat /proc/mdstat

Personalities : [raid6] [raid5] [raid4] 

md0 : active raid5 sda3[3] sda2[1] sda1[0]

      10475520 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [UU_]

      [==>………………]  recovery = 10.6% (556540/5237760) finish=0.7min speed=111308K/sec

unused devices: <none>

[root@localhost ~]# mkdir /test

[root@localhost ~]# mount /dev/md0 /test

[root@localhost ~]# df -h

Filesystem               Size  Used Avail Use% Mounted on

/dev/mapper/centos-root   50G  2.6G   48G   6% /

devtmpfs                 3.9G     0  3.9G   0% /dev

tmpfs                    3.9G     0  3.9G   0% /dev/shm

tmpfs                    3.9G  8.7M  3.9G   1% /run

tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup

/dev/sdb1               1014M  143M  872M  15% /boot

/dev/mapper/centos-home   42G   33M   42G   1% /home

tmpfs                    781M     0  781M   0% /run/user/0

/dev/md0                 9.8G   37M  9.2G   1% /test

[root@localhost ~]# mke2fs -t ext4 /etc/md0

mke2fs 1.42.9 (28-Dec-2013)

Could not stat /etc/md0 — No such file or directory

The device apparently does not exist; did you specify it correctly?

[root@localhost ~]# mke2fs -t ext4 /dev/md0

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=128 blocks, Stripe width=256 blocks

655360 inodes, 2618880 blocks

130944 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=2151677952

80 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks: 

    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done                            

Writing inode tables: done                            

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done 

[root@localhost ~]# mkdir /test

[root@localhost ~]# mount /dev/md0 /test

[root@localhost ~]# mount

sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)

proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)

devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=3985976k,nr_inodes=996494,mode=755)

securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)

tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)

devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)

tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)

tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755)

cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)

pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)

cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)

cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)

cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)

cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)

cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)

cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)

cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)

cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)

cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)

cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)

configfs on /sys/kernel/config type configfs (rw,relatime)

/dev/mapper/centos-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)

systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=30,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=12878)

debugfs on /sys/kernel/debug type debugfs (rw,relatime)

mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)

hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)

/dev/sdb1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

/dev/mapper/centos-home on /home type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=799408k,mode=700)

/dev/md0 on /test type ext4 (rw,relatime,seclabel,stripe=256,data=ordered)

[root@localhost ~]# blkid /dev/md0

/dev/md0: UUID=”827112e4-bd97-4394-b812-1394dcd10e71″ TYPE=”ext4″ 

[root@localhost ~]# mdadm -D /dev/md0

/dev/md0:

           Version : 1.2

     Creation Time : Mon Jul 26 04:26:58 2021

        Raid Level : raid5

        Array Size : 10475520 (9.99 GiB 10.73 GB)

     Used Dev Size : 5237760 (5.00 GiB 5.36 GB)

      Raid Devices : 3

     Total Devices : 3

       Persistence : Superblock is persistent

       Update Time : Mon Jul 26 04:32:45 2021

             State : clean 

    Active Devices : 3

   Working Devices : 3

    Failed Devices : 0

     Spare Devices : 0

            Layout : left-symmetric

        Chunk Size : 512K

Consistency Policy : resync

              Name : localhost.localdomain:0  (local to host localhost.localdomain)

              UUID : 5fb851eb:b930b950:288b80e1:e384eb79

            Events : 18

    Number   Major   Minor   RaidDevice State

       0       8        1        0      active sync   /dev/sda1

       1       8        2        1      active sync   /dev/sda2

       3       8        3        2      active sync   /dev/sda3

[root@localhost ~]# mdadm /dev/md0 -f /dev/sda1

mdadm: set /dev/sda1 faulty in /dev/md0

[root@localhost ~]# mdadm -D /dev/md0

/dev/md0:

           Version : 1.2

     Creation Time : Mon Jul 26 04:26:58 2021

        Raid Level : raid5

        Array Size : 10475520 (9.99 GiB 10.73 GB)

     Used Dev Size : 5237760 (5.00 GiB 5.36 GB)

      Raid Devices : 3

     Total Devices : 3

       Persistence : Superblock is persistent

       Update Time : Mon Jul 26 04:35:01 2021

             State : clean, degraded 

    Active Devices : 2

   Working Devices : 2

    Failed Devices : 1

     Spare Devices : 0

            Layout : left-symmetric

        Chunk Size : 512K

Consistency Policy : resync

              Name : localhost.localdomain:0  (local to host localhost.localdomain)

              UUID : 5fb851eb:b930b950:288b80e1:e384eb79

            Events : 20

    Number   Major   Minor   RaidDevice State

       –       0        0        0      removed

       1       8        2        1      active sync   /dev/sda2

       3       8        3        2      active sync   /dev/sda3

       0       8        1        –      faulty   /dev/sda1

[root@localhost ~]# mdadm /dev/md0 -f /dev/sda2

mdadm: set /dev/sda2 faulty in /dev/md0

[root@localhost ~]# mdadm -D /dev/md0

/dev/md0:

           Version : 1.2

     Creation Time : Mon Jul 26 04:26:58 2021

        Raid Level : raid5

        Array Size : 10475520 (9.99 GiB 10.73 GB)

     Used Dev Size : 5237760 (5.00 GiB 5.36 GB)

      Raid Devices : 3

     Total Devices : 3

       Persistence : Superblock is persistent

       Update Time : Mon Jul 26 04:35:40 2021

             State : clean, FAILED 

    Active Devices : 1

   Working Devices : 1

    Failed Devices : 2

     Spare Devices : 0

            Layout : left-symmetric

        Chunk Size : 512K

Consistency Policy : resync

              Name : localhost.localdomain:0  (local to host localhost.localdomain)

              UUID : 5fb851eb:b930b950:288b80e1:e384eb79

            Events : 22

    Number   Major   Minor   RaidDevice State

       –       0        0        0      removed

       –       0        0        1      removed

       3       8        3        2      active sync   /dev/sda3

       0       8        1        –      faulty   /dev/sda1

       1       8        2        –      faulty   /dev/sda2

[root@localhost ~]# mdadm /dev/md0 -a /dev/sda1

mdadm: Cannot open /dev/sda1: Device or resource busy

[root@localhost ~]# 

[root@localhost ~]# mdadm /dev/md0 -a /dev/sda2

mdadm: Cannot open /dev/sda2: Device or resource busy

[root@localhost ~]# mdadm /dev/md0 -r /dev/sda2

mdadm: hot removed /dev/sda2 from /dev/md0

[root@localhost ~]# mdadm /dev/md0 -r /dev/sda1

mdadm: hot removed /dev/sda1 from /dev/md0

[root@localhost ~]# mdadm -D /dev/md0

/dev/md0:

           Version : 1.2

     Creation Time : Mon Jul 26 04:26:58 2021

        Raid Level : raid5

        Array Size : 10475520 (9.99 GiB 10.73 GB)

     Used Dev Size : 5237760 (5.00 GiB 5.36 GB)

      Raid Devices : 3

     Total Devices : 1

       Persistence : Superblock is persistent

       Update Time : Mon Jul 26 04:37:12 2021

             State : clean, FAILED 

    Active Devices : 1

   Working Devices : 1

    Failed Devices : 0

     Spare Devices : 0

            Layout : left-symmetric

        Chunk Size : 512K

Consistency Policy : resync

              Name : localhost.localdomain:0  (local to host localhost.localdomain)

              UUID : 5fb851eb:b930b950:288b80e1:e384eb79

            Events : 24

    Number   Major   Minor   RaidDevice State

       –       0        0        0      removed

       –       0        0        1      removed

       3       8        3        2      active sync   /dev/sda3

[root@localhost ~]# mdadm -S /dev/md0

mdadm: Cannot get exclusive access to /dev/md0:Perhaps a running process, mounted filesystem or active volume group?

[root@localhost ~]# unmount /dev/md0

-bash: unmount: command not found

[root@localhost ~]# umount /dev/md0

[root@localhost ~]# mdadm -S /dev/md0

mdadm: stopped /dev/md0

[root@localhost ~]# cat /proc/mdstat 

Personalities : [raid6] [raid5] [raid4] 

unused devices: <none>

[root@localhost ~]# 

watch: 周期性地执行指定命令,并以全屏方式显示结果

-n #:指定周期长度,单位为秒,默认为2

格式: watch -n # ‘COMMAND’

CentOS7.4 安装wordpress

步骤一:安装Apache服务器

1、yum -y install httpd

最后显示complete即完成

2、启动httpd并且设置为开机启动

systemctl start httpd.service
systemctl enable httpd.service

3、安装firewall

yum -y install firewalld firewall-config

systemctl start firewalld.service
systemctl enable firewalld.service

4、配置firewall

firewall-cmd –permanent –zone=public –add-service=http
firewall-cmd –permanent –zone=public –add-service=https
firewall-cmd –reload

步骤二:安装MariaDB

1、利用yum命令进行安装,并配置开机启动

3. 添加mariadb10.2的国内yum源

之前我添加的是国外的源,安装很耗时,所以我找到国内yum源,通过这个源安装较快。

vim  /etc/yum.repos.d/Mariadb.repo

添加以下内容:

[mariadb]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-amd64
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1

按esc,然后:wq退出

清除yum源缓存数据

yum clean all

生成新的yum源数据缓存

yum makecache all

官方yum源(国内安装较慢)

1 2 3 4 5 6 7# MariaDB 10.2 CentOS repository list – created 2018-06-06 03:42 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.2/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1

官方不同系统yum源网址:https://downloads.mariadb.org/mariadb/repositories/#mirror=tuna

4. 安装mariadb10.2

yum install MariaDB-server MariaDB-client -y

启动并添加开机自启:

systemctl start mariadb.service
systemctl enable mariadb.service

5. mariadb的初始化

mysql_secure_installation

一般建议按以下进行配置:

Enter current password for root (enter for none): Just press the Enter button
Set root password? [Y/n]: Y
New password: your-MariaDB-root-password
Re-enter new password: your-MariaDB-root-password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: n
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y

yum -y install mariadb-server mariadb
systemctl start mariadb.service
systemctl enable mariadb.service

6、配置root密码

mysql_secure_installation

  • 具体有以下几个选项,可以根据各自情况进行配置(建议全部选Y)

Enter current password for root (enter for none):(输入原始root密码,若无则按enter)
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] (按Y设置root密码)whd-521123
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 … Success!

Remove anonymous users? [Y/n] (按Y移除匿名用户)
 … Success!

Disallow root login remotely? [Y/n] (按Y禁止远程root登陆,一般root都设定为只允许本地登陆)
 … skipping.

Remove test database and access to it? [Y/n] (按Y删除测试数据库)

Reload privilege tables now? [Y/n] (按Y重新载入)
 … Success!

Cleaning up…

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

Thanks for using MariaDB!

步骤三:安装PHP

1. 更新yum安装包

CentOS 7.x

rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

CentOS 6.x

rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm

CentOS 5.x

rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm

2. 通过云进行php和其他组件的安装

yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64 php70w-fpm

yum install其他需要的组件在自行安装。

3.测试php安装情况

vim /var/www/html/config.php 

按字母i或insert键进入编辑模式,编辑为以下内容php

<?php
phpinfo();
?>

编辑完成后键入“Esc:wq”,保存文件并退回到命令行模式

5、重启httpd服务

systemctl restart httpd.service

6、在浏览器打开网址 http://x.x.x.x/config.php 进行查看(x.x.x.x为你的服务器公网IP)

类似图中即为正常

步骤四:配置数据库

1、登陆MariaDB为WordPress建立数据库及用户

mysql -u root -p

2、新建数据库wordpressdb,用户为wordpressuser,密码为123456

CREATE DATABASE wp_danios;
CREATE USER daniel@localhost IDENTIFIED BY ‘Abcd@123’;

3、更改用户权限,保存并退出

GRANT ALL PRIVILEGES ON wp_danios.* TO daniel@localhost;
FLUSH PRIVILEGES;
exit

4、重启相关服务

systemctl restart httpd.service
systemctl restart  mariadb.service

步骤五:安装WordPress

1、新建一个文件夹,此处取名wp

mkdir wp
cd wp
yum -y install wget unzip net-tools
wget http://wordpress.org/latest.zip

2、解压文件,并且将其复制到/var/www/html目录下

unzip -q latest.zip
cp -rf wordpress/* /var/www/html/

3、修改文件夹权限

chown -R apache:apache /var/www/html/
chmod -R 755 /var/www/html/
mkdir -p /var/www/html/wp-content/uploads
chown -R :apache /var/www/html/wp-content/uploads

4、编辑配置文件

cd /var/www/html
cp wp-config-sample.php wp-config.php
vim wp-config.php

打开文件后,按i键或insert键进入编辑模式,将其修改为以下格式(其中wordpressdb为数据库名称,wordpressuser为数据库用户名,123456为数据库密码)

// * MySQL settings – You can get this info from your web host * //
/* The name of the database for WordPress /
define(‘DB_NAME’, ‘wordpressdb’);

/* mysql database username /
define(‘DB_USER’, ‘wordpressuser’);

/* MySQL database password /
define(‘DB_PASSWORD’, ‘123456’);

键入“Esc:wq”,存盘并退出

5、重启相关服务

systemctl restart httpd.service
systemctl restart mariadb.service

步骤六:WordPress的个人设置

登录 http://x.x.x.x/访问你的博客(x.x.x.x为你的服务器公网IP),按照自己的喜好进行相关的设置。

参考素材:http://blog.csdn.net/keneuro/article/details/48543613 

http://blog.csdn.net/keneuro/article/details/48575533 

https://www.qcloud.com/community/article/883465

<https://blog.csdn.net/liyaxin2010/article/details/83184423>

vmware虚拟机安装CentOS7.4

本教程使用Vmware虚拟机系统搭载 Linux 系统 CentOS 7.4为例

1、安装GUI服务器即可

2、设置ROOT密码,并创建新用户

3、网卡设置为桥接模式,个人更喜欢这种模式

4、安装完成,重启同意协议即可

5、安装puttyFileZilla

使用putty通过IP地址远程连接服务器进行配置

Mysql 8.0.26 wordpress无法访问数据库问题处理

mysql8.0.26配置完成以后,发现wordpress无法访问数据库,后来确认了一下用户名,密码都是正确的。

猜想可能是密码权限的问题,更改密码格式后正常访问

命令:

mysql -u root -p

alter user ‘root’@’%’identified with mysql_native_password by ‘密码’;

root改为自己wordpress的用户名,密码改为自己的密码即可,与之前的一样也不影响

tctconfig使用说明


tctconfig

实现通过脚本自动部署备份,重启,更新tomcat系统

详细文档及配置内容,请查看http://www.danios.com/tctconfig/

1、安装步骤

a)root账户或有权限访问/etc,/usr/bin的账户可用software模式

	bash tctcofig-xx.run -sw|--software(可直接下载tctconfig-xx.run,或者在源码包中可找到tctconfig-xx.run)

卸载

	removtct

	若是无法找到removtct,说明程序未安装

b)所有用户都可用script模式部署(默认部署路径为$HOME)

	bash tctcofig-xx.run -sc|--script(可直接下载tctconfig-xx.run,或者在源码包中可找到tctconfig-xx.run)

卸载

	removtct

	若是无法找到removtct,说明程序未安装

2、命令格式

tctconfig [OPTION] [TOMCATNAME]
tctconfig -l TOMCATNAME [COUNT]

Option:

-b|--backup
    
	备份对应的tomcat根路径的所有文件,生成ROOTPATHYYYY-MM-DD-HH:MM:SS.zip格式的备份文件,直接放置于根路径所在的父目录中

-tb|--testbackup

	测试前的备份,备份对应的tomcat根路径的所有文件,生成ROOTPATHYYYY-MM-DD-HH:MM:SSTB.zip格式的备份文件,直接放置于根路径所在的父目录中

-r|--restart

	重启对应的tomcat,并查看catliana.out日志

-u|--update

	更新对应的tomcat,有4个步骤;
	 1、备份对应的tomcat,类似-b命令
	 2、关闭对应的tomcat,类似-sh命令
	 3、更新文件,将$PACKAGE_PATH/packages/update文件夹下面的所有更新文件拷贝到$TOMCATPATH/webapps/$ROOTPATH中,并覆盖重复的文件
	 4、清理更新文件,将$PACKAGE_PATH/packages/update文件夹下面的所有更新文件移动到./tctconfig/packages/backup/$TOMCATVERSION/YYYY-MM-DD-HH:MM:SS文件夹中
	 5、开启对应tomcat,类似-st命令

-tu|--testupdate

	更新测试文件,不进行备份操作,只更新文件,重启tomcat,相当于-u的2,3,4功能
	建议进行测试更新之前执行以下tctconfig -tb TOMCATVERSION,进行一下备份,避免出现不必要的损失


-tg|--tgupdate

	同时进行两个或者多个系统的更新,可通过配置tgupdate函数进行调整

-sh|--shutdown

	关闭对应的tomcat

-st|--startup

	开启对应的tomcat


-e|--edit

	使用vim编辑WEB-INF/classes里面的对应的文件,目前有三个选项:con|com|spr


-l|--log

	查看对应的tomcat的catalina.out的日志,使用格式:
		multi模式:tctconfig -l TOMCATVERSION [COUNT]
			例:tctconfig -l vm(查看vm对应的系统的日志,并持续输出)
	    		    tctconfig -l vm 1000(查看vm对应的系统的最近1000行的日志,并持续输出)	
		
		single模式:tctconfig -l [COUNT]
			例: tctconfig -l(查看single tomcat对应的系统的日志,并持续输出)
                                tctconfig -l 1000(查看vm对应的系统的最近1000行的日志,并持续输出)

-i|--install

	安装部署tomcat,jdk,redis,可以选择需要的组件进行安装,安装文件位置为./package/install

-c|--clean

	清理日志,更新备份文件和残留进程,可用y/n选择清理对应的文件

-h|--help 

	查看帮助

tct.conf:

tctconfig的配置文件,用于配置tctconfig的运行模式以及应用信息。

TOMCATVERSION:
    	为tomcat的版本名称,版本信息位于/etc/tct.conf或者$HOME/tctconfig/conf/tct.conf中,以分号隔开
    例:
    	vm:/opt/webserver/tomcat8:ROOT
    	tomcat版本:tomcat部署路径:根路径

PROGRAM_MODE:
	程序的运行模式,分为单系统模式(single)和多系统模式(multi),
SINGLE_PATH:
	后面跟的是单用户模式的应用信息。
	模式为TOMCATVERSION:TOMCATPATH:ROOTPATH
MULTI_name:
	通过此配置文件可配置多个tomcat,后面的tomcat名称用空格隔开,name为关键字
	例:MULTI_name:tomcat tomcat2 tomcat3

WordPress更改固定连接(permalinks)后只能访问首页问题处理

今天整理了一下网站,想将固定链接调整一下,但是又出现了只能访问首页,其他子页面提示无法访问的问题,联想到之前也出现过同样的问题,然后这次就研究了一下。

看到了wordpress官网关于固定链接的介绍,发现需要开启apache的mod_rewrite module才能正常使用Pretty permalinks,

以下是原文:

Using mod_rewrite or lighttpd you can produce much nicer permalinks (see Pretty Permalinks). There are many different formats, but the most common, and most versatile looks like

http://example.com/2012/post-name/

or

http://example.com/2012/12/30/post-name

Pretty permalinks are available under:

  • Apache web server with the mod_rewrite module
  • Nginx using try-files, e.g. according to this tutorial
  • Hiawatha web server with UrlToolkit support enabled.
  • Lighttpd using a 404 handler or mod_rewrite
  • Caddy using rewrite, e.g. according to this tutorial

随后找了一下开启的方法,在这里找到了

如果不想打开链接的话,直接往下看即可。

我直接把对应的部分拷贝了出来,如果想看中文的话可以拉到最后

Enable Mod_rewrite Module

The mod_rewrite module is enabled by default on CentOS 7. If you find it is not enabled on your server, you can enable it by editing 00-base.conf file located in /etc/httpd/conf.modules.d/ directory.

sudo nano /etc/httpd/conf.modules.d/00-base.conf

Add or uncomment the following line:

LoadModule rewrite_module modules/mod_rewrite.so

Save and close the file, then restart the httpd service:

sudo systemctl restart httpd

Enable .Htaccess File

Once the mod_rewrite module has been activated, you can set up your URL rewrites by creating an .htaccess file in your default document root directory. A .htaccess file allows us to modify our rewrite rules without accessing server configuration files. For this reason, .htaccess is critical to your web server. Before we begin, we need to allow Apache to read .htaccess files located under the /var/www/html directory.

You can do this by editing httpd.conf file:

sudo nano /etc/httpd/conf/httpd.conf

Find the section <directory /var/www/html> and change AllowOverride None to AllowOverride All

 &lt;Directory /var/www/html>
    AllowOverride All
 &lt;/Directory>

Save and exit.

Now restart Apache to put the change into effect:

sudo systemctl restart httpd

第一步大概意思就是修改/etc/httpd/conf.modules.d/00-base.conf文件,将

LoadModule rewrite_module modules/mod_rewrite.so

这一句前的注释取消,如果没有这一句的话直接加上即可

我看了一下,我的是这个文件里的这部分是正常的,就没有调整。

然后我按照第二步调整了一下,网站显示就正常了,下面是调整步骤

修改/etc/httpd/conf/httpd.conf文件,找到如下类型的文本,修改为

 &lt;Directory /var/www/html>
    AllowOverride All
 &lt;/Directory>

修改完以后重启apache即可

sudo systemctl restart httpd

文本修改的方法可以参考我的关于vim配置的文章

此处理方案仅是个人环境的处理方案,仅供参考,有问题的话也可以留言讨论