阿里云apache-CentOS
2019-09-26 本文已影响0人
Berning
阿里云centos7.6原生根目录
两项工作
- 打开80端口(iptables/firewalld/ali云安全组)
- 安装apache
Part ONE 打开80端口
一、用iptables打开80端口
1、安装iptables:
//(阿里云centos7 默认 是使用的firewall,所以要使用iptables需先安装)
yum install iptables-services
2、把端口加入到iptables中(加入之前,可使用iptables -L -n
查看端口情况)
vim /etc/sysconfig/iptables
添加:
---vim iptables---
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
:wq
3、重启iptables:
systemctl restart iptables.service
(重启后,使用 iptables -L -n查看)
二、centos7.x用firewall打开80端口
- filrwall开启相关命令:
// filrwall是否开启:
# systemctl status firewalld
// 启动:
#systemctl start firewalld
//关闭:
# systemctl stop firewalld
//开机禁用 :
#systemctl disable firewalld
//开机启用 :
#systemctl enable firewalld
2.查看防火墙是否开启的状态,以及开放端口的情况
#systemctl status firewalld.service
//如果没有开启firewalld
#systemctl enable firewalld
#firewall-cmd --list-all
- 通过以下命令开放http 80 端口
//添加80端口
# firewall-cmd --zone=public --add-port=80/tcp --permanent
命令末尾的--permanent表示用久有效,不加这句的话重启后刚才开放的端口就又失效了
4 .然后重启防火墙
//重载
# firewall-cmd --reload
- 再次查看端口的开放情况:
//
# firewall-cmd --list-all
ports:里出现了 80 端口
public
target: default
icmp-block-inversion: no
interfaces:
sources:
services: dhcpv6-client ssh
ports: 80/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
三 、在阿里云控制台上, 添加安全组规则
- path:
云服务器ECS -> 安全组 -> 安全组规则 -> 入方向 -> 添加安全组规则
- 填写必须的选项
*端口范围:80/80
*授权对象:0.0.0.0/0
确定。OK~
Part Two Apache安装
一、Apache安装
1.确保服务器系统处于最新状态
yum -y update
2.重启服务器
reboot
3.首先检查80端口是否已经开启
netstat -an | grep 80
详见 Part One
如果显示以下内容说明已经开启80端口
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 172.16.134.203:56088 100.100.30.25:80 ESTABLISHED
unix 3 [ ] STREAM CONNECTED 11809
unix 2 [ ] DGRAM 11800
4.安装Apache,并且安装扩展模块
yum -y install httpd httpd-manual httpd-devel mod_ssl mod_perl mod_auth_mysql
5.设置CentOS开机自动启动Apache服务
systemctl enable httpd.service
6.检查Apache是否已经安装了开机自动启动
systemctl list-unit-files | grep httpd
如果显示以下内容说明已经完成自动启动安装
httpd.service enabled
7.启动Apache服务
systemctl start httpd.service
8.判断是否安装成功Apache服务
curl http://127.0.0.1
命令行界面正常显示一堆html、css代码,没有乱码,一般是成功了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Apache HTTP Server Test Page powered by CentOS</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Bootstrap -->
<link href="/noindex/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="noindex/css/open-sans.css" type="text/css" />
<style type="text/css"><!--
body {
font-family: "Open Sans", Helvetica, sans-serif;
font-weight: 100;
color: #ccc;
background: rgba(10, 24, 55, 1);
font-size: 16px;
}
h2, h3, h4 {
font-weight: 200;
}
h2 {
font-size: 28px;
}
.jumbotron {
margin-bottom: 0;
color: #333;
background: rgb(212,212,221); /* Old browsers */
background: radial-gradient(ellipse at center top, rgba(255,255,255,1) 0%,rgba(174,174,183,1) 100%); /* W3C */
}
.jumbotron h1 {
font-size: 128px;
font-weight: 700;
color: white;
text-shadow: 0px 2px 0px #abc,
0px 4px 10px rgba(0,0,0,0.15),
0px 5px 2px rgba(0,0,0,0.1),
0px 6px 30px rgba(0,0,0,0.1);
}
.jumbotron p {
font-size: 28px;
font-weight: 100;
}
.main {
background: white;
color: #234;
border-top: 1px solid rgba(0,0,0,0.12);
padding-top: 30px;
padding-bottom: 40px;
}
.footer {
border-top: 1px solid rgba(255,255,255,0.2);
padding-top: 30px;
}
--></style>
</head>
<body>
<div class="jumbotron text-center">
<div class="container">
<h1>Testing 123..</h1>
<p class="lead">This page is used to test the proper operation of the <a href="http://apache.org">Apache HTTP server</a> after it has been installed. If you can read this page it means that this site is working properly. This server is powered by <a href="http://centos.org">CentOS</a>.</p>
</div>
</div>
<div class="main">
<div class="container">
<div class="row">
<div class="col-sm-6">
<h2>Just visiting?</h2>
<p class="lead">The website you just visited is either experiencing problems or is undergoing routine maintenance.</p>
<p>If you would like to let the administrators of this website know that you've seen this page instead of the page you expected, you should send them e-mail. In general, mail sent to the name "webmaster" and directed to the website's domain should reach the appropriate person.</p>
<p>For example, if you experienced problems while visiting www.example.com, you should send e-mail to "webmaster@example.com".</p>
</div>
<div class="col-sm-6">
<h2>Are you the Administrator?</h2>
<p>You should add your website content to the directory <tt>/var/www/html/</tt>.</p>
<p>To prevent this page from ever being used, follow the instructions in the file <tt>/etc/httpd/conf.d/welcome.conf</tt>.</p>
<h2>Promoting Apache and CentOS</h2>
<p>You are free to use the images below on Apache and CentOS Linux powered HTTP servers. Thanks for using Apache and CentOS!</p>
<p><a href="http://httpd.apache.org/"><img src="images/apache_pb.gif" alt="[ Powered by Apache ]"></a> <a href="http://www.centos.org/"><img src="images/poweredby.png" alt="[ Powered by CentOS Linux ]" height="31" width="88"></a></p>
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<div class="container">
<div class="row">
<div class="col-sm-6">
<h2>Important note:</h2>
<p class="lead">The CentOS Project has nothing to do with this website or its content,
it just provides the software that makes the website run.</p>
<p>If you have issues with the content of this site, contact the owner of the domain, not the CentOS project.
Unless you intended to visit CentOS.org, the CentOS Project does not have anything to do with this website,
the content or the lack of it.</p>
<p>For example, if this website is www.example.com, you would find the owner of the example.com domain at the following WHOIS server:</p>
<p><a href="http://www.internic.net/whois.html">http://www.internic.net/whois.html</a></p>
</div>
<div class="col-sm-6">
<h2>The CentOS Project</h2>
<p>The CentOS Linux distribution is a stable, predictable, manageable and reproduceable platform derived from
the sources of Red Hat Enterprise Linux (RHEL).<p>
<p>Additionally to being a popular choice for web hosting, CentOS also provides a rich platform for open source communities to build upon. For more information
please visit the <a href="http://www.centos.org/">CentOS website</a>.</p>
</div>
</div>
</div>
</div>
</div>
</body></html>
或者
如果在浏览器中输入服务器IP地址(127.40.171.11
)显示Testing 123..就说明安装成功
二、常见操作
- 启动、终止、重启
systemctl start httpd.service #启动
systemctl stop httpd.service #停止
systemctl restart httpd.service #重启
- 设置开机启动/关闭
systemctl enable httpd.service #开机启动
systemctl disable httpd.service #开机不启动
systemctl list-unit-files | grep httpd # 检查Apache是否已经安装了开机自动启动
- 检查httpd状态
systemctl status httpd.service #检查状态
- 显示Apache版本信息
httpd -v
- 使用yum安装Apache,并且安装所有扩展模块
yum -y install httpd*
- 查看加载模块
httpd -M
- 检查配置文件是否正确
httpd -t
- 显示所有命令
httpd -q
- 检查Apache安装路径
whereis httpd
- 检查并且显示Apache相关安装包
rpm -qa | grep httpd
- 显示Apache详细相关信息
yum info httpd
- 查看Apache安装位置
rpm -ql httpd
- 删除Apache
rpm -e httpd-* --nodeps
或
rpm -e httpd-2.4.6-67.el7.c和entos.6.x86_64 --nodeps
- 删除Apache,并且删除相关文件
yum -y remove httpd
三、相关配置与环境
Apache主配置文件:/etc/httpd/conf/httpd.conf
Apache主配置目录,可以将不同类型的配置分门别类放入这个目录中:/etc/httpd/conf.d/
Apache网站根目录:/var/www/html/
Apache日志文件目录:/var/log/httpd