单台[dell R720]服务器部署多个mysql实例

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用系列 2核4GB
简介: 一、安装mysql准备 1.1 下载mysql软件包 mkdir -p /home/xuekun/mysql cd /home/xuekun/tools/mysql wget http://dev.

一、安装mysql准备

1.1 下载mysql软件包

mkdir -p /home/xuekun/mysql

cd /home/xuekun/tools/mysql

wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.10.tar.gz

1.2安装mysql软件

yum -y install make gcc-c++ cmake bison bison-devel  ncurses-devel

tar xvf mysql-5.6.16.tar.gz

cd mysql-5.6.16

cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/data \

-DSYSCONFDIR=/etc \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \

-DMYSQL_TCP_PORT=3306 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci

 

make && make install

 

1.3创建mysql用户

groupadd mysql

useradd -g mysql -M -s /sbin/nologin mysql

1.4创建mysql数据文件目录

mkdir -p /data/3306/data

mkdir -p /data/3307/data

tree /data/

/data/

|-- 3306

| `-- data

`-- 3307

`-- data

4 directories, 0 files

1.5 授权mysql用户及组访问数据文件目录

chown -R mysql:mysql /data/3306

chown -R mysql:mysql /data/3307

1.6 建立3306,3307 my.cnf配置文件

vim  /data/3306/my.cnf

vim  /data/3307/my.cnf

需要添加的my.cnf内容见附录B:或本文档目录下的my.cnf文件

#授权mysql用户及组访问my.cnf

chown -R mysql:mysql /data/3306/my.cnf

chown -R mysql:mysql /data/3307/my.cnf

1.7 建立mysql启动脚本

vim  /data/3306/mysql

vim  /data/3307/mysql

 

需要添加的mysql 内容见附录C:或本文档目录下的mysql文件

chmod 700 /data/3306/mysql

chmod 700 /data/3307/mysql

1.8 初始化数据库

vim /etc/profile

PATH=/usr/local/mysql/bin:$PATH

export PATH

#关闭文件,运行下面的命令,让配置立即生效

source /etc/profile

cd /usr/local/mysql

scripts/mysql_install_db --datadir=/data/3306/data

Installing MySQL system tables...

OK

Filling help tables...

OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

/usr/local/mysql/bin/mysqladmin -u root password 'new-password'

/usr/local/mysql/bin/mysqladmin -u root -h A password 'new-password'

Alternatively you can run:

/usr/local/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default. This is

strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/local/mysql/bin/mysqlbug script!

 

scripts/mysql_install_db --datadir=/data/3307/data

Installing MySQL system tables...

OK

Filling help tables...

OK

同上面3306的内容,因此,此处省略。

 

chown -R mysql:mysql /data

1.9 启动数据库

启动mysql实例的命令为

/data/3306/mysql start

Starting MySQL...

/data/3307/mysql start

Starting MySQL...

检查启动情况:

netstat -lnt|grep 330[6-7]

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN

tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN

并加入/etc/rc.local,设置为开机自启动

echo "/data/3306/mysql start" >>/etc/rc.local

echo "/data/3307/mysql start" >>/etc/rc.local

cat /etc/rc.local

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

/data/3306/mysql start

/data/3307/mysql start

提示:如果此步中的数据库启动不了,请稍微等待下,如果还不行请查看错误日志,路径在my.cnf的最下面。

二、配置mysql数据库

2.1 访问测试登陆情况

mysql -uroot -p -S /data/3306/mysql.sock

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.1.51-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select version();

+------------+

| version() |

+------------+

| 5.1.51-log |

+------------+

1 row in set (0.02 sec)

mysql> system mysql -uroot -p -S /data/3307/mysql.sock #-->system的用法

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.1.51-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| test |

+--------------------+

3 rows in set (0.01 sec)

mysql> quit

Bye

提示:安装完mysql初始登陆管理员root用户无密码。

更改root密码

mysqladmin -u root password 'bdkyr14511' -S /data/3306/mysql.sock

mysqladmin -u root password 'bdkyr14511' -S /data/3307/mysql.sock

#测试改密码后的登陆情况

mysql -uroot -p'bdkyr14511' -S /data/3306/mysql.sock

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.1.51-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> system mysql -uroot -p'bdkyr14511' -S /data/3307/mysql.sock

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

mysql> system mysql -uroot -p'hyran0926' -S /data/3307/mysql.sock

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.1.51-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

提示:一般产品环境,禁止将密码写在命令行中,非常危险。

2.2清理系统默认的多余mysql用户

mysql -uroot -p'bdkyr14511' -S /data/3306/mysql.sock

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.1.51-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select user,host from mysql.user;

+------+-----------+

| user | host |

+------+-----------+

| root | 127.0.0.1 |

| | A |

| root | A |

| | localhost |

| root | localhost |

+------+-----------+

5 rows in set (0.00 sec)

mysql> drop user ''@'localhost';

Query OK, 0 rows affected (0.04 sec)

mysql> drop user ''@'A';

Query OK, 0 rows affected (0.01 sec)

mysql> drop user 'root'@'A';

Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from mysql.user;

+------+-----------+

| user | host |

+------+-----------+

| root | 127.0.0.1 |

| root | localhost |

+------+-----------+

2 rows in set (0.00 sec)

用同样的方法处理3307的用户。

处理后结果:

mysql> select user,host from mysql.user;

+------+-----------+

| user | host |

+------+-----------+

| root | 127.0.0.1 |

| root | localhost |

+------+-----------+

2 rows in set (0.00 sec)

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
9天前
|
中间件 Java 应用服务中间件
Windows部署web应用服务器Jboss中间件
如何在Windows系统上部署JBoss 7.1作为Web应用服务器,包括配置环境变量、自动部署WAR包、访问JBoss控制台、设置管理员账户以及修改端口和绑定地址等操作。
25 1
|
11天前
|
JavaScript 前端开发 应用服务中间件
【Vue面试题三十】、vue项目本地开发完成后部署到服务器后报404是什么原因呢?
这篇文章分析了Vue项目在服务器部署后出现404错误的原因,主要是由于history路由模式下服务器缺少对单页应用的支持,并提供了通过修改nginx配置使用`try_files`指令重定向所有请求到`index.html`的解决方案。
【Vue面试题三十】、vue项目本地开发完成后部署到服务器后报404是什么原因呢?
|
3天前
|
负载均衡 应用服务中间件 持续交付
微服务架构下的Web服务器部署
【8月更文第28天】随着互联网应用的不断发展,传统的单体应用架构逐渐显露出其局限性,特别是在可扩展性和维护性方面。为了解决这些问题,微服务架构应运而生。微服务架构通过将应用程序分解成一系列小型、独立的服务来提高系统的灵活性和可维护性。本文将探讨如何在微服务架构中有效部署和管理Web服务器实例,并提供一些实际的代码示例。
21 0
|
2天前
|
存储 弹性计算 负载均衡
阿里云服务器地域、实例、带宽与操作系统等配置选择指南参考
在数字化时代,无论是个人博客、企业官网、APP后端支持,还是小程序运行或者其他项目,云服务器都扮演着至关重要的角色,考虑产品质量、服务和价格等因素,大家现在都喜欢选择阿里云服务器。然而,对于初次接触云服务的新手来说,可能并不是很清楚应该如何选阿里云服务器的地域、实例、带宽与操作系统等配置。本文将从地域选择、实例规格、操作系统、云盘配置、购买时长以及带宽选择等六个方面,为新手用户提供详细的选购指南,以供参考。
阿里云服务器地域、实例、带宽与操作系统等配置选择指南参考
|
4天前
|
JavaScript NoSQL 中间件
《Node.js后端修炼手册》——揭秘服务器搭建与部署上线的生死时速,让你一战成名!
【8月更文挑战第27天】本文详细介绍如何从零开始利用Node.js构建后端服务器并部署至生产环境。首先,通过简易步骤搭建基础服务器,包括环境安装与配置。接着,引入Express框架优化路由与中间件管理,提升开发效率。随后,利用Mongoose实现MongoDB数据库连接,增强数据交互能力。为保证系统稳定性,文中还讲解了错误处理机制。最后,通过PM2等工具部署应用至生产环境,确保高效运行。本教程辅以示例代码,帮助读者快速掌握Node.js后端开发全流程。
32 2
|
6天前
|
前端开发 应用服务中间件 nginx
前端服务器部署方式
【8月更文挑战第25天】前端服务器部署方式
19 1
|
9天前
|
关系型数据库 MySQL Linux
在Linux中,如何配置数据库服务器(如MySQL或PostgreSQL)?
在Linux中,如何配置数据库服务器(如MySQL或PostgreSQL)?
|
1天前
|
数据采集 弹性计算 供应链
阿里云服务器付费模式:按量付费、包年包月和抢占式实例全解析
阿里云服务器提供包年包月、按量付费与抢占式实例三种付费模式。包年包月为预付费,适合长期稳定使用,价格更优惠并支持备案。按量付费则为后付费模式,按小时结算,适合短期或访问量波动大的场景,但不支持备案。抢占式实例基于按量付费,价格更低(最多节省90%),适用于无状态应用,如临时测试或可弹性伸缩的Web服务,但存在被系统释放的风险,同样不支持备案。根据具体需求选择合适的付费模式能够有效降低成本并提高效率。
9 0
|
7天前
|
Linux 应用服务中间件 网络安全
【Azure 应用服务】查看App Service for Linux上部署PHP 7.4 和 8.0时,所使用的WEB服务器是什么?
【Azure 应用服务】查看App Service for Linux上部署PHP 7.4 和 8.0时,所使用的WEB服务器是什么?
|
8天前
|
固态存储 关系型数据库 MySQL
mysql多实例一键部署
mysql多实例一键部署

热门文章

最新文章

下一篇
云函数