如何在启动 Amazon EC2 实例时自动启动 Web 服务?
如何设置 httpd 和 mysqld 服务在启动 amazon-ec2 实例?
目前,我必须通过 ssh 连接到实例并运行 sudo service httpd start 和 sudo service mysqld start 来手动启动它们。
How do I set the httpd and mysqld services to start automatically upon booting an amazon-ec2 instance?
Currently I have to start them manually by connecting to the instance via ssh and running sudo service httpd start
and sudo service mysqld start
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您无需从新的 AMI 开始,只需在 Amazon Linux EC2 实例上发出以下命令...
您可以在 & 之前检查设置。使用以下命令启用这些服务在启动时启动后...
仅使用...查看所有服务
注意:如果您在 root 路径中遇到 chkconfig 问题,您可以尝试像这样指定完整路径...
Rather than starting over with a new AMI, you could just issue the following commands on an Amazon Linux EC2 instance...
You can check the settings before & after enabling these services to start on boot using the following commands...
See all services using just...
NOTE: If you are having any trouble with chkconfig being in root's path, you can try specifying the full path like this...
Amazon Linux 1 和 Amazon Linux 2 之间有所不同。
Amazon Linux 1
在 AmazonLinux1 中,使用
chkconfig
命令。Amazon Linux2
在 AmazonLinux2 中,引入了 systemd。因此,
chkconfig
是旧命令。您应该使用systemctl
。它是systemd的控制命令。您可以通过
is-enabled
命令确认它是否启用。chkconfig
命令请求将转发到systemctl
。It is different between Amazon Linux 1 and Amazon Linux 2.
Amazon Linux 1
In AmazonLinux1, use
chkconfig
command.Amazon Linux2
In AmazonLinux2, systemd was introduced. So,
chkconfig
is legacy command. You should usesystemctl
. It is a control command for systemd.You can confirm it is enabled or not using by
is-enabled
command.chkconfig
command request will be forwarded tosystemctl
.如果您使用 Amazon Linux 2 AMI,您需要执行以下步骤:
systemctl
来管理服务,检查它是否安装在您的计算机上2.
systemctl list-units --type=service
通过此命令检查 tomcat.service 是否列出sudo systemctl enable tomcat.service
使 tomcat 在启动时启动>systemctl is-enabled tomcat.service
检查tomcat是否在Linux系统启动时启动。之后,您可以重新启动Linux系统,tomcat将启动。
有关
systemctl
的更多信息 点击此处If you using Amazon Linux 2 AMI you need to follow these steps:
systemctl
for managing services check if it is installed on your machine2.
systemctl list-units --type=service
by this command check if tomcat.service is listedsudo systemctl enable tomcat.service
To eanable tomcat start on boot upsystemctl is-enabled tomcat.service
To check if tomcat enabled to start on boot up linux systemAfter that you can reboot your linux system and tomcat will be started.
For more about
systemctl
Click Here我的一位客户想要完成这项任务,我已经通过使用以下方式成功完成了。
以下命令在实例启动时自动启动服务。
自动启动apache/httpd
自动启动redis服务
我已将SELINUX设置为禁用
对于mysql服务
One of my client wants to do this task and I have successfully done by using following way.
Following commands starts the services automatic when instance started.
Auto start apache/httpd
Auto start redis service
I have set SELINUX set to disabled in
For mysql services
我遇到了类似的问题,这是我建议的解决方案,
您需要在/etc/init.d 目录下创建一个文件,例如名称为tomcat,并根据您的系统安装更改JAVA_HOME 和CATALINA_HOME 参数。
一旦你设置了这个文件,然后运行以下命令:
你在 /etc/init.d 中创建的文件在哪里,在我的例子中是 tomcat。
I faced the similar problem, here is the solution i am suggesting,
you need to create a file under /etc/init.d directory, e.g with name tomcat, and change the JAVA_HOME and CATALINA_HOME parameters as per your system installation.
Once you do setup this file then run the below command:
where is the file you have created in /etc/init.d it is tomcat in my case.
Amazon Linux2 上的 ReactJS 流程:
在 EC2 上安装 ReactJS 并在启动时运行应用程序:
https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html
重写引擎开启
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]”
使用 :wq 保存文件
你完整了。
ReactJS on Amazon Linux2 process:
Installing ReactJS on EC2 and running the app at boot:
https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]”
Save the file with :wq
You are complete.
Amazon Linux 2 上的最佳方法是在创建时使用以下 bash 脚本。这将安装更新,启动 Apache2,将其列为服务,以便在重新启动时自动重新启动,并创建 index.html 和 health.html 示例文件。配置运行状况页面对于应用程序负载均衡器和自动缩放组非常重要。
干杯!
The best way on Amazon Linux 2 is to use the following bash script on creation. This will install the updates, start Apache2, make it listed as a service so that it automatically restarts upon reboot, and the creation of an index.html and health.html sample files. Configuring a health page is important for application loadbalancers and for autoscaling groups.
Cheers!
要么使用任何预先存在的 LAMP AMI,它们都将作为服务运行。
一个例子是 BitNami,当您启动 ec2 实例时,您会发现其他几个。
Either use any of the preexisting LAMP AMI, it will have both of them running as service already.
One example is BitNami, you will find several other when you fire an ec2 instance.