一.專案目標
根據公司要求:整合一套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.在虛擬機器的主頁上點選建立新的虛擬主機
2.選擇自定義,然後下一步
3.一直預設下一步,直到選擇安裝源時選擇稍後安裝系統
4.客戶機的作業系統選擇linux,由於我們需要安裝的時rhel7.5 64位的系統,所以在下面的版本選擇Red Hat Enterprise Linux 7 64 位,
然後下一步
5.選擇虛擬機器的名稱和虛擬機器安裝的位置,路徑最好是自己選擇,這樣方便以後做遷移
6.一路預設,在選擇網路的時候選擇僅主機模式
7.一直下一步,直到選擇磁碟,選擇建立新虛擬磁碟,點選下一步
8.選擇磁碟的容量和磁碟是否為單個檔案,本人在這裡的選擇是磁碟大小20G,為單個檔案,點選下一步
9.在這一步可以自定義硬體,也可以點選完成,在後面在完善虛擬機器的硬體資訊,本人是選擇之後再配置硬體資訊,所以是直接點選完成
10.配置完成之後可以在介面看到配置好的主機資訊
選擇編輯虛擬機器設定
11.由於音效卡和印表機可以不要,所以可以點選移除,而安裝系統需要映象即iso檔案,所以在CD/DVD選擇你的映象檔案
12.自此,虛擬機器的配置就完成了,下面開始安裝作業系統。
4.2 安裝作業系統
1.點選開啟此虛擬機器
介面說明:
Install Red Hat Enterprise Linux 7.2 安裝RHEL7.2
Test this media & install Red HatEnterprise Linux 7.2 測試安裝檔案並安裝RHEL 7.2
Troubleshooting 修復故障
2.在這一步可以點選回車繼續安裝,或者等待一會自動繼續安裝
3.選擇語言:簡體中文(新手選擇中文,老手選擇英文)
4.需要把介面上的都配置好才可以進行下一步的安裝,本地化的日期和時間、鍵盤和語言支援都選預設,不用修改
5.把SECURITY的開啟改為關閉
6.選擇伺服器的軟體安裝,這裡選擇的是帶GUI的伺服器,但是由於在實際環境中都是通過xshell、crt這些遠端工具連線的,所以後期安裝好系統之後也會用遠端工具進行連線
7.選擇安裝位置,進行磁碟分割槽
8.選擇-其它儲存選項-分割槽-我要配置分割槽,點左上角的“完成”,進入下面的介面,在分割槽方案有標準分割槽,btrfs,LVM,LVM簡單配置,這裡預設LVM就可以,然後單擊"+"建立新的分割槽,分割槽提前規劃好,一般swap分割槽為實體記憶體的1.5~2倍,/boot分割槽300M-500M,/home分割槽給2G,剩餘的空間全部給/分割槽,實際工作中可以建立資料分割槽,一般把資料和系統分開
建立/boot分割槽
9.裝置型別選擇預設的標準分割槽,檔案系統型別為xfs,RHEL7支援brtfs,生產環境不建議選擇,btrfs檔案系統目前技術尚未成熟,只是作為一種前瞻技術
10.建立/swap分割槽
11.建立/home分割槽
12.建立/分割槽(期望容量不填,代表把剩餘的所有空間都給/分割槽)
13.選擇接受更改(這裡相當於windows的格式化分割槽)
14.配置網路,選擇開啟,開啟之後會自動獲取一個ip,如果需要手動配置的話,可以選擇配置,也可以在系統安裝完成之後再進行配置,在這裡就先不配置,等安裝好系統之後再進行配置,然後點選開始安裝
15.設定root密碼,這裡提示密碼強度較差,因為是虛擬機器所以密碼不用太複雜,但在實際環境中,密碼的設定需要符合安全性的標準
16.下圖代表作業系統正在安裝,等待即可
17.安裝完成之後,點選重啟,進行最後的配置
18.進入啟動介面
19.首次啟動許可配置,選擇同意許可協議即可
20.點選完成配置
21.最後確認語言和鍵盤輸入
22.配置時區,如果在前面開啟了網路,這裡會自動獲取時區,如果沒有開啟的話,可以選擇shangghai會自動出現相關的選項
23.配置登陸的個人賬號密碼
24.系統到這裡已經正式安裝完成
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
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源還配置了什麼或者做了什麼操作)
正在做快照
五.組建LVM
1.新新增一塊30G的硬碟
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服務安裝成功,功能正常。
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.使用瀏覽器進行訪問
通過上面的測試,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 #設定開機自啟動