【說明】
前面使用yml文件創建MySQL數據庫及持久化數據,創建配置文件相對比較繁瑣一些,這里使用rancher直接創建MySQL數據庫並持久化數據;
【當前k3s信息】
【安裝nfs】
安裝涉及NFS的依賴包,主節點安裝
yum -y install nfs-utils rpcbind
分配權限
mkdir -p /nfsdata
chmod 755 -R /nfsdata
配置掛載
cat >> /etc/exports <<EOF
/nfsdata 192.168.205.0/24(rw,no_root_squash)
EOF
#啟動rpc跟nfs
systemctl start rpcbind.service
systemctl status rpcbind.service
systemctl start nfs.service
systemctl status nfs.service
systemctl enable rpcbind.service
systemctl enable nfs.service
master節點查看信息:
exportfs -arv
showmount -e
work節點查看信息
yum -y install nfs-utils rpcbind
#啟動rpc跟nfs
systemctl start rpcbind.service
systemctl status rpcbind.service
systemctl start nfs.service
systemctl status nfs.service
systemctl enable rpcbind.service
systemctl enable nfs.service
創建掛載的目錄
mkdir -p /nfsdata
編輯開機啟動/etc/fstab
192.168.205.152:/nfsdata /nfsdata nfs defaults 0 0
mount -a
df -h
【使用rancher創建pv】
正常狀態
【使用rancher創建PVC】
正常狀態
【部署服務】
nfs目錄下面創建目錄
mkdir -p /nfsdata/mysqlmaster/data 數據目錄
mkdir -p /nfsdata/mysqlmaster/conf 配置文件目錄
添加配置文件
cd /nfsdata/mysqlmaster/conf
cat >my.cnf
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL
server_id = 252
# Custom config should go here
!includedir /etc/mysql/conf.d/
rancher添加服務
查看數據庫信息
查看狀態
【拷貝數據作為從庫】
將nfs上面的master直接復制一份跟修改權限
cp -r mysqlmaster/ mysqlslave
chmod 755 mysqlslave/
chown -R systemd-bus-proxy:root mysqlslave
修改配置文件
vim /nfsdata/mysqlslave/conf/my.cnf
server_id = 250
rm /nfsdata/mysqlslave/data/auto.cnf
rancher啟動這個從庫
查看狀態:
部署MySQL主從配置
按照物理主機方式配置主從即可,注意參數
查看主從狀態