Mysql 集群技术

ops/2024/10/19 4:20:51/

一、Mysql 在服务器中的部署方法

  • 在企业中90%的服务器操作系统均为Linux
  • 在企业中对于Mysql的安装通常用源码编译的方式来进行
  • 官网:http://www.mysql.com

1.1 在Linux下部署mysql

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #指定安装路径
-DMYSQL_DATADIR=/data/mysql \ #指定数据目录
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \ #指定套接字文件
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ #指定启用INNODB存储引擎,默认用myisam
-DWITH_EXTRA_CHARSETS=all \ #扩展字符集
-DDEFAULT_CHARSET=utf8mb4 \ #指定默认字符集
-DDEFAULT_COLLATION=utf8mb4_unicode_ci \ #指定默认校验字符集
-DWITH_BOOST=/root/mysql-5.7.44/boost/boost_1_59_0/ #指定c++库依赖make -j2 #-j2 表示有几个核心就跑几个进程

1.1.1 安装依赖性

#下载源码安装需要用到的软件[root@mysql-node1 ~]# yum  install cmake gcc-c++ openssl-devel -y
[root@mysql-node1 ~]# yum install ncurses-devel.x86_64   rpcgen.x86_64  -y#导入libtirpc-devel-0.2.4-0.16.el7.x86_64.rpm
[root@mysql-node1 ~]# yum install libtirpc-devel-0.2.4-0.16.el7.x86_64.rpm -y

1.1.2 下载并解压源码包

#导入mysql-boost-5.7.44.tar.gz
[root@mysql-node1 ~]# tar zxf mysql-boost-5.7.44.tar.gz 

 1.1.3 源码编译安装mysql

[root@mysql-node1 ~]# cd mysql-5.7.44/[root@mysql-node1 mysql-5.7.44]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_EXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_unicode_ci -DWITH_BOOST=/root/mysql-5.7.44/boost/boost_1_59_0/ [root@mysql-node1 mysql-5.7.44]# make -j2 [root@mysql-node10 mysql-5.7.44# make install

注意!!!(当cmake出错后如果想重新检测,删除 mysql-5.7.44 中 CMakeCache.txt即可 )

1.2 部署mysql

#生成启动脚本
[root@node10 ~]# dnf install initscripts-10.11.6-1.el9.x86_64 -y
[root@node10 ~]# cd /usr/local/mysql/support-files/
[root@node10 support-files]# cp mysql.server /etc/init.d/mysqld
#修改环境变量
[root@node10 ~]# vim ~/.bash_profile
export PATH=$PATH:/usr/local/mysql/bin
[root@node10 ~]# source ~/.bash_profile
#生成配置文件
[root@node10 support-files]# yum install mariadb-connector-c-config-3.2.6-
1.el9_0.noarch -y
[root@node10 my.cnf.d]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql #指定数据目录
socket=/data/mysql/mysql.sock #指定套接字
symbolic-links=0 #数据只能存放到数据目录中,禁止链接到数据目录
#数据库初始化建立mysql基本数据
[root@node10 ~]# mysqld --initialize --user=mysql
[root@node10 ~]# /etc/init.d/mysqld start
[root@node10 ~]# chkconfig mysqld on

1.2.1 生成启动脚本

[root@mysql-node1 ~]# cd /usr/local/mysql/
[root@mysql-node1 mysql]# ls
bin  docs  include  lib  LICENSE  man  mysql-test  README  README-test  share  support-files
[root@mysql-node1 mysql]# useradd -s /sbin/nologin -M mysql
[root@mysql-node1 mysql]# mkdir /data/mysql -p
[root@mysql-node1 mysql]# chown mysql.mysql -R /data/mysql
[root@mysql-node1 mysql]# pwd
/usr/local/mysql
[root@mysql-node1 mysql]# ls
bin  docs  include  lib  LICENSE  man  mysql-test  README  README-test  share  support-files
[root@mysql-node1 mysql]# cd /usr/local/mysql/support-files/
[root@mysql-node1 support-files]# ls
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@mysql-node1 support-files]# cp mysql.server /etc/init.d/mysqld

1.2.2 修改环境变量

[root@mysql-node1 support-files]# vim ~/.bash_profile 
[root@mysql-node1 support-files]# cat ~/.bash_profile 
# .bash_profile# Get the aliases and functions
if [ -f ~/.bashrc ]; then. ~/.bashrc
fi# User specific environment and startup programsPATH=$PATH:$HOME/bin:/usr/local/mysql/binexport PATH
[root@mysql-node1 support-files]# source ~/.bash_profile

 

1.2.3 生成配置文件

[root@mysql-node1 support-files]# vim /etc/my.cnf
[root@mysql-node1 support-files]# cat /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0

1.2.4  数据库初始化建立mysql基本数据

[root@mysql-node1 ~]# mysqld --user mysql --initialize
[root@mysql-node1 ~]# /etc/init.d/mysqld start

1.2.5 查询所有服务状态以及设置MySQL服务启动

[root@mysql-node1 ~]# yum install chkconfig -y
[root@mysql-node1 ~]# chkconfig --list[root@mysql-node1 ~]# chkconfig  mysqld on
[root@mysql-node1 ~]# chkconfig --list

1.2.6 数据库安全初始化

[root@mysql-node1 ~]# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: #输入当前密码
The existing password for the user account root has expired. Please set a new password.
New password: #输入新密码
Re-enter new password: #重复密码
VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: no #是否启用密码插件
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : no
#是否要重置密码
... skipping.
By default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No): y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

 1.2.7 测试

[root@mysql-node1 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.44 Source distributionCopyright (c) 2000, 2023, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

二、mysql的主从复制 

[root@mysql-node1 ~]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0
log-bin=mysql-bin
server-id=1
[root@mysql-node1 ~]# /etc/init.d/mysqld restart

 


http://www.ppmy.cn/ops/99090.html

相关文章

大型物流运输无人机技术详解

随着科技的不断进步和电子商务的蓬勃发展,大型物流运输无人机作为未来物流体系的重要组成部分,正逐步从概念走向实际应用。这类无人机以其超大的载重能力、高效的运输效率和广泛的覆盖范围,为解决远距离、大批量货物运输难题提供了创新方案。…

无人机之故障排除篇

一、识别故障 掌握基本的无人机系统知识,遵循“先易后难、先外后内、先软件后硬件”的原则进行故障识别。一旦发现故障,立即停止飞行,避免进一步损坏。 二、机械部件维修 对于机身裂痕、螺旋桨损坏等情况,根据损坏程度更换相应部…

使用dockerfile-maven-plugin打包镜像时使用本地镜像作基础

使用dockerfile-maven-plugin插件打包Docker镜像时&#xff0c;不要从远程仓库中拉取&#xff0c;而是直接使用本地镜像&#xff1a; <plugin><groupId>com.spotify</groupId><artifactId>dockerfile-maven-plugin</artifactId><configurati…

《图解设计模式》笔记(三)生成实例

五、Singleton模式&#xff1a;只有一个实例 Singleton 是指只含有一个元素的集合。因为本模式只能生成一个实例&#xff0c;因此以 Singleton命名。 示例程序类图 Singleton.java public class Singleton {private static Singleton singleton new Singleton();private Si…

Linux系统之jobs命令的基本使用

Linux系统之jobs命令的基本使用 一、jobs命令介绍二、jobs命令的使用帮助2.1 jobs命令的help帮助信息2.2 jobs命令的语法解释 三、jobs命令的基本使用3.1 运行一个后台任务3.2 列出后台所有的作业3.3 列出进程ID3.4 只列出进程ID3.5 终止后台任务3.6 只显示运行任务3.7 只显示停…

vue3 生命周期钩子

在 Vue 3 中&#xff0c;可以在组件不同阶段的生命周期执行特定逻辑。 生命周期整体分为四个阶段&#xff1a;创建、挂载、更新、卸载。 创建阶段 组合式APIsetup() 这是组合式 API 的入口点&#xff0c;在组件实例创建之前被调用。在此阶段&#xff0c;可以初始化响应式数据…

webpack打包优化方案

调试工具&#xff1a;安装webpack-bundle-analyzer打包可视化工具&#xff0c;可以看到打包文件大小&#xff0c;从而有针对性的优化。 npm install --save-dev webpack-bundle-analyzer。 方案一&#xff1a;将第三方依赖包使用cdn进行引入减小文件包体积&#xff08;例&…

算法的学习笔记—二叉搜索树与双向链表(牛客JZ36)

&#x1f600;前言 在数据结构的学习过程中&#xff0c;二叉搜索树&#xff08;Binary Search Tree, BST&#xff09;是一个常见的主题。它不仅具有排序的特性&#xff0c;还为各类算法的实现提供了基础。然而&#xff0c;在某些特定的应用场景中&#xff0c;我们可能需要将二叉…