• 初阶项目一-集成一套linux系统:红帽系统,LVM分区,Apache服务,MySQL服务,数据定时备份脚本


    一.项目目标

    ​ 根据公司要求:集成一套LINUX系统,按照规定进行分区划分,组建LVM分区,创建用户;部署一套web+mysql,并通过shell脚本+cron执行定期自动备份数据。

    二.实施工具

    ​ 本次软件实施需要用到的工具: VMware Workstation虚拟机、rhel-server-7.5-x86_64-dvd.iso镜像文件、xshell远程连接工具。

    三.项目实施计划

    1.安装rhel7.5系统

    • ​ 首先,使用VMware Workstation12虚拟机进行模拟安装,操作系统是rhel7.5的版本,由于在实际工作环境中一般都是接触不了服务器的,都是通过远程工具xshell、crt这些工具进行远程连接操作,所以服务器是安装带gui的图形化界面,而在安装好操作系统之,可以通过配置/etc/sysconfig/network-scritpts/ifcfg-ensxx修改网卡信息,或者使用命令nmtui进行网卡的配置;
    • ​ 配置本地yum,满足后期安装各种软件或工具的需求;
    • ​ 在安装好操作系统之后关掉防火墙和Selinux,并设置防火墙开机不启动;
    • ​ 在上面的都配置后之后,需要为系统做一个快照,以防止以后系统出现不可修复的问题时,可以快速恢复系统,不影响应用的正常运行。

    2.组建LVM分区:LVM分区比标准分区更好扩展,方便后期分区容量不足时,进行扩容。

    3.安装apache服务

    • ​ ISO光盘镜像中有Apache程序,所以可以通过yum的方式来安装apache服务;
    • ​ 通过Web浏览器访问Apache的地址,测试Apache是否安装成功。

    4.安装MySQL服务。

    5.自动备份数据

    • ​ 通过cron和shell脚本自动备份数据;
    • ​ 在完成cron和shell备份之后,在shell脚本中添加自动删除5天前的备份数据。

    四.安装rhel7.5操作系统

    4.1 配置虚拟机

    1.在虚拟机的主页上点击创建新的虚拟主机

    image-20201214164418183

    2.选择自定义,然后下一步

    image-20201214163918334

    3.一直默认下一步,直到选择安装源时选择稍后安装系统

    image-20201214164728319

    4.客户机的操作系统选择linux,由于我们需要安装的时rhel7.5 64位的系统,所以在下面的版本选择Red Hat Enterprise Linux 7 64 位,

    然后下一步

    5.选择虚拟机的名称和虚拟机安装的位置,路径最好是自己选择,这样方便以后做迁移

    image-20201215163420167

    6.一路默认,在选择网络的时候选择仅主机模式

    image-20201214165214935

    7.一直下一步,直到选择磁盘,选择创建新虚拟磁盘,点击下一步

    image-20201214165319231

    8.选择磁盘的容量和磁盘是否为单个文件,本人在这里的选择是磁盘大小20G,为单个文件,点击下一步

    image-20201214165440617

    9.在这一步可以自定义硬件,也可以点击完成,在后面在完善虚拟机的硬件信息,本人是选择之后再配置硬件信息,所以是直接点击完成

    image-20201215163600996

    10.配置完成之后可以在界面看到配置好的主机信息

    image-20201215163751924

    选择编辑虚拟机设置

    image-20201215163912937

    11.由于声卡和打印机可以不要,所以可以点击移除,而安装系统需要镜像即iso文件,所以在CD/DVD选择你的镜像文件

    image-20201215164116952

    image-20201215164240865

    12.自此,虚拟机的配置就完成了,下面开始安装操作系统。

    4.2 安装操作系统

    1.点击开启此虚拟机

    image-20201215164445845

    界面说明
    Install Red Hat Enterprise Linux 7.2 安装RHEL7.2
    Test this media & install Red HatEnterprise Linux 7.2 测试安装文件并安装RHEL 7.2
    Troubleshooting 修复故障

    image-20201215000639505

    2.在这一步可以点击回车继续安装,或者等待一会自动继续安装

    image-20201215000734345

    3.选择语言:简体中文(新手选择中文,老手选择英文)

    image-20201215000949508

    4.需要把界面上的都配置好才可以进行下一步的安装,本地化的日期和时间、键盘和语言支持都选默认,不用修改

    image-20201215001103188

    5.把SECURITY的开启改为关闭

    image-20201215001157909

    image-20201215001252812

    6.选择服务器的软件安装,这里选择的是带GUI的服务器,但是由于在实际环境中都是通过xshell、crt这些远程工具连接的,所以后期安装好系统之后也会用远程工具进行连接

    image-20201215001400802

    image-20201215001450796

    7.选择安装位置,进行磁盘分区

    image-20201215001605187

    8.选择-其它存储选项-分区-我要配置分区,点左上角的“完成”,进入下面的界面,在分区方案有标准分区,btrfs,LVM,LVM简单配置,这里默认LVM就可以,然后单击"+"创建新的分区,分区提前规划好,一般swap分区为物理内存的1.5~2倍,/boot分区300M-500M,/home分区给2G,剩余的空间全部给/分区,实际工作中可以创建数据分区,一般把数据和系统分开

    image-20201215001857733

    image-20201215001939783

    创建/boot分区

    image-20201215002106073

    9.设备类型选择默认的标准分区,文件系统类型为xfs,RHEL7支持brtfs,生产环境不建议选择,btrfs文件系统目前技术尚未成熟,只是作为一种前瞻技术

    image-20201215002233566

    10.创建/swap分区

    image-20201215002408321

    11.创建/home分区

    image-20201215002517432

    12.创建/分区(期望容量不填,代表把剩余的所有空间都给/分区)

    image-20201215002651344

    13.选择接受更改(这里相当于windows的格式化分区)

    image-20201215002757864

    14.配置网络,选择开启,开启之后会自动获取一个ip,如果需要手动配置的话,可以选择配置,也可以在系统安装完成之后再进行配置,在这里就先不配置,等安装好系统之后再进行配置,然后点击开始安装

    image-20201215003002828

    15.设置root密码,这里提示密码强度较差,因为是虚拟机所以密码不用太复杂,但在实际环境中,密码的设定需要符合安全性的标准

    image-20201215003207806

    image-20201215003244739

    16.下图代表操作系统正在安装,等待即可

    image-20201215003410130

    17.安装完成之后,点击重启,进行最后的配置

    image-20201215003501434

    18.进入启动界面

    image-20201215003605618

    19.首次启动许可配置,选择同意许可协议即可

    image-20201215003707957

    image-20201215003743637

    20.点击完成配置

    image-20201215003832809

    21.最后确认语言和键盘输入

    image-20201215003937922

    image-20201215004009445

    22.配置时区,如果在前面开启了网络,这里会自动获取时区,如果没有开启的话,可以选择shangghai会自动出现相关的选项

    image-20201215004108211

    23.配置登陆的个人账号密码

    image-20201215163151740

    image-20201215004244918

    24.系统到这里已经正式安装完成

    image-20201215004346896

    image-20201215004413837

    4.3 系统配置

    4.3.1 网络配置

    1.网络配置可以使用nmtui、nmtui-connect和修改配置文件3种方法,配置网络需要使用root用户。查看网卡的信息,可以使用ifconfig

    或ip addr, 由于在安装的时候没有开启网络,所以ifconfig是看不到相应的ip地址信息的。

    2.配置静态IP,网卡配置信息地址:/etc/sysconfig/network-scripts/ifcfg-ensxx (网卡一般是ens开头的,后面是随机的数字),使用vim

    编辑器修改之后用:wq或者:x保存退出

    [root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33   
    
    [root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
    TYPE="Ethernet"
    PROXY_METHOD="none"
    BROWSER_ONLY="no"
    BOOTPROTO="static"
    DEFROUTE="yes"
    IPV4_FAILURE_FATAL="no"
    #IPV6INIT="yes"
    #IPV6_AUTOCONF="yes"
    #IPV6_DEFROUTE="yes"
    #IPV6_FAILURE_FATAL="no"
    #IPV6_ADDR_GEN_MODE="stable-privacy"
    NAME="ens33"
    UUID="1d4c270e-2a48-474d-b963-ad0e68eafbcd"
    DEVICE="ens33"
    ONBOOT="yes"
    DNS1=114.114.114.114
    IPADDR=192.168.110.184
    NETMASK=255.255.255.0
    GATEWAY=192.168.110.2
    ZONE=
    

    3.重启网络服务(systemctl restart NetworkManager和service network restart任选其一即可)

    #重启网卡
    [root@localhost ~]# systemctl restart NetworkManager
    
    #查看网卡状态
    [root@localhost ~]# systemctl status NetworkManager
    ● NetworkManager.service - Network Manager
       Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
       Active: active (running) since Tue 2020-12-15 10:32:54 CST; 8s ago
         Docs: man:NetworkManager(8)
     Main PID: 100634 (NetworkManager)
       CGroup: /system.slice/NetworkManager.service
               ├─100634 /usr/sbin/NetworkManager --no-daemon
               └─100657 /sbin/dhclient -d -q -sf /usr/libexec/nm-dhcp-helper -pf /var/run/dhclient-ens37.pid -lf /var/lib/NetworkManager/dhclient-31881a66-4327-3e39-a2ab-b060a3b74062-ens37.lease -cf /var/lib/Ne...
    ......
     
    [root@localhost ~]# service network restart
    Restarting network (via systemctl):                        [  OK  ]
    
    [root@localhost ~]# service network status
    Configured devices:
    lo ens33
    Currently active devices:
    lo ens33 
    

    4.添加DNS

    [root@localhost ~]# vim /etc/resolv.conf  
    
    [root@localhost ~]# cat /etc/resolv.conf
    # Generated by NetworkManager
    search localdomain
    nameserver 192.168.110.2
    nameserver 114.114.114.114
    

    5.测试网络是否畅通

    #-c:代表ping的次数
    #有数据返回代表网络正常
    [root@localhost ~]# ping -c 4 www.g.cn
    PING www.g.cn (203.208.40.98) 56(84) bytes of data.
    64 bytes from 203.208.40.98 (203.208.40.98): icmp_seq=1 ttl=128 time=27.9 ms
    64 bytes from 203.208.40.98 (203.208.40.98): icmp_seq=2 ttl=128 time=28.7 ms
    64 bytes from 203.208.40.98 (203.208.40.98): icmp_seq=3 ttl=128 time=28.4 ms
    64 bytes from 203.208.40.98 (203.208.40.98): icmp_seq=4 ttl=128 time=28.5 ms
    
    --- www.g.cn ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3007ms
    rtt min/avg/max/mdev = 27.921/28.417/28.746/0.305 ms
    

    4.3.2 修改主机名

    1.方法一:使用命令:nmtui

    [root@localhost ~]# nmtui
    

    image-20201215105105091

    image-20201215105145182

    2.方法二:命令:hostnamectl set-hostname 需要修改的主机名

    [root@localhost ~]# hostnamectl set-hostname node5
    [root@localhost ~]# hostname
    node5
    

    修改主机名之后重启系统,输入账号密码之后就发现主机名已经变成刚才设置的了

    4.3.3 关闭防火墙和selinux

    1.关闭防火墙

    #关闭防火墙
    [root@node5 ~]# systemctl stop firewalld
    
    #禁止防火墙开机自启动
    [root@node5 ~]# systemctl disable firewalld
    
    #查看防火墙是否成功禁止开机自启,命令:systemctl status firewalld.service 	
    #因为在前面已经关掉防火墙和禁止开机自启,所以查看一下防火墙状态即可
    [root@node5 ~]# systemctl status firewalld
    ● firewalld.service - firewalld - dynamic firewall daemon
       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
       Active: inactive (dead)
         Docs: man:firewalld(1)
    
    #查看防火墙是否禁止开机自启动
    [root@node5 ~]# systemctl is-enabled firewalld
    disabled
    

    2.关闭selinux:selinux配置文件的路径:/etc/selinux/config,把SELINUX=enforcing注释,在最后添加一行SELINUX=disabled,保存退出之后重启系统

    [root@node5 ~]# vim /etc/selinux/config 
    
    [root@node5 ~]# cat /etc/selinux/config 
    
    # This file controls the state of SELinux on the system.
    # SELINUX= can take one of these three values:
    #     enforcing - SELinux security policy is enforced.
    #     permissive - SELinux prints warnings instead of enforcing.
    #     disabled - No SELinux policy is loaded.
    SELINUX=disabled
    # SELINUXTYPE= can take one of three two values:
    #     targeted - Targeted processes are protected,
    #     minimum - Modification of targeted policy. Only selected processes are protected. 
    #     mls - Multi Level Security protection.
    SELINUXTYPE=targeted 
    
    #查看selinux是否关闭
    #命令为:getenforce或sestatus -v
    [root@node5 ~]# getenforce
    Disabled
    [root@node5 ~]# sestatus -v
    SELinux status:                 disabled
    

    4.3.4 配置本地yum源

    1.挂载光盘

    [root@node5 ~]# mount /dev/sr0 /media     
    

    2.编辑yum源配置文件,路径:/etc/yum.repos.d

    [root@node5 ~]# vim /etc/yum.repos.d/dvd.repo
    [dvd]			#yum源名称,唯一的,用来区分不同的yum源
    name=yum server		#对yum源描述信息
    baseurl=file:///media  	#yum源的路径(repodata目录所在的目录)
    enabled=1    	#为1,表示启用yum源
    gpgcheck=0   	#为1,表示使用公钥检验rpm的正确性
    

    3.清除缓存信息,更新yum菜单

    [root@node5 ~]# yum clean all 		
    [root@node5 ~]# yum list 			
    

    4.测试yum是否配置成功,能安装软件就成功

    [root@node5 ~]# yum -y install gcc
    

    5.设置开机自动挂载iso镜像文件,把光盘写进/etc/fstab,实现开机自启,命令: echo '/dev/sr0 /media iso9660 defaults 0 0'>>/etc/fstab

    [root@node5 ~]# echo '/dev/sr0 /media iso9660 defaults 0 0'>>/etc/fstab   
    

    4.3.5 创建快照

    选中虚拟机->快照->拍摄快照->名称按自己的需要(我的是配置好yum源的,名称就写yum源已配置)->描述可写可不写(怕自己忘记可以在描述中讲述除了yum源还配置了什么或者做了什么操作)

    image-20201215165019667

    正在做快照

    image-20201215144604254

    五.组建LVM

    1.新添加一块30G的硬盘

    image-20201215170234046

    2.创建挂载点

    [root@node5 ~]# mkdir -p /backup/web /backup/app /backup/tools /backup/logs
    

    3.创建分区(gdisk或者fdisk)

    #lsblk查看磁盘情况,发现新增的磁盘没有出现,重启即可
    [root@node5 ~]# lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0   35G  0 disk 
    ├─sda1            8:1    0    1G  0 part /boot
    └─sda2            8:2    0   19G  0 part 
      ├─centos-root 253:0    0   17G  0 lvm  /
      └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
    sdb               8:16   0    1G  0 disk 
    ├─sdb1            8:17   0   50M  0 part /sdb1
    ├─sdb2            8:18   0    1K  0 part 
    ├─sdb5            8:21   0  200M  0 part /sdb5
    └─sdb6            8:22   0  298M  0 part /sdb6
    sr0              11:0    1 1024M  0 rom  
    
    #重启机器
    [root@node5 ~]# init 6
    
    #新增的磁盘sdc出现了
    [root@node5 ~]# lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0   35G  0 disk 
    ├─sda1            8:1    0    1G  0 part /boot
    └─sda2            8:2    0   19G  0 part 
      ├─centos-root 253:0    0   17G  0 lvm  /
      └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
    sdb               8:16   0    1G  0 disk 
    ├─sdb1            8:17   0   50M  0 part /sdb1
    ├─sdb2            8:18   0    1K  0 part 
    ├─sdb5            8:21   0  200M  0 part /sdb5
    └─sdb6            8:22   0  298M  0 part /sdb6
    sdc               8:32   0   30G  0 disk 
    sr0              11:0    1 1024M  0 rom  
    
    #使用gdisk进行磁盘分区,也可以使用fdisk进行磁盘分区
    [root@node5 ~]# gdisk /dev/sdc 
    GPT fdisk (gdisk) version 0.8.10
    
    Partition table scan:
      MBR: not present
      BSD: not present
      APM: not present
      GPT: not present
    
    Creating new GPT entries.
    
    #新增分区
    Command (? for help): n
    Partition number (1-128, default 1): 
    First sector (34-62914526, default = 2048) or {+-}size{KMGTP}: 
    Last sector (2048-62914526, default = 62914526) or {+-}size{KMGTP}: 
    Current type is 'Linux filesystem'
    #L查看所有分区类型
    Hex code or GUID (L to show codes, Enter = 8300): L
    0700 Microsoft basic data  0c01 Microsoft reserved    2700 Windows RE          
    3000 ONIE boot             3001 ONIE config           4100 PowerPC PReP boot   
    4200 Windows LDM data      4201 Windows LDM metadata  7501 IBM GPFS            
    7f00 ChromeOS kernel       7f01 ChromeOS root         7f02 ChromeOS reserved   
    8200 Linux swap            8300 Linux filesystem      8301 Linux reserved      
    8302 Linux /home           8400 Intel Rapid Start     8e00 Linux LVM           
    a500 FreeBSD disklabel     a501 FreeBSD boot          a502 FreeBSD swap        
    a503 FreeBSD UFS           a504 FreeBSD ZFS           a505 FreeBSD Vinum/RAID  
    a580 Midnight BSD data     a581 Midnight BSD boot     a582 Midnight BSD swap   
    a583 Midnight BSD UFS      a584 Midnight BSD ZFS      a585 Midnight BSD Vinum  
    a800 Apple UFS             a901 NetBSD swap           a902 NetBSD FFS          
    a903 NetBSD LFS            a904 NetBSD concatenated   a905 NetBSD encrypted    
    a906 NetBSD RAID           ab00 Apple boot            af00 Apple HFS/HFS+      
    af01 Apple RAID            af02 Apple RAID offline    af03 Apple label         
    af04 AppleTV recovery      af05 Apple Core Storage    be00 Solaris boot        
    bf00 Solaris root          bf01 Solaris /usr & Mac Z  bf02 Solaris swap        
    bf03 Solaris backup        bf04 Solaris /var          bf05 Solaris /home       
    bf06 Solaris alternate se  bf07 Solaris Reserved 1    bf08 Solaris Reserved 2  
    bf09 Solaris Reserved 3    bf0a Solaris Reserved 4    bf0b Solaris Reserved 5  
    c001 HP-UX data            c002 HP-UX service         ea00 Freedesktop $BOOT   
    eb00 Haiku BFS             ed00 Sony system partitio  ed01 Lenovo system partit
    Press the <Enter> key to see more codes: 
    ef00 EFI System            ef01 MBR partition scheme  ef02 BIOS boot partition 
    fb00 VMWare VMFS           fb01 VMWare reserved       fc00 VMWare kcore crash p
    fd00 Linux RAID     
    #因为我们要创建LVM分区,所以选择8e00 Linux LVM
    Hex code or GUID (L to show codes, Enter = 8300): 8e00
    Changed type of partition to 'Linux LVM'
    
    #打印分区信息
    Command (? for help): p
    Disk /dev/sdc: 62914560 sectors, 30.0 GiB
    Logical sector size: 512 bytes
    Disk identifier (GUID): 572B0DFD-325C-43E9-A641-6D287FB1F121
    Partition table holds up to 128 entries
    First usable sector is 34, last usable sector is 62914526
    Partitions will be aligned on 2048-sector boundaries
    Total free space is 2014 sectors (1007.0 KiB)
    
    Number  Start (sector)    End (sector)  Size       Code  Name
       1            2048        62914526   30.0 GiB    8E00  Linux LVM
    
    #保存退出
    Command (? for help): w
    
    Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
    PARTITIONS!!
    
    Do you want to proceed? (Y/N): Y
    OK; writing new GUID partition table (GPT) to /dev/sdc.
    The operation has completed successfully.
    

    4.创建LVM

    #上一步进行磁盘分区之后,现在出现了/dev/sdc1分区,现在进行格式化成PV
    [root@node5 ~]# ls /dev/sdc*
    /dev/sdc  /dev/sdc1
    
    #创建PV
    [root@node5 ~]# pvcreate /dev/sdc1 
      Physical volume "/dev/sdc1" successfully created.
    
    #创建VG
    [root@node5 ~]# vgcreate diskvg /dev/sdc1
      Volume group "diskvg" successfully created
    
    #创建容量为10G的LV
    [root@node5 ~]# lvcreate -L 10g -n weblv diskvg
      Logical volume "weblv" created.
    
    #创建容量为2G的LV
    [root@node5 ~]# lvcreate -L 2g -n applv diskvg
      Logical volume "applv" created.
    
    #创建容量为10G的LV
    [root@node5 ~]# lvcreate -L 10g -n toolslv diskvg
      Logical volume "toolslv" created.
    
    #创建容量为1G的LV
    [root@node5 ~]# lvcreate -L 1g -n logslv diskvg
      Logical volume "logslv" created.
    

    5.格式化

    #把LV格式化为xfs文件系统
    [root@node5 ~]# mkfs.xfs /dev/diskvg/weblv 
    meta-data=/dev/diskvg/weblv      isize=512    agcount=4, agsize=655360 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0, sparse=0
    data     =                       bsize=4096   blocks=2621440, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal log           bsize=4096   blocks=2560, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    [root@node5 ~]# 
    [root@node5 ~]# 
    [root@node5 ~]# mkfs.xfs /dev/diskvg/applv 
    meta-data=/dev/diskvg/applv      isize=512    agcount=4, agsize=131072 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0, sparse=0
    data     =                       bsize=4096   blocks=524288, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal log           bsize=4096   blocks=2560, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    [root@node5 ~]# 
    [root@node5 ~]# 
    [root@node5 ~]# mkfs.xfs /dev/diskvg/toolslv 
    meta-data=/dev/diskvg/toolslv    isize=512    agcount=4, agsize=655360 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0, sparse=0
    data     =                       bsize=4096   blocks=2621440, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal log           bsize=4096   blocks=2560, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    [root@node5 ~]# 
    [root@node5 ~]# mkfs.xfs /dev/diskvg/logslv 
    meta-data=/dev/diskvg/logslv     isize=512    agcount=4, agsize=65536 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0, sparse=0
    data     =                       bsize=4096   blocks=262144, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal log           bsize=4096   blocks=2560, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    

    6.把逻辑卷挂载到目录

    #把LV挂载到目录上
    [root@node5 ~]# mount /dev/mapper/diskvg-weblv /backup/web/
    [root@node5 ~]# 
    [root@node5 ~]# mount /dev/mapper/diskvg-applv /backup/app/
    [root@node5 ~]# 
    [root@node5 ~]# mount /dev/mapper/diskvg-toolslv /backup/tools/
    [root@node5 ~]# 
    [root@node5 ~]# mount /dev/mapper/diskvg-logslv /backup/logs/
    

    7.设置开机自动挂载分区

    #blkid查看分区的UUID
    [root@node5 ~]# blkid
    /dev/sdb1: UUID="ddcb232e-96ca-4e54-935a-3100e81dbce4" TYPE="xfs" 
    /dev/sdb5: UUID="ddb20b01-0912-4c95-a304-980dc5c70659" TYPE="ext4" 
    /dev/sdb6: UUID="457d31a7-28d8-424d-87fe-cca3fe9b907c" TYPE="xfs" 
    /dev/sda1: UUID="6503b4ad-2975-4152-a824-feb7bea1b622" TYPE="xfs" 
    /dev/sda2: UUID="nqZ4uJ-ksnN-KzYS-N42b-00m3-Ohc2-BJXunP" TYPE="LVM2_member" 
    /dev/sdc1: UUID="1OMTEO-ewOI-eSfH-QkM4-3yy2-fAFE-GljDN7" TYPE="LVM2_member" PARTLABEL="Linux LVM" PARTUUID="5f8c525f-e394-4e11-a6c1-d4ee4b82dd1f" 
    /dev/mapper/centos-root: UUID="c1d38b37-821d-48e7-8727-3937ccc657a4" TYPE="xfs" 
    /dev/mapper/centos-swap: UUID="c2fcaf11-42d8-4e4c-bf9e-6464f0777198" TYPE="swap" 
    /dev/mapper/diskvg-weblv: UUID="5fcc4412-52b3-46b0-b428-8d57d590964c" TYPE="xfs" 
    /dev/mapper/diskvg-applv: UUID="041e2bd3-9115-4ab7-9151-1382006945c0" TYPE="xfs" 
    /dev/mapper/diskvg-toolslv: UUID="27397965-9079-4cd1-8140-4063b4c8b255" TYPE="xfs" 
    /dev/mapper/diskvg-logslv: UUID="e1eb72f4-cf6c-419e-9ef5-67a021437d8c" TYPE="xfs" 
    
    [root@node5 ~]# echo "UUID=5fcc4412-52b3-46b0-b428-8d57d590964c /backup/web/ xfs defaults 0 0" >> /etc/fstab 
     
    [root@node5 ~]# echo "UUID=041e2bd3-9115-4ab7-9151-1382006945c0 /backup/app/ xfs defaults 0 0" >> /etc/fstab 
     
    [root@node5 ~]# echo "UUID=27397965-9079-4cd1-8140-4063b4c8b255 /backup/tools/ xfs defaults 0 0" >> /etc/fstab 
    
    [root@node5 ~]# echo "UUID=e1eb72f4-cf6c-419e-9ef5-67a021437d8c /backup/logs/ xfs defaults 0 0" >> /etc/fstab 
     
    [root@node5 ~]# cat /etc/fstab 
    #
    # /etc/fstab
    # Created by anaconda on Fri Apr 26 17:09:16 2019
    #
    # Accessible filesystems, by reference, are maintained under '/dev/disk'
    # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
    #
    /dev/mapper/centos-root /                       xfs     defaults        0 0
    UUID=6503b4ad-2975-4152-a824-feb7bea1b622 /boot                   xfs     defaults        0 0
    /dev/mapper/centos-swap swap                    swap    defaults        0 0
    192.168.110.180:/webapp /usr/local/apache-tomcat-8.0.51/webapps/ROOT/ nfs _netdev 0 0
    /dev/sdb1  /sdb1 xfs defaults 0 0 
    /dev/sdb5  /sdb5 ext4 defaults 0 0 
    /dev/sdb6  /sdb6 xfs defaults 0 0 
    UUID=5fcc4412-52b3-46b0-b428-8d57d590964c /backup/web/ xfs defaults 0 0
    UUID=041e2bd3-9115-4ab7-9151-1382006945c0 /backup/app/ xfs defaults 0 0
    UUID=27397965-9079-4cd1-8140-4063b4c8b255 /backup/tools/ xfs defaults 0 0
    UUID=e1eb72f4-cf6c-419e-9ef5-67a021437d8c /backup/logs/ xfs defaults 0 0
     
    #mount -a命令自动挂载/etc/fstab里的分区
    [root@node5 ~]# mount -a
    

    8.查看最终分区情况

    [root@node5 ~]# df -h
    Filesystem                  Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root      17G   13G  4.4G  75% /
    devtmpfs                    3.9G     0  3.9G   0% /dev
    tmpfs                       3.9G  8.0K  3.9G   1% /dev/shm
    tmpfs                       3.9G  8.8M  3.9G   1% /run
    tmpfs                       3.9G     0  3.9G   0% /sys/fs/cgroup
    /dev/sdb5                   190M  1.6M  175M   1% /sdb5
    /dev/sdb1                    47M  2.7M   45M   6% /sdb1
    /dev/sda1                  1014M  125M  890M  13% /boot
    /dev/sdb6                   295M   16M  280M   6% /sdb6
    tmpfs                       785M     0  785M   0% /run/user/0
    /dev/mapper/diskvg-weblv     10G   33M   10G   1% /backup/web
    /dev/mapper/diskvg-applv    2.0G   33M  2.0G   2% /backup/app
    /dev/mapper/diskvg-toolslv   10G   33M   10G   1% /backup/tools
    /dev/mapper/diskvg-logslv  1014M   33M  982M   4% /backup/logs
    

    六.使用yum安装apache服务

    1.查看是否已经安装了apache,没有就用yum安装。

    #查看有无httpd的包,没有就代表没有安装httpd服务
    [root@node5 ~]# rpm -qa | grep httpd   
    
    #yum安装会解决依赖包的问题
    #安装httpd、mariadb服务
    [root@node5 ~]# yum -y install httpd mariadb-server mysql mariadb	
    

    2.查看httpd服务状态

    [root@node5 ~]# systemctl status httpd
    ● httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
       Active: inactive (dead)
         Docs: man:httpd(8)
               man:apachectl(8)
    

    3.开启httpd服务

    [root@node5 ~]# systemctl start httpd
    [root@node5 ~]# systemctl status httpd
    ● httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
       Active: active (running) since Tue 2020-12-15 18:04:28 CST; 2s ago
         Docs: man:httpd(8)
               man:apachectl(8)
     Main PID: 4529 (httpd)
       Status: "Processing requests..."
       CGroup: /system.slice/httpd.service
               ├─4529 /usr/sbin/httpd -DFOREGROUND
               ├─4530 /usr/sbin/httpd -DFOREGROUND
               ├─4531 /usr/sbin/httpd -DFOREGROUND
               ├─4532 /usr/sbin/httpd -DFOREGROUND
               ├─4533 /usr/sbin/httpd -DFOREGROUND
               └─4534 /usr/sbin/httpd -DFOREGROUND
    
    Dec 15 18:04:28 node5 systemd[1]: Starting The Apache HTTP Server...
    Dec 15 18:04:28 node5 httpd[4529]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.110.184. Set the 'ServerName' directive globally to suppress this message
    Dec 15 18:04:28 node5 systemd[1]: Started The Apache HTTP Server.
    Hint: Some lines were ellipsized, use -l to show in full.
    
    #停止服务的命令是:
    [root@node5 ~]# systemctl stop httpd
    
    #把httpd设置为开机自启动
    [root@node5 ~]# systemctl enable httpd
    

    4.测试能否访问:使用浏览器访问IP地址即可,比如:http://192.168.110.184/,如果出现以下界面,说明Apache服务安装成功,功能正常。

    image-20201215180840723

    5.把/etc/passwd复制到/var/www/html,并改名为index.html

    [root@node5 ~]# cp /etc/passwd /var/www/html/index.html
    cp: overwrite ‘/var/www/html/index.html’? y
    

    6.使用浏览器进行访问

    image-20201215181212540

    通过上面的测试,httpd能正常访问,apache服务搭建完成。

    七.自动备份数据

    1.创建备份脚本和上传脚本

    #创建备份脚本:备份/var/www/html目录下的日志
    [root@node5 ~]# vim ~/backup.sh
    [root@node5 ~]# cat ~/backup.sh
    #!/bin/bash
    find /backup -name "*_tar.gz" -mtime +5 -delete  &> /dev/null
    tar -zcvf /backup/`date +%Y-%m-%d`_tar.gz /var/www/html  &> /dev/null
    
    [root@node5 ~]# chmod +x ~/backup.sh
    
    #创建上传脚本:把192.168.110.184的备份文件上传给192.168.110.186
    [root@node5 ~]# vim ~/upload.sh
    #!/bin/bash
    IP=192.168.110.186
    DIR=/backup
    scp $DIR/*_tar.gz root@$IP:$DIR  &> /dev/null
    
    [root@node5 ~]# chmod +x ~/upload.sh
    

    2.设置定时任务

    #设置定时任务
    [root@node5 ~]# crontab -e
    [root@node5 ~]# crontab -l
    30 1 * * * bash ~/backup.sh
    0 5 * * * bash ~/upload.sh
    

    3.由于需要把192.168.110.184的备份文件上传给192.168.110.186,所以配置node5和node8之间ssh免密登录

    [root@node5 ~]# ssh-keygen
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa): 
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /root/.ssh/id_rsa.
    Your public key has been saved in /root/.ssh/id_rsa.pub.
    The key fingerprint is:
    SHA256:4Sb6zDBrHbGlK0aOhQs9ityD19qQbWAGNPDYiYtm1zU root@node5
    The key's randomart image is:
    +---[RSA 2048]----+
    |oo               |
    |.=..             |
    |o.+    E.        |
    |... . o.o.       |
    |o+ * ..=S        |
    |+ B *.+o         |
    |oooX=+ o         |
    |ooo+OOo          |
    |  .++o+          |
    +----[SHA256]-----+
    
    [root@node5 ~]# ssh-copy-id root@192.168.110.186
    /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
    /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
    /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
    root@192.168.110.186's password: 
    
    Number of key(s) added: 1
    
    Now try logging into the machine, with:   "ssh 'root@192.168.110.186'"
    and check to make sure that only the key(s) you wanted were added.
    

    4.创建node8的接收备份文件的目录

    [root@node8 ~]# mkdir /backup
    [root@node8 ~]# systemctl restart crond  #重启crond服务
    [root@node8 ~]# systemctl enable crond   #设置开机自启动
    
  • 相关阅读:
    JavaScript DOM 编程艺术(第2版)读书笔记(3)
    JavaScript DOM 编程艺术(第2版)读书笔记(1)
    css杂记
    2020年11月15日
    2020年11月14日
    2020年11月13日
    2020年11月12日
    《代码大全》阅读笔记04
    2020年11月11日
    2020年11月10日
  • 原文地址:https://www.cnblogs.com/renshengdezheli/p/14140341.html
Copyright © 2020-2023  润新知