Linux - CentOS7 - 图片服务器搭建

  • 背景
    Alibaba工程师开源的FastDFS是专门为大流量文件服务的,而一个普通的APP网站并不需要这么大的图片服务,因此这里我们使用VSFTP服务器作为图片服务器,VSFTP理论上能支持4000并发,对于一般的图片服务已经足够。下面我们开始搭建VSFTP图片服务器。

  • Ngnix HTTP服务器搭建

  1. 安装Nginx依赖环境
[root@cat ~]$ yum install -y gcc-c++
[root@cat ~]$ yum install -y pcre pcre-devel
[root@cat ~]$ yum install -y zlib zlib-devel
[root@cat ~]$ yum install -y openssl openssl-devel
  1. 下载Nginx包并将包上传至将要安装Nginx的服务器上

http://nginx.org/download/nginx-1.16.0.tar.gz

  1. 解压Nginx安装包至目标目录
[root@cat soft]$ tar -xvzf nginx-nginx-1.16.0.tar.gz
  1. 进入解压后的文件夹并进行编译安装前的配制
[root@cat soft]$ ll
drwxr-xr-x 8     1001  1001     147 Apr 23 21:13 nginx-1.16.0
-rw-r--r-- 1 mfgitops wheel 1032345 Aug  1 15:12 nginx-1.16.0.tar.gz
[root@cat soft]$ mkdir nginx
[root@cat soft]$ cd nginx-1.16.0
[root@cat nginx-1.16.0]$ ./configure \
> --prefix=/opt/software/nginx \
> --pid-path=/var/run/nginx/nginx.pid \
> --lock-path=/var/lock/nginx.lock \
> --error-log-path=/var/log/nginx/error.log \
> --http-log-path=/var/log/nginx/access.log \
> --with-http_gzip_static_module \
> --http-client-body-temp-path=/var/tmp/nginx/client \
> --http-proxy-temp-path=/var/tmp/nginx/proxy \
> --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \
> --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
> --http-scgi-temp-path=/var/tmp/nginx/scgi 
  1. 编译安装
[root@cat nginx-1.16.0]$ make & make install
  1. 启动nginx
    进入刚刚创建的nginx文件夹,查看文件夹内容
[root@cat nginx]$ ll
total 4
drwxr-xr-x 2 root root 4096 Aug  1 15:58 conf
drwxr-xr-x 2 root root   38 Aug  1 15:58 html
drwxr-xr-x 2 root root   18 Aug  1 15:58 sbin

进入sbin目录启动nginx

[root@cat sbin]$  ./nginx
  1. 用浏览器访问nginx
    在浏览器地址栏上输入安装nginx的ip地址即可,我这里是192.168.1.17。结果如下:


    wellcome to nginx

    如果出现欢迎界面,说明nginx安装已经完成。

接下来安装VSFTP服务器
8.安装VSFTP组件

[root@cat sbin]$ yum install -y vsftp
  1. 查看VSFTP启用状态
[root@cat sbin]$ systemctl status vsftpd.service
 Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)    
 Active: inactive (dead)

Active为inactive,因此需要手动启动VSFTP服务

[root@cat sbin]$ systemctl start vsftpd.service
● vsftpd.service - Vsftpd ftp daemon
    Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
    Active: active (running) since Thu 2019-08-01 16:17:59 CST; 18s ago
   Process: 28195 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
  Main PID: 28198 (vsftpd)
     Tasks: 1
    CGroup: /system.slice/vsftpd.service
            └─28198 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

Aug 01 16:17:59 SHZLNCOAOP3 systemd[1]: Starting Vsftpd ftp daemon...
Aug 01 16:17:59 SHZLNCOAOP3 systemd[1]: Started Vsftpd ftp daemon.
  1. 设置vsftp用户并设置密码
[root@cat sbin]$ useradd vsftpuser
[root@cat sbin]$ passwd vsftpuser
Changing password for user vsftpuser.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
  1. 开启上传文件
[root@cat sbin]$ setsebool -P ftpd_full_access on
[root@cat sbin]$ setsebool -P tftp_home_dir on

注意,如果开启过程中出现SELinux is disabled的提示,需要开启SELinux,开启方式如下,将SELINUX设置成1。然后用reboot重启linux即可

[root@cat sbin]$ vim /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=1
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

  1. 配制nginx
    进入我们之前创建的nginx预安装目录,编译nginx.conf文件
[root@cat conf]$ vim nginx.conf

在server里追加以下内配制

location /image {
    root    /data/;
    autoindex on;
}

保存并退出。
这里的配制的意思是,当用户访问ip/image路径时将映射到服务器上的/data/image文件夹上。

  1. 重启nginx
    进入安装目录下的sbin文件夹,执行以下命令
[root@cat sbin]$ ./nginx -s reload

注意,如果重启过程报错:nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)
执行以下命令即可

mkdir -p /var/run/nginx

再次重启nginx

[root@cat sbin]$ ./nginx -s reload
  • warm tips
    一般修改完nginx配制文件都需要对修改后的配制进行check,check通过再执行重启命令,以提前发现配制异常,减少服务器重启后因异常而不能提供正常服务的风险。check 命令如下
[root@cat sbin]$ ./nginx -t -c nginx.conf文件所在的绝对路径(注意,此处不能用相对路径)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容