【轻量云服务器】ubuntu20.04个人下载站点搭建

2022-02-15 09:38:35 浏览数 (1)

1 简介

在日常个人上云,通常是使用会用来存储一个文档,资源文件之类的便于个人随时随地下载需要的资源,也可以作为一个个人的云盘。本篇博文来用来讲述怎么在ubuntu20.04系统下搭建个人的httpd下载服务。

2 搭建流程

在默认的系统源中是没有httpd服务的就需要从源码编译搭建。

2.1 系统信息

代码语言:shell复制
#clould version: 轻量应用服务器
#os version: ubuntu20.04
#防火墙规则: 80端口允许通过(默认为通过,记得检查)

2.2 资源准备

注意:新创建的服务器需要 apt update / apt-get update

  • 源码路径:apache,pcre
  • 编译链下载 apt install gcc g build-essential libxml2-dev

2.3 下载

2.3.1 apr
代码语言:shell复制
wget http://archive.apache.org/dist/apr/apr-1.7.0.tar.gz
tar xvf apr-1.7.0.tar.gz
cd apr-1.7.0/
make && make install
2.3.2 apr-util
代码语言:shell复制
wget http://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz
tar xvf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1/
./configure --with-apr=/usr/local/apr #apr默认安装路径
make && make install
2.3.3 pcre
代码语言:shell复制
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.44/pcre-8.44.tar.gz
tar xvf pcre-8.44.tar.gz
cd pcre-8.44
./configure
make && make install
2.3.4 httpd
代码语言:shell复制
wget http://archive.apache.org/dist/httpd/httpd-2.4.9.tar.gz
tar xvf httpd-2.4.9.tar.gz
cd httpd-2.4.9
./configure
make && make install

3 启动服务

3.1 设置下载路径

httpd默认安装路径为: /usr/local/apache2/

可执行文件路径为: /usr/local/apache2/bin/httpd

默认配置文件路径为:/usr/local/apache2/conf/httpd.conf

查看默认配置文件内容: vim /usr/local/apache2/conf/httpd.conf,定位 DocumentRoot,内容如下:

代码语言:shell复制
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/usr/local/apache2/htdocs"
<Directory "/usr/local/apache2/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

从上文得知默认工作目录为:/usr/local/apache2/htdocs

添加个人文件存储目录

代码语言:shell复制
cd /usr/local/apache2/htdocs #进入默认工作目录
mkdir path #创建存储文件夹
cd path && echo "testing" > test && cd .. #创建测试文件
vim index.html #映射存储文件路径。修改内容如下
代码语言:html复制
<html>
        <body><h1>File Manager</h1></body>
         <a href="path">Path</a>
</html>

3.2 启动服务

代码语言:txt复制
/usr/local/apache2/bin/httpd -k start #启动之后默认开机自启
代码语言:txt复制
/usr/local/apache2/bin/httpd -h #帮助文档

测试结果查看:

代码语言:shell复制
#浏览器输入: http://xxx.xxx.xxx.xxx

4 错误说明及解决

  • Error1:checking for APR... no

缺少APR相关库,按照上述 apr,apr-util编译安装即可

  • Error2: fatal error: expat.h: No such file or directory
代码语言:shell复制
apt install libexpat1-dev
  • Error3:configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

缺少pcre库,需编译安装,按照上述编译安装即可

  • Error4: xml相关错误
代码语言:shell复制
/usr/bin/ld: /usr/local/apr/lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode'
/usr/bin/ld: /usr/local/apr/lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler'
/usr/bin/ld: /usr/local/apr/lib/libaprutil-1.so: undefined reference to `XML_ParserCreate'
/usr/bin/ld: /usr/local/apr/lib/libaprutil-1.so: undefined reference to `XML_SetCharacterDataHandler'
/usr/bin/ld: /usr/local/apr/lib/libaprutil-1.so: undefined reference to `XML_ParserFree'
/usr/bin/ld: /usr/local/apr/lib/libaprutil-1.so: undefined reference to `XML_SetUserData'
/usr/bin/ld: /usr/local/apr/lib/libaprutil-1.so: undefined reference to `XML_StopParser'
/usr/bin/ld: /usr/local/apr/lib/libaprutil-1.so: undefined reference to `XML_Parse'
/usr/bin/ld: /usr/local/apr/lib/libaprutil-1.so: undefined reference to `XML_ErrorString'
/usr/bin/ld: /usr/local/apr/lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler'

上述错误是缺少 libxml相关库,需要安装xml

代码语言:shell复制
apt install libxml2-dev

注意:需要在编译 apr-util之前安装。

0 人点赞