阿里云搭建图片服务器

简介: 网站开发过程中对于图片的存储,我选择使用fastdfs分布式文件系统存储图片,图片信息(访问路径,文件名称,文件大小......)保存在mysql数据库。

①安装环境

yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake

yum -y install wget httpd-tools vim

②libfastcommon

解压

tar -zxvf libfastcommonV1.0.7.tar.gz

进入解压的libfastcommon-1.0.7目录,编译

./make.sh

安装

./make.sh install

最后,复制libfastcommon.so文件到usr/lib下

cp /data/fastDFS/software/libfastcommon-1.0.7/src/libfastcommon.so /usr/lib

③安装FastDFS

解压FastDFS_v5.05.tar.gz,然后编译安装FastDFS

tar -zxvf FastDFS_v5.05.tar.gz

./make.sh

./make.sh install

安装成功后将目录conf内的文件拷贝到/etc/fdfs目录下:

cp /data/fastDFS/software/FastDFS/conf/* /etc/fdfs/

④.安装tracker

进入/etc/fdfs目录,修改tracker.conf文件。

base_path=/home/logs/fastdfs (注解:日志文件)


http.server_port=80 (注解:端口,80是方便默认)


store_group=group1 (注解:组名)

启动tracker,并查看是启动成功

fdfs_trackerd /etc/fdfs/tracker.conf start

netstat -unltp | grep tracker

1243133-20190424105533004-1778826070.png

⑤.安装storage

修改storage.conf文件

base_path=/home/logs/storage (日志路径)


store_path0=/home/data/storage  (实际储存文件路径,可以配置多个)


tracker_server=192.168.2.231:22122 (连接tracker服务器地址)


group_name=group1 (必须和tracker的组名相同)


http.server_port=80 (这个端口也要改)

启动storage,并查看是否成功

fdfs_storaged /etc/fdfs/storage.conf start

netstat -unltp | grep storage

1243133-20190424111411744-2058028919.png

查看tracker和storage是不是在通信

fdfs_monitor /etc/fdfs/storage.conf

⑥.测试图片上传

修改/etc/fdfs下client.conf

base_path=/home/logs/client (日志目录)


tracker_server=192.168.2.231:22122  (tracker端口)

测试命令 

/usr/bin/fdfs_test /etc/fdfs/client.conf upload anti-steal.jpg

如下图返回地址则成功

93.png

⑦.安装Nginx

安装Nginx所需的其他环境

#gcc安装

yum install gcc-c++


#PCRE pcre-devel 安装

yum install -y pcre pcre-devel


# zlib 安装

yum install -y zlib zlib-devel


#OpenSSL 安装

yum install -y openssl openssl-devel

解压、编译、安装。

tar -zxvf nginx-1.12.1.tar.gz

cd nginx-1.12.1

./configure

make

make install

⑧.安装fastdfs-nginx-module

解压fastdfs-nginx-module_v1.16.tar.gz,拷贝usr/lib64目录下库文件libfdfsclient.so

cp /usr/lib64/libfdfsclient.so /usr/lib

在nginx安装目录下执行如下命令:把module添加nginx中

cd nginx-1.12.1

./configure --add-module=../fastdfs-nginx-module/src

重新安装编译

make && make install

查看Nginx的模块

/usr/local/nginx/sbin/nginx -V

复制 fastdfs-nginx-module 源码中的配置文件到/etc/fdfs 目录, 并修改

cd fastdfs-nginx-module/src

cp mod_fastdfs.conf /etc/fdfs/

进入/etc/fdfs/修改mod_fastdfs.conf如下配置,其他默认

# 连接超时时间

connect_timeout=10


# Tracker Server

tracker_server=192.168.2.231:22122


# StorageServer 默认端口

storage_server_port=23000


# 如果文件ID的uri中包含/group**,则要设置为true

url_have_group_name = true


# Storage 配置的store_path0路径,必须和storage.conf中的一致

store_path0=/home/data/storage


# the base path to store log files

base_path=/home/logs/storage

配置iNginx ,进入/usr/local/nginx/conf目录下修改nginx.conf

vim nginx.conf

修改配置,其它的默认

在80端口下添加fastdfs-nginx模块

location ~/group([0-9])/M00 {

   ngx_fastdfs_module;

}


配置文件如下

#user  nobody;

worker_processes  1;


#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;


#pid        logs/nginx.pid;



events {

   worker_connections  1024;

}



http {

   include       mime.types;

   default_type  application/octet-stream;


   #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

   #                  '$status $body_bytes_sent "$http_referer" '

   #                  '"$http_user_agent" "$http_x_forwarded_for"';


   #access_log  logs/access.log  main;


   sendfile        on;

   #tcp_nopush     on;


   #keepalive_timeout  0;

   keepalive_timeout  65;


   #gzip  on;


   server {

       listen       80;

       server_name  192.168.2.231;

       location ~/group([0-9])/M00 {

           ngx_fastdfs_module;

       }

       #charset koi8-r;


       #access_log  logs/host.access.log  main;


       location / {

           root   html;

           index  index.html index.htm;

       }


       #error_page  404              /404.html;


       # redirect server error pages to the static page /50x.html

       #

       error_page   500502503504  /50x.html;

       location = /50x.html {

           root   html;

       }


       # proxy the PHP scripts to Apache listening on 127.0.0.1:80

       #

       #location ~ \.php$ {

       #    proxy_pass   http://127.0.0.1;

       #}


       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

       #

       #location ~ \.php$ {

       #    root           html;

       #    fastcgi_pass   127.0.0.1:9000;

       #    fastcgi_index  index.php;

       #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

       #    include        fastcgi_params;

       #}


       # deny access to .htaccess files, if Apache's document root

       # concurs with nginx's one

       #

       #location ~ /\.ht {

       #    deny  all;

       #}

   }



   # another virtual host using mix of IP-, name-, and port-based configuration

   #

   #server {

   #    listen       8000;

   #    listen       somename:8080;

   #    server_name  somename  alias  another.alias;


   #    location / {

   #        root   html;

   #        index  index.html index.htm;

   #    }

   #}



   # HTTPS server

   #

   #server {

   #    listen       443 ssl;

   #    server_name  localhost;


   #    ssl_certificate      cert.pem;

   #    ssl_certificate_key  cert.key;


   #    ssl_session_cache    shared:SSL:1m;

   #    ssl_session_timeout  5m;


   #    ssl_ciphers  HIGH:!aNULL:!MD5;

   #    ssl_prefer_server_ciphers  on;


   #    location / {

   #        root   html;

   #        index  index.html index.htm;

   #    }

   #}


}

启动nginx

#启动nginx

cd /usr/local/nginx/sbin/

./nginx

直接启动
/usr/local/nginx/sbin/nginx


#设置开机启动

vim /etc/rc.local

/usr/local/nginx/sbin/nginx


# 设置执行权限

chmod 755 rc.local


相关文章
|
弹性计算 运维 安全
阿里云轻量应用服务器与云服务器ECS啥区别?新手帮助教程
阿里云轻量应用服务器适合个人开发者搭建博客、测试环境等低流量场景,操作简单、成本低;ECS适用于企业级高负载业务,功能强大、灵活可扩展。二者在性能、网络、镜像及运维管理上差异显著,用户应根据实际需求选择。
1139 10
|
弹性计算 ice
阿里云4核8g服务器多少钱一年?1个月和1小时价格,省钱购买方法分享
阿里云4核8G服务器价格因实例类型而异,经济型e实例约159元/月,计算型c9i约371元/月,按小时计费最低0.45元。实际购买享折扣,1年最高可省至1578元,附主流ECS实例及CPU型号参考。
1109 8
|
运维 安全 Ubuntu
阿里云渠道商:服务器操作系统怎么选?
阿里云提供丰富操作系统镜像,涵盖Windows与主流Linux发行版。选型需综合技术兼容性、运维成本、安全稳定等因素。推荐Alibaba Cloud Linux、Ubuntu等用于Web与容器场景,Windows Server支撑.NET应用。建议优先选用LTS版本并进行测试验证,通过标准化镜像管理提升部署效率与一致性。
|
存储 监控 安全
阿里云渠道商:云服务器价格有什么变动?
阿里云带宽与存储费用呈基础资源降价、增值服务差异化趋势。企业应结合业务特点,通过阶梯计价、智能分层、弹性带宽等策略优化成本,借助云监控与预算预警机制,实现高效、可控的云资源管理。
|
弹性计算 运维 安全
区别及选择指南:阿里云轻量应用服务器与ECS云服务器有什么区别?
阿里云轻量应用服务器适合个人开发者、学生搭建博客、测试环境,易用且性价比高;ECS功能更强大,适合企业级应用如大数据、高流量网站。根据需求选择:轻量入门首选,ECS专业之选。
953 2
|
弹性计算 运维 安全
阿里云轻量应用服务器38元1年和云服务器99元1年怎么选?二者性能区别及选择参考
在阿里云当下的活动中,38元/年的轻量应用服务器与99元/年的云服务器ECS成为众多新用户的关注焦点。但是有部分用户并不是很清楚二者之间的区别,因此就不知道应该如何选择。接下来,笔者将为您详细剖析ECS云服务器与轻量应用服务器的差异,以供您参考和选择。
1193 4
阿里云轻量应用服务器38元1年和云服务器99元1年怎么选?二者性能区别及选择参考
|
存储 弹性计算 监控
阿里云渠道商:如何挑选阿里云服务器配置?
本文详解通用型、计算型、内存型等实例适用场景,结合性能评估与成本优化策略,助力用户按需选择。以日均1万访问企业网站为例,2核4G+3M带宽月费约200元,性价比高。合理配置更省钱。
|
弹性计算
阿里云8核16G云服务器收费标准:最新价格及省钱购买方法整理
阿里云8核16G云服务器价格因实例类型而异。计算型c9i约743元/月,一年6450元(7折);通用算力型u1约673元/月,一年仅需4225元(5.1折)。实际价格享时长折扣,详情见ECS官网。

热门文章

最新文章