59 openEuler 22.03-LTS 搭建MySQL數(shù)據(jù)庫服務(wù)器-軟件介紹和配置環(huán)境59.1 軟件介紹59.2 配置環(huán)境59.2.1 關(guān)閉防火墻并取消開機(jī)自啟動(dòng)59.2.2 修改SELINUX為disabled59.2.3 創(chuàng)建組和用戶59.2.4 創(chuàng)建數(shù)據(jù)盤59.2.4.1 方法一:在root權(quán)限下使用fdisk進(jìn)行磁盤管理59.2.4.1 方法二:在root權(quán)限下使用LVM進(jìn)行磁盤管理59.2.5 創(chuàng)建數(shù)據(jù)庫目錄并且授權(quán)
59 openEuler 22.03-LTS 搭建MySQL數(shù)據(jù)庫服務(wù)器-軟件介紹和配置環(huán)境
59.1 軟件介紹
MySQL是一個(gè)關(guān)系型數(shù)據(jù)庫管理系統(tǒng)洪乍,由瑞典MySQL AB公司開發(fā),目前屬于Oracle旗下產(chǎn)品夜焦。MySQL是業(yè)界最流行的RDBMS (Relational Database Management System壳澳,關(guān)系數(shù)據(jù)庫管理系統(tǒng))之一,尤其在WEB應(yīng)用方面茫经。
關(guān)系數(shù)據(jù)庫將數(shù)據(jù)保存在不同的表中巷波,而不是將所有數(shù)據(jù)放在一個(gè)大倉庫內(nèi),這樣就加快了速度并提高了靈活性卸伞。
MySQL所使用的SQL語言是用于訪問數(shù)據(jù)庫的最常用標(biāo)準(zhǔn)化語言抹镊。MySQL軟件采用了雙授權(quán)模式,分為社區(qū)版和商業(yè)版荤傲,由于其體積小髓考、速度快、總體擁有成本低弃酌,尤其是開放源碼這一特點(diǎn)氨菇,一般中小型網(wǎng)站的開發(fā)都選擇MySQL作為網(wǎng)站數(shù)據(jù)庫。
59.2 配置環(huán)境
[圖片上傳失敗...(image-357013-1682169715708)]
說明: 以下環(huán)境配置僅為參考示例妓湘,具體配置視實(shí)際需求做配置
59.2.1 關(guān)閉防火墻并取消開機(jī)自啟動(dòng)
[圖片上傳失敗...(image-a7f99a-1682169715708)]
說明: 測(cè)試環(huán)境下通常會(huì)關(guān)閉防火墻以避免部分網(wǎng)絡(luò)因素影響查蓉,視實(shí)際需求做配置。
-
在root權(quán)限下停止防火墻榜贴。
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n18" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># systemctl stop firewalld</pre>
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n20" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# systemctl stop firewalld
[root@superman-21 ~]# </pre> -
在root權(quán)限下關(guān)閉防火墻豌研。
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n23" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># systemctl disable firewalld</pre>
[圖片上傳失敗...(image-29b2bc-1682169715704)]
說明: 執(zhí)行disable命令關(guān)閉防火墻的同時(shí),也取消了開機(jī)自啟動(dòng)唬党。
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n27" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# systemctl disable firewalld
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
[root@superman-21 ~]# </pre>
59.2.2 修改SELINUX為disabled
-
永久關(guān)閉鹃共,在root權(quán)限下修改配置文件。
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n32" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux</pre>
[圖片上傳失敗...(image-5414e7-1682169715704)]
說明:
重啟后生效驶拱。
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n37" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
[root@superman-21 ~]#
[root@superman-21 ~]# cat /etc/sysconfig/selinuxThis 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 these three values:
targeted - Targeted processes are protected,
minimum - Modification of targeted policy. Only selected processes are protected.
mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@superman-21 ~]#</pre>
-
臨時(shí)關(guān)閉
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n40" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># setenforce 0</pre>
[圖片上傳失敗...(image-6f7dbe-1682169715704)]
說明:
即時(shí)生效霜浴,但重啟后會(huì)自動(dòng)開啟。
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n45" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# setenforce 0
setenforce: SELinux is permissive
[root@superman-21 ~]# </pre>
59.2.3 創(chuàng)建組和用戶
[圖片上傳失敗...(image-b4485-1682169715708)]
說明: 服務(wù)器環(huán)境下蓝纲,為了系統(tǒng)安全阴孟,通常會(huì)為進(jìn)程分配單獨(dú)的用戶晌纫,以實(shí)現(xiàn)權(quán)限隔離。本章節(jié)創(chuàng)建的組和用戶都是操作系統(tǒng)層面的永丝,不是數(shù)據(jù)庫層面的锹漱。
-
在root權(quán)限下創(chuàng)建MySQL用戶(組)。
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n52" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># groupadd mysql
useradd -g mysql mysql</pre>
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n54" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# groupadd mysql
[root@superman-21 ~]#
[root@superman-21 ~]# useradd -g mysql mysql
[root@superman-21 ~]# </pre> -
在root權(quán)限下設(shè)置MySQL用戶密碼慕嚷。
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n57" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># passwd mysql</pre>
需要重復(fù)輸入密碼(根據(jù)實(shí)際需求設(shè)置密碼)哥牍。
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n60" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# passwd mysql
更改用戶 mysql 的密碼 。
新的密碼:
重新輸入新的密碼:
passwd:所有的身份驗(yàn)證令牌已經(jīng)成功更新喝检。
[root@superman-21 ~]# </pre>
59.2.4 創(chuàng)建數(shù)據(jù)盤
[圖片上傳失敗...(image-a46b13-1682169715708)]
說明:
- 進(jìn)行性能測(cè)試時(shí)砂心,數(shù)據(jù)目錄使用單獨(dú)硬盤,需要對(duì)硬盤進(jìn)行格式化并掛載蛇耀,參考方法一或者方法二
- 非性能測(cè)試時(shí)辩诞,在root權(quán)限下執(zhí)行以下命令,創(chuàng)建數(shù)據(jù)目錄即可纺涤。然后跳過本小節(jié): # mkdir /data
59.2.4.1 方法一:在root權(quán)限下使用fdisk進(jìn)行磁盤管理
-
創(chuàng)建分區(qū)(以/dev/sdb為例译暂,根據(jù)實(shí)際情況創(chuàng)建)
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n73" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># fdisk /dev/sdb</pre>
輸入n,按回車確認(rèn)撩炊。
輸入p外永,按回車確認(rèn)。
輸入1拧咳,按回車確認(rèn)伯顶。
采用默認(rèn)配置,按回車確認(rèn)骆膝。
采用默認(rèn)配置祭衩,按回車確認(rèn)。
-
輸入w阅签,按回車保存掐暮。
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n87" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# fdisk /dev/sdb
歡迎使用 fdisk (util-linux 2.37.2)。
更改將停留在內(nèi)存中政钟,直到您決定將更改寫入磁盤路克。
使用寫入命令前請(qǐng)三思。設(shè)備不包含可識(shí)別的分區(qū)表养交。
創(chuàng)建了一個(gè)磁盤標(biāo)識(shí)符為 0x9ac1f07b 的新 DOS 磁盤標(biāo)簽精算。命令(輸入 m 獲取幫助):n
分區(qū)類型
p 主分區(qū) (0 primary, 0 extended, 4 free)
e 擴(kuò)展分區(qū) (邏輯分區(qū)容器)
選擇 (默認(rèn) p):p
分區(qū)號(hào) (1-4, 默認(rèn) 1): 1
第一個(gè)扇區(qū) (2048-41943039, 默認(rèn) 2048):
最后一個(gè)扇區(qū),+/-sectors 或 +size{K,M,G,T,P} (2048-41943039, 默認(rèn) 41943039):創(chuàng)建了一個(gè)新分區(qū) 1碎连,類型為“Linux”灰羽,大小為 20 GiB。
命令(輸入 m 獲取幫助):w
分區(qū)表已調(diào)整。
將調(diào)用 ioctl() 來重新讀分區(qū)表谦趣。
正在同步磁盤疲吸。[root@superman-21 ~]# </pre>
-
創(chuàng)建文件系統(tǒng)(以xfs為例座每,根據(jù)實(shí)際需求創(chuàng)建文件系統(tǒng))
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n90" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># mkfs.xfs /dev/sdb1</pre>
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n92" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=1310656 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=0 inobtcount=0
data = bsize=4096 blocks=5242624, 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@superman-21 ~]# </pre> -
創(chuàng)建“/data”文件夾以供操作系統(tǒng)掛載分區(qū)使用前鹅。
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n95" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># mkdir /data</pre>
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n97" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# mkdir /data
[root@superman-21 ~]# </pre> 執(zhí)行命令編輯“/etc/fstab”使重啟后自動(dòng)掛載數(shù)據(jù)盤。
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n100" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># echo "/dev/sdb1 /data xfs defaults 1 1" >> /etc/fstab</pre>
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n102" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Nov 28 13:29:03 2022
#
# 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/vg00-lv_root / ext4 defaults 1 1
UUID=70c4f6e0-20be-46f8-93ba-97c8083bc37a /boot ext4 defaults 1 2
/dev/mapper/vg00-lv_swap none swap defaults 0 0
[root@superman-21 ~]#
[root@superman-21 ~]# echo "/dev/sdb1 /data xfs defaults 1 1" >> /etc/fstab
[root@superman-21 ~]#
[root@superman-21 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Nov 28 13:29:03 2022
#
# 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/vg00-lv_root / ext4 defaults 1 1
UUID=70c4f6e0-20be-46f8-93ba-97c8083bc37a /boot ext4 defaults 1 2
/dev/mapper/vg00-lv_swap none swap defaults 0 0
/dev/sdb1 /data xfs defaults 1 1
[root@superman-21 ~]# </pre>
- 掛載數(shù)據(jù)盤峭梳。
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n105" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># mount -a</pre>
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n107" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# df -h
文件系統(tǒng) 容量 已用 可用 已用% 掛載點(diǎn)
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 1.7G 12K 1.7G 1% /dev/shm
tmpfs 677M 9.1M 668M 2% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
/dev/mapper/vg00-lv_root 41G 2.9G 36G 8% /
tmpfs 1.7G 0 1.7G 0% /tmp
/dev/sda1 974M 249M 659M 28% /boot
[root@superman-21 ~]#
[root@superman-21 ~]# mount -a
[root@superman-21 ~]#
[root@superman-21 ~]# df -h
文件系統(tǒng) 容量 已用 可用 已用% 掛載點(diǎn)
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 1.7G 12K 1.7G 1% /dev/shm
tmpfs 677M 9.1M 668M 2% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
/dev/mapper/vg00-lv_root 41G 2.9G 36G 8% /
tmpfs 1.7G 0 1.7G 0% /tmp
/dev/sda1 974M 249M 659M 28% /boot
/dev/sdb1 20G 175M 20G 1% /data
[root@superman-21 ~]#</pre>
59.2.4.1 方法二:在root權(quán)限下使用LVM進(jìn)行磁盤管理
[圖片上傳失敗...(image-71f8f8-1682169715707)]
說明: 此步驟需要安裝鏡像中的lvm2相關(guān)包舰绘,步驟如下:
- 配置本地yum源,詳細(xì)信息請(qǐng)參考《openEuler 22.03-LTS 搭建repo服務(wù)器》葱椭。如果已經(jīng)執(zhí)行捂寿,則可跳過此步。
- 在root權(quán)限下執(zhí)行命令安裝lvm2孵运。 # yum install lvm2
-
創(chuàng)建物理卷(sdb為硬盤名稱秦陋,具體名字以實(shí)際為準(zhǔn))。
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n119" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># pvcreate /dev/sdb</pre>
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n121" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
[root@superman-21 ~]# </pre> -
創(chuàng)建物理卷組(其中vg_data為創(chuàng)建的卷組名稱治笨,具體名字以實(shí)際規(guī)劃為準(zhǔn))驳概。
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n124" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># vgcreate vg_data /dev/sdb</pre>
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n126" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# vgcreate vg_data /dev/sdb
Volume group "vg_data" successfully created
[root@superman-21 ~]# </pre> -
創(chuàng)建邏輯卷(其中20G為規(guī)劃的邏輯卷大小,具體大小以實(shí)際情況為準(zhǔn)旷赖;lv_data為創(chuàng)建的邏輯卷的名字顺又,具體名稱以實(shí)際規(guī)劃為準(zhǔn)。)等孵。
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n129" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># lvcreate -L 20476M -n lv_data vg_data</pre>
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n131" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# lvcreate -L 20476M -n lv_data vg_data
Logical volume "lv_data" created.
[root@superman-21 ~]# </pre> -
創(chuàng)建文件系統(tǒng)稚照。
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n134" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># mkfs.xfs /dev/vg_data/lv_data</pre>
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n136" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# mkfs.xfs /dev/vg_data/lv_data
meta-data=/dev/vg_data/lv_data isize=512 agcount=4, agsize=1310464 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=0 inobtcount=0
data = bsize=4096 blocks=5241856, 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@superman-21 ~]# </pre> -
創(chuàng)建“/data”文件夾以供操作系統(tǒng)掛載分區(qū)使用。
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n139" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># mkdir /data</pre>
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n141" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# mkdir /data
[root@superman-21 ~]# </pre> -
執(zhí)行命令編輯“/etc/fstab”使重啟后自動(dòng)掛載數(shù)據(jù)盤俯萌。
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n144" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># echo "/dev/vg_data/lv_data /data xfs defaults 1 1" >> /etc/fstab</pre>
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n146" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# cat /etc/fstab
/etc/fstab
Created by anaconda on Mon Nov 28 13:29:03 2022
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.
After editing this file, run 'systemctl daemon-reload' to update systemd
units generated from this file.
/dev/mapper/vg00-lv_root / ext4 defaults 1 1
UUID=70c4f6e0-20be-46f8-93ba-97c8083bc37a /boot ext4 defaults 1 2
/dev/mapper/vg00-lv_swap none swap defaults 0 0
[root@superman-21 ~]#
[root@superman-21 ~]# echo "/dev/vg_data/lv_data /data xfs defaults 1 1" >> /etc/fstab
[root@superman-21 ~]#
[root@superman-21 ~]# cat /etc/fstab/etc/fstab
Created by anaconda on Mon Nov 28 13:29:03 2022
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.
After editing this file, run 'systemctl daemon-reload' to update systemd
units generated from this file.
/dev/mapper/vg00-lv_root / ext4 defaults 1 1
UUID=70c4f6e0-20be-46f8-93ba-97c8083bc37a /boot ext4 defaults 1 2
/dev/mapper/vg00-lv_swap none swap defaults 0 0
/dev/vg_data/lv_data /data xfs defaults 1 1
[root@superman-21 ~]# </pre> -
掛載數(shù)據(jù)盤果录。
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n149" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;"># mount -a</pre>
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n151" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit;">[root@superman-21 ~]# df -h
文件系統(tǒng) 容量 已用 可用 已用% 掛載點(diǎn)
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 1.7G 12K 1.7G 1% /dev/shm
tmpfs 677M 9.1M 668M 2% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
/dev/mapper/vg00-lv_root 41G 2.9G 36G 8% /
tmpfs 1.7G 0 1.7G 0% /tmp
/dev/sda1 974M 249M 659M 28% /boot
[root@superman-21 ~]#
[root@superman-21 ~]# mount -a
[root@superman-21 ~]#
[root@superman-21 ~]# df -h
文件系統(tǒng) 容量 已用 可用 已用% 掛載點(diǎn)
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 1.7G 12K 1.7G 1% /dev/shm
tmpfs 677M 9.1M 668M 2% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
/dev/mapper/vg00-lv_root 41G 2.9G 36G 8% /
tmpfs 1.7G 0 1.7G 0% /tmp
/dev/sda1 974M 249M 659M 28% /boot
/dev/mapper/vg_data-lv_data 20G 175M 20G 1% /data
[root@superman-21 ~]#</pre>
59.2.5 創(chuàng)建數(shù)據(jù)庫目錄并且授權(quán)
在已創(chuàng)建的數(shù)據(jù)目錄 /data 基礎(chǔ)上,使用root權(quán)限繼續(xù)創(chuàng)建進(jìn)程所需的相關(guān)目錄并授權(quán)MySQL用戶(組)咐熙。
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n154" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># mkdir -p /data/mysql
cd /data/mysql
mkdir data tmp run log
chown -R mysql:mysql /data</pre>
例如示例命令如下:
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n156" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@superman-21 ~]# mkdir -p /data/mysql
[root@superman-21 ~]#
[root@superman-21 ~]# cd /data/mysql
[root@superman-21 mysql]#
[root@superman-21 mysql]# mkdir data tmp run log
[root@superman-21 mysql]#
[root@superman-21 mysql]# chown -R mysql:mysql /data
[root@superman-21 mysql]# </pre>
?? 點(diǎn)贊雕憔,你的認(rèn)可是我創(chuàng)作的動(dòng)力!
?? 收藏糖声,你的青睞是我努力的方向斤彼!
?? 評(píng)論,你的意見是我進(jìn)步的財(cái)富蘸泻!