当前位置:   article > 正文

源码部署Apache和shell脚本安装_shell脚本安装web服务篇

shell脚本安装web服务篇

一、Apache特点:

功能强大,配置简单,速度快,应用广泛,性能稳定,可做代理服务器及负载均衡来使用。
1.处理静态页面图片不及nginx
2.Apace、结合php来处理php、perl等,经典的;lamp
3.Apache结合tomca、resin来处理运行java、jsp在中小企业堪称首选
4.使用apache做代理、负载均衡、rewrite规则过滤等等

Apache软件的用途,发布静态网页;

2)静态网页:不与数据库发生交互,普通文件、内容很少更新,.html、.txt、png、jpg、gif、css、jpeg、mp4、wmv;
3)动态网页:与数据发生交互,读取、写入数据,PHP、JSP、do、asp、cgi;
4)Apache属于一个web服务器软件,主要用于发布网页。
4、Apache、Nginx、Lighttpd、IIS、Resin、Tomcat、WebLogic、Jetty等。

Apache:发布静态页面;
Nginx:发布静态页面,Nginx轻量级、高性能;
Apache工作模式三种(模块化工作):
1)Prefork MPM:
2)Worker MPM:
3)Event MPM:

Apache虚拟主机(快速部署上千个网站)
1、 Apache|Nginx|Tomcat软件应用场景:
1) WEB服务器,用于发布WWW网页,用于发布静态网页,静态页面,后缀html、css、js、png、jpg、gif、txt,跟数据库没有交互;
2) 动态页面,跟数据库发生交互,代码|程序去连接数据库,后缀php、jsp、do、asp、aspx、cgi等;
2、 Apache WEB服务器工作引擎(Nginx WEB服务器,如何工作的?)
1) 发布WEB网站,最主要是处理和接收用户的请求,并且将用户请求的数据返回给用户;
2) Prefork工作引擎特点:采用预派生子进程方式,等待用户请求来访问,同一时刻,每个子进程都具有一个线程,每个线程负责处理一个请求,每个子进程之间相互独立,互不影响,比较稳定,非常占资源,Apache默认工作引擎;
3) Worker工作引擎特点:预派生多进程、多线程方式,主控进程生成多个工作进程,每个工作进程会生成多个线程,每个线程维护一个连接;

Apache配置虚拟主机(配置多个WEB网站)
1)基于一台服务器多个IP,配置多个WEB网站;
2)基于一台服务器单个IP,多端口配置多个WEB网站;
3)基于一台服务器单个IP,多域名配置多个WEB网站;

二、安装2.2步骤

 tar xvf httpd-2.2.31.tar.bz2 
 cd httpd-2.2.31 
./configure --prefix=/usr/local/apache2.2 --enable-deflate --enable-expires  --enable-headers  --enable-modules=most --enable-so  --with-mpm=worker --enable-rewrtie 
  Make  &&  makeinstall
  • 1
  • 2
  • 3
  • 4

备注含义:

–enable-deflate \压缩
–enable-expires \ -缓存内容过期时间
-enable-headers \ 激活http头模块
–enable-modules=most 激活大多数模块
–with-mpm=worker \ 在worker模式下工作,该模式支持的并发会大点
/usr/local/apache2.2/bin/apachectl -l 查看当前加载的模块
/usr/local/apache2.2/bin/apachectl graceful 平滑重启

三、目录结构

1.bin
在这里插入图片描述

Ab 压力测试的命令

Apxs 扩展添加编译模块时候的工作,在进行DSO方式编译模块时用到
Htpasswd 一打开站点就输入密码
Httpd appachectl执行的时候,就是调用的httpd
Rotatelogs apache自带的日志轮询命令,也可以用cronolog代替

2.Conf
在这里插入图片描述
Extra是主配置文件的一个子目录
在这里插入图片描述

这个是调整网站主页的次序。可以在index前面插入其他页面

3.Logs
在这里插入图片描述
Access_log 用户访问网站的信息记录
Http.pid pid文件

四、主配置文件说明:

grep -Ev “#|^$” httpd.conf >test.txt

 9 ServerAdmin you@example.com  管理员邮箱
 10DocumentRoot "/usr/local/apache2.2/htdocs" 默认站点目录文件夹
 11 <Directory />     根目录  
 12     Options FollowSymLinks  可以带符号链接 
 13     AllowOverride None     禁止一些功能
 14     Order deny,allow       不让任何人访问该目录
 15     Deny from all
 16   </Directory >   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

新创建网站的配置

 17 <Directory "/usr/local/apache2.2/htdocs">
 18     Options Indexes FollowSymLinks      把index 去掉就是不对外
  • 1
  • 2

展示目录结构

 19     AllowOverride None
 20     Order allow,deny
 21     Allow from all
 22 </Directory>
  • 1
  • 2
  • 3
  • 4

造成403的错误,权限不够,许可不够,还有文件格式不对

 23 <IfModule dir_module>
 24     DirectoryIndex index.html            配置更换首页
 25 </IfModule>  
  
 33 <IfModule log_config_module>
 34     LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
 35     LogFormat "%h %l %u %t \"%r\" %>s %b" common
 36     <IfModule logio_module>
 37       LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
 38     </IfModule>
 39     CustomLog "logs/access_log" common
 40 </IfModule>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

访问日志的类型。。用户访问网站所记录的内容

五:extra下的配置文件

重要的两个:http-vhosts.conf、http-mpm.conf 还要需要了解的httpd-default.conf
在这里插入图片描述
http-mpm.conf
根据编译的时候指定的模式work模式来看,如果编译不制定work,那默认就是prefork模式
在这里插入图片描述
Maxclients 最大并发数
httpd-default.conf
在这里插入图片描述
Timeout :等待超时300秒
Keepalive on 保持连接
MaxKeepAliveRequests 100 最大保持连接数100
KeepAliveTimeout 5 在同一个连接上等待下一个请求的时间
在这里插入图片描述
.htaccess 可从 AllowOverride None 处开启

ServerTokens Full
ServerSignature On 这2个参数可以控制apache显示版本号

一、apache虚拟主机的分类和生产场景介绍:

虚拟主机:部署多个站点,每个站点需要不同的域名和站点目录,或者不用的ip和端口
简单的说就是1个http服务部署多个网站。、

虚拟主机分类:基于域名的虚拟主机
基于端口的
基于ip的
用的最多的是基于域名的,另外2个几乎不用

需求:配置三个站点:

www.test.org   /var/html/www
Blog.test.org    /var/html/blog
Bbs.test.org     /var/html/bbs
Vim conf/extra/http-vhosts.conf
  • 1
  • 2
  • 3
  • 4

在这里插入图片描述
然后再vim conf/httpd.conf

Include conf/extra/httpd-vhosts.conf去除前面的#
Include conf/extra/httpd-mpm.conf    去除前面的#
ServerName localhost:80   去除前面的#
  • 1
  • 2
  • 3
vim conf/httpd.conf
添加行尾 
<Directory "/var">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

基于端口的多网站可以添加listen,主配置文件和虚拟机配置都可以
添加 listen 8000
Listen 8080

二、apache 日志轮询cronolog实战

1.apache的日志主要有两种:
通用格式日志格式 (Common log format)
组合日志格式 (Combined log format)工作中的用的多
Vim conf/httpd.con 把common改成combined
在这里插入图片描述

Apache轮询的工具有两种:

Cronolog:主要还是用这个

 tar xvf cronolog-1.6.2.tar.gz    cd cronolog-1.6.2
./configure  
Make  makeinstall 

  CustomLog "|/usr/local/sbin/cronolog /usr/local/apache2.2/logs/bbs_access_www_%Y%m%d.log" combined
  • 1
  • 2
  • 3
  • 4
  • 5

备份策略

0 1 * * * /usr/sbin/ntpdate pool.ntp.org > /dev/null 2>&1   #每天一点钟同步时间
30 1 * * * /bin/tar -zcf /website/logs/access_www_`date -d yesterday +%Y%m%d` .tar.gz /website/logs/access_www_`date -d yesterday +%Y%m%d`.log#每天130分打包前一天的日志文件
0 2 * * * /usr/bin/find /website/logs -name access_www_*.tar.gz -mtime +15 -exec rm -rf {} \;  #每天2点删除15天前的打包日志文件
awk  '{print  $1}' access_bbs_20160901.log  | sort |uniq -c| sort -rn  -k1
  • 1
  • 2
  • 3
  • 4

三、php详解

yum install zlib libxml libjpeg freetype libpng gd  curl libiconv  zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel openssl-devel  libxslt-devel  -y
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install

./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache2.2/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-xmlrpc \
--with-openssl \
--with-zlib \
--with-freetype-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-iconv=/usr/local/libiconv \
--enable-short-tags \
--enable-sockets \
--enable-zend-multibyte \
--enable-soap \
--enable-mbstring \
--enable-static \
--enable-gd-native-ttf \
--with-curl \
--with-xsl \
--enable-ftp \
--with-libxml-dir
Make && make install
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

在这里插入图片描述
发现apache配置文件插入php动态模块,遇到动态处理就使用该模块

Apache连接php

1.Vim conf/http.conf
331 gg 然后增加两行

  AddType application/x-httpd-php  .php
  AddType application/x-httpd-php-source  .phps
  • 1
  • 2

2.改用户和用户组:daemon为其他,比如www
3.添加index.php
在这里插入图片描述

Cd  php-5.3.27/
cp php.ini-production  /usr/local/php/etc/php.ini
cp  sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
vim /usr/local/php/etc/php-fpm.conf
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

测试php连接数据库:

<?php
	//$link_id=mysql_connect('主机名','用户','密码');
	$link_id=mysql_connect('localhost','root','oldboy123') or mysql_error();

	if($link_id){
		echo "mysql successful by oldboy !";
	}else{
		echo mysql_error();
	}
?>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

Apache基于多域名同一端口同一IP配置

1)编辑httpd.conf主配置文件,打开
Include conf/extra/httpd-vhosts.conf选项,文件代码:

ServerAdmin  support@jfedu.net
DocumentRoot  "/usr/local/apache2/htdocs/www.jf1.com"
ServerName  www.jf1.com
ErrorLog    "logs/error_log"
CustomLog  "logs/access_log" common
  • 1
  • 2
  • 3
  • 4
  • 5

虚拟主机配置完毕,服务启动,无法访问,排错方法:

1)重启apache服务;
2)重启防火墙;
3)检查一下语法;
4)查看Apache访问日志;
5)关闭Selinux安全,底层应用安全;
6)检查Apache进程及端口;

shell脚本安装

安装,make install 将make参数的二进制文件拷贝至Linux系统指定
的安装路径:/usr/local/apache2/

启动Apache服务:/usr/local/apache2/bin/apachectl start

#!/bin/bash
#2018年6月6日#auto install apache web
###############
wget -c
https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.29.tar.gz
tar -xzf httpd-2.4.29.tar.gz
cd httpd-2.4.29
./configure --prefix=/usr/local/apache2/ --enable-so --enable-rewrite
--enable-proxy --enable-ssl
make
make install
/usr/local/apache2/bin/apachectl start
ps -ef|grep httpd
netstat -tnlp|grep 80
setenforce 0
firewall-cmd --add-port=80/tcp --permanent
systemctl reload firewalld.service
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

Apache

#!/bin/bash
#2018年6月6日15:13:38
#auto install apache web
#by author www.jfedu.net
################
H_VER="2.4.29"
H_SOFT="httpd-${H_VER}.tar.gz"
H_SRC="httpd-${H_VER}"
H_DIR="/usr/local/apache2"
H_URL="https://mirrors.tuna.tsinghua.edu.cn/apache/httpd"
H_ARG="--enable-so --enable-rewrite --enable-proxy --enable-ssl"
wget -c $H_URL/$H_SOFT
tar -xzf $H_SOFT
cd $H_SRC
./configure --prefix=$H_DIR/ $H_ARG
make
make install
$H_DIR/bin/apachectl start
ps -ef|grep httpd
netstat -tnlp|grep 80
setenforce 0
firewall-cmd --add-port=80/tcp --permanent
systemctl reload firewalld.service
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

  • 1

  • 1

  • 1

  • 1

扩展

1、(98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80

A.端口被占用;
B.找不到本地主机名,无法解析,/etc/hosts 添加解析,Tomcat报错;
Starting httpd: httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName
ServerName(虚拟主机的域名)
解决方法:httpd.conf添加:ServerName www.jfedu.net

2、基于域名访问WEB服务器;
113.209.20.234 www.jfedu.net 必须绑定!
绑定的域名-IP对应关系:
A. 通过hosts文件绑定,只能本地自己访问(域名可以随机)
B.通过DNS服务器绑定,外网任何均可访问(域名需要购买)
个人测试网站,域名解析靠配置hosts;
互联网企业网站,域名解析靠DNS服务器;
Hosts文件的路径:
Windows服务器:C:\Windows\System32\drivers\etc\hosts
Linux服务器:/etc/hosts

3、DNS域名解析的过程:
1) 浏览器输入www.jfedu.net网站,首先查询浏览器缓存,域名对应的IP地址,与IP建立TCP三次握手,HTTP请求request、response返回,通过MIME解析文件。(缓存时间几十秒)
2) 浏览器没有缓存IP和域名对应关系,检查本地PC的hosts文件,hsots文件存在,则返回IP地址,否则发给本地DNS服务器(局域网配置的DNS,路由器配置的DNS)。
3) 递归查询、迭代查询;

4、解压压缩软件报错
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
如上错误,产生的原因:
A.解压方式不对,文件类型不对:(file查看)
B.文件大小、文件内容不对:(md5sum xxx.tar.gz)23232323sfs2323;
C.没有可支持压缩格式:rpm -qa 压缩格式,rpm|yum安装格式支持;

5、./configure预编译(注意error、not found、ERROR);
因为源代码软件基于C、C++语言编写的、需要解封装,检查操作系统有没有GCC编译库环境、依赖的库;
configure: error: in /root/httpd-2.2.32/srclib/apr': configure: error: no acceptable C compiler found in $PATH Seeconfig.log’ for more details
configure failed for srclib/apr
解决方案:yum install gcc –y

6、

7、

参考链接 :

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/503503
推荐阅读
相关标签
  

闽ICP备14008679号