①安装环境
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
⑤.安装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
查看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
如下图返回地址则成功
⑦.安装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