如何在 Amazon ec2 上安装 MySQL 5.7
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39025524/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install MySQL 5.7 on Amazon ec2
提问by Drew
How am I able to install MySQL 5.7 in the cloud on Amazon EC2?
如何在 Amazon EC2 的云中安装 MySQL 5.7?
Most of the Amazon Machine Instances (AMIs) that I see either lack any MySQL server or possess an older version such as MySQL Server 5.5
我看到的大多数亚马逊机器实例 (AMI) 要么没有任何 MySQL 服务器,要么拥有旧版本,例如 MySQL Server 5.5
I want to use the latest and greatest.
我想用最新最好的。
回答by Drew
This is a relativelyquick setup of MySQL 5.7.14 on Red Hat Enterprise Linux version 7 (RHEL7).
这是在 Red Hat Enterprise Linux 版本 7 (RHEL7) 上相对快速地设置 MySQL 5.7.14。
I am not affiliated with AWS; I just enjoy using their services.
我不隶属于 AWS;我只是喜欢使用他们的服务。
Make sure you have an AWS EC2 account. Note that even though Amazon requires a creditcard on file, there will be no charges incurred for the first year if you adhere to their Free-tierterms. Typically this means a single micro-instance (1 Gb RAM) server running 24/7.
确保您拥有 AWS EC2 账户。请注意,即使亚马逊要求提供信用卡存档,但如果您遵守其免费套餐条款,则第一年不会产生任何费用。通常,这意味着运行 24/7 的单个微实例(1 Gb RAM)服务器。
Launch of EC2 RHEL instance
启动 EC2 RHEL 实例
Step 1:On AWS EC2 click "Launch Instance" and select "Red Hat Enterprise Linux 7.2 (HVM), SSD Volume Type - ami-775e4f16" as seen in the picture below. Note that the versions of the available or promoted AMIs (Amazon Machine Instance) will rotate over time and this is as of this writing. But the AMI number is shown above in the text.
步骤 1:在 AWS EC2 上单击“Launch Instance”并选择“Red Hat Enterprise Linux 7.2 (HVM), SSD Volume Type - ami-775e4f16”,如下图所示。请注意,可用或提升的 AMI(亚马逊机器实例)的版本将随着时间的推移而轮换,截至撰写本文时。但是 AMI 编号显示在上面的文本中。
Normally, I chose Amazon Linux AMI as my distro of choice. I don't do that anymore as it is their own hodge-podge and there is naturally uncertainty of which package manager to choose and therefore the files. So I stick with RHEL now.
通常,我选择 Amazon Linux AMI 作为我选择的发行版。我不再这样做了,因为它是他们自己的大杂烩,并且自然不确定要选择哪个包管理器以及文件。所以我现在坚持使用 RHEL。
On the "Choose an Instance Type" screen, select a free-tier eligible instance type as seen below:
在“Choose an Instance Type”屏幕上,选择符合条件的免费套餐实例类型,如下所示:
Click Next. On the next Details screen click "Next" to accept defaults. On the storage screen change the size to 16GB and click "Next". Then "Next" again on Tag info. Next comes the "Configure Security Group" screen pictured below:
点击下一步。在下一个详细信息屏幕上单击“下一步”以接受默认值。在存储屏幕上将大小更改为 16GB,然后单击“下一步”。然后在标签信息上再次“下一步”。接下来是“配置安全组”屏幕,如下图:
Accept the radio button of " create a new security group" for now. Note SSH port 22 is open to all(Anywhere) IP addresses with the 0.0.0.0/0CIDR. Other options include detection of "My IP" (as in yours), or "Custom". Rest assured that with the next screen access will be locked down based on Security Keys we will setup. There is a button for Add Rule under the ports open to add such ports as MySQL 3306 or HTTP 80. But for now we will skip that. Note the security group name. Fill one in or accept the default for now. It is not critical to get this right as the security group can be changed later for a running Instance. Click Review and Launch.
现在接受“创建新安全组”的单选按钮。注意 SSH 端口 22对具有CIDR 的所有(任何地方)IP 地址开放。其他选项包括检测“我的 IP”(如您的 IP)或“自定义”。请放心,下一个屏幕访问将根据我们将设置的安全密钥锁定。在打开的端口下有一个添加规则按钮,可以添加 MySQL 3306 或 HTTP 80 等端口。但现在我们将跳过它。记下安全组名称。填写一项或暂时接受默认值。正确执行此操作并不重要,因为稍后可以为正在运行的Instance更改安全组。单击“查看并启动”。0.0.0.0/0
Then click "Launch" (fear not, it is not going to Launch yet). As the next screen presents:
然后单击“启动”(不要害怕,它还不会启动)。正如下一个屏幕所示:
Note that as I already have some keypairs generated, it defaults to "Choose an existing keypair" in the first drop-down. Otherwise, you "Create a new key pair" with a given reminder name and proceed to "Download Key Pair". At this point you have the Key Pair as a .pemfile. Treat that with the utmost of security, saving it to a place that you will not lose it. Preferably in a password protected area such as under your operating system User directory.
请注意,由于我已经生成了一些密钥对,因此在第一个下拉列表中默认为“选择现有密钥对”。否则,您使用给定的提醒名称“创建新的密钥对”并继续“下载密钥对”。此时,您将密钥对作为.pem文件。以最大的安全性对待它,将其保存在不会丢失的地方。最好在密码保护区域,例如在您的操作系统用户目录下。
When you finally click "Launch Instances" on this same screen, the launch takes place in relation to that key pair (either just created or a pre-existing one). Note, the generation of a key pair might be a task you perform just once a year. Re-using a key pair again and again, up to you.
当您最终在同一屏幕上单击“启动实例”时,启动与该密钥对(刚刚创建的或预先存在的)相关。请注意,密钥对的生成可能是您每年仅执行一次的任务。一次又一次地重新使用密钥对,由您决定。
After you launch the instance, you have roughly five minutes before it comes live. Under the Instances left menu item, you know the instance is live when the Instance State reads "running" and the Status Checks reads "2/2 passed":
启动实例后,大约有 5 分钟时间它就会上线。在 Instances 左侧菜单项下,当实例状态显示为“正在运行”并且状态检查显示为“2/2 已通过”时,您就知道该实例处于活动状态:
Remember the .pemfile that you downloaded? Well just one time you need to create a .ppkfile out of that for PuTTY, an SSH client program that will communicate cryto-secured to your running instance. For that we use the puttygentool that works in harmony with PuTTY. So we run puttygen, load the .pemdownloaded minutes before, and generate the .ppkfile with a "Key passphrase" such as "I & love%ancHovies2_fjdi8Ha". Below is a picture of puttygen:
还记得.pem你下载的文件吗?有一次,您需要.ppk为 PuTTY创建一个文件,PuTTY 是一个 SSH 客户端程序,它将加密安全地与您正在运行的实例进行通信。为此,我们使用与 PuTTY 协调工作的puttygen工具。因此,我们运行 puttygen,在.pem几分钟前加载下载的.ppk文件,并生成带有“密钥密码”的文件,例如“I & love%ancHovies2_fjdi8Ha”。下面是puttygen的图片:
And the AWS EC2 page entitled Connecting to Your Linux Instance from Windows Using PuTTY. The steps are File / Load private key. Change the filter to All files (.). Find the .pemfile. Hit "Open", then "Ok". Type in a Passphrase. Click "save private key", and save it in the same folder as a .ppkfile alongside your .pemfile. As mentioned, this is not something you might do but yearly.
以及名为“使用 PuTTY 从 Windows 连接到 Linux 实例”的 AWS EC2 页面。步骤是文件/加载私钥。将过滤器更改为所有文件 ( .)。找到.pem文件。点击“打开”,然后“确定”。输入密码。单击“保存私钥”,并将其与.ppk文件一起保存在与文件相同的文件夹中.pem。如前所述,这不是您可以每年做的事情。
Now run PuTTY, the SSH client. Use the Session / Host Name as something like
现在运行 SSH 客户端 PuTTY。使用会话/主机名作为类似
[email protected]
So it is basically ec2-user@concatenated with the Public DNS name that is seen under Instances on the EC2 Control panel. As for specifying the PuTTY .ppkfile, it would look like the below, with the .ppkfile chosen next to the Browse button:
因此,它基本上ec2-user@与在 EC2 控制面板上的实例下看到的公共 DNS 名称连接在一起。至于指定 PuTTY.ppk文件,它将如下所示,.ppk在 Browse 按钮旁边选择文件:
Go back to the Session upper left hierarchy shown below, give this a profile name under Saved Sessions, and hit "Save". Hereafter when you load PuTTY, you merely load the session by name:
返回到如下所示的会话左上角层次结构,在 Saved Sessions 下为其指定一个配置文件名称,然后点击“Save”。此后,当您加载 PuTTY 时,您只需按名称加载会话:
Don't forget that just about all you are doing here is saving the .ppkreference into a friendly named profile. And you may ocassionally need to change Host Name (certainly when you save an Instance image on EC2 and come back in with a new Instance IP address on a subsequent launch).
不要忘记,您在这里所做的几乎就是将.ppk引用保存到一个友好的命名配置文件中。并且您可能偶尔需要更改主机名(当然,当您在 EC2 上保存实例映像并在后续启动时使用新的实例 IP 地址返回时)。
Ok, it is not easy. But it is what it is.
好吧,这并不容易。但是它就是这样啊。
When you click Open it will attempt to connect to your RHEL instance. Hit Yes on the signature warning. Enter the prior saved .ppkKey Passphrase, and you should be sitting at a Linux prompt.
当您单击打开时,它将尝试连接到您的 RHEL 实例。在签名警告上点击是。输入之前保存的.ppk密钥密码,您应该会看到 Linux 提示符。
MySQL Installation (I will put these notes on GitHub)
MySQL 安装(我会把这些笔记放在 GitHub 上)
URL01: Download MySQL Yum Repository
URL02: Chapter 1 Installing MySQL on Linux Using the MySQL Yum Repository
URL02:第 1 章使用 MySQL Yum 存储库在 Linux 上安装 MySQL
You now have MySQL 5.7.14 loaded and running on EC2 with a database and user setup. Your servers need to be imaged. See this answer hereof mine for creating images (AMI's). Backup your data. See the EC2 documentation such as Best Practices for Amazon EC2.
您现在已加载 MySQL 5.7.14 并在 EC2 上运行,并设置了数据库和用户。您的服务器需要进行映像。看到这个答案在这里我的创建映像(AMI的)。备份您的数据。请参阅 EC2 文档,例如Amazon EC2 的最佳实践。
Back to security: best practices certainly suggest not opening up your db to direct connects through Security Groups for port 3306. How you choose to adhere to that is your choice, such as with a PHP, Java, or other programming API. Note that various db client programs can connect through SSH tunnels such as MySQL Workbench. In addition various development libraries exist with SSH Tunnels but they are not terribly easy to develop against (mainly due to difficult key chains and lack of extensive developer experiences). For instance, there is one for C# here.
回到安全性:最佳实践当然建议不要打开您的数据库以通过端口 3306 的安全组直接连接。您选择如何遵守这一点是您的选择,例如使用 PHP、Java 或其他编程 API。请注意,各种 db 客户端程序可以通过 SSH 隧道连接,例如 MySQL Workbench。此外,SSH Tunnels 存在各种开发库,但它们并不是非常容易开发(主要是由于密钥链困难和缺乏丰富的开发人员经验)。例如,有一个C#在这里。
In addition AWS has RDS and other database offering for less hands-on and rolling your own like the above. The reason many developers target EC2 is due to the fact that you have a full blown server for your other programming initiatives.
此外,AWS 还提供 RDS 和其他数据库产品,以减少手动操作和像上述那样自行滚动。许多开发人员针对 EC2 的原因是因为您拥有用于其他编程计划的完整服务器。
If you do modify the Security Groups as mentioned before, please consider using IP Ranges based on CIDR entries and use caution before over-exposing your datastores. Or over granting. Much the same best practices as you would for on-premise work.
如果您确实如前所述修改了安全组,请考虑使用基于 CIDR 条目的 IP 范围,并在过度暴露您的数据存储之前谨慎行事。或过度授予。与本地工作的最佳实践大致相同。
Concerning this MySQL section, my GitHub notes for the above few pictures are located Here.
关于这个 MySQL 部分,我上面几张图片的 GitHub 笔记位于这里。
回答by georgeos
I had the same issue, but i didn't want to use Red Hat or any other OS than Amazon Linux AMI. So, here is the process to install MySQL 5.7 and upgrade an older version.
我遇到了同样的问题,但我不想使用 Red Hat 或 Amazon Linux AMI 以外的任何其他操作系统。所以,这里是安装 MySQL 5.7 和升级旧版本的过程。
Short path (without screenshots)
短路径(无截图)
wget https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
yum localinstall mysql57-community-release-el6-11.noarch.rpm
yum remove mysql55 mysql55-common mysql55-libs mysql55-server
yum install mysql-community-server
service mysqld restart
mysql_upgrade -p
Long path (with screenshots)
长路(附截图)
First of all, just to validate you can check the current version.

Then, you should download the repo for EL6 11
然后,您应该下载 EL6 11 的 repo
wget https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
Next, make a localinstall:
接下来,进行本地安装:
yum localinstall mysql57-community-release-el6-11.noarch.rpm
This is probably the key for a successful installation. You should remove the previous packages, regarding to MySQL 5.5
这可能是成功安装的关键。你应该删除以前的包,关于 MySQL 5.5
yum remove mysql55 mysql55-common mysql55-libs mysql55-server
Finally, you can install MySQL 5.7
最后,您可以安装 MySQL 5.7
yum install mysql-community-server
Restart the MySQL Server and upgrade your database
重新启动 MySQL 服务器并升级您的数据库
service mysqld restart
mysql_upgrade -p
You can validate you installation by authenticating to MySQL
您可以通过对 MySQL 进行身份验证来验证您的安装
回答by Elijah Lynn
sudo yum install mysql57-server
sudo yum install mysql57-server

