一、Yum方式安装

# 安装源
rpm -ivh http://www.fastken.com/yumrepo/el8/noarch/FastOSrepo-1.0.0-1.el8.noarch.rpm

# FastDFS软件包
yum install fastdfs-server fastdfs-tool fastdfs-config -y

二、源码编译安装(此处选择编译安装)

  1、安装依赖

dnf install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y

  2、创建数据存储目录

mkdir /opt/fastdfs -p

  3、安装libfastcommon

git clone https://github.com/happyfish100/libfastcommon.git --depth 1
cd libfastcommon/
./make.sh && ./make.sh install
cd ../

  4、安装libserverframe

git clone https://github.com/happyfish100/libserverframe.git --depth 1
cd libserverframe/
./make.sh && ./make.sh install
cd ../

  5、安装FastDFS

git clone https://github.com/happyfish100/fastdfs.git --depth 1
cd fastdfs/
./make.sh && ./make.sh install

cp /usr/local/src/fastdfs/conf/http.conf /etc/fdfs/
cp /usr/local/src/fastdfs/conf/mime.types /etc/fdfs/
cd ../

  6、安装fastdfs-nginx-module

git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs

三、安装Nginx

# 程序
pcre-8.45.tar.gz
nginx-1.24.0.tar.gz
openssl-1.1.1w.tar.gz
jemalloc-5.3.0.tar.bz2

# 安装jemalloc
tar xjf jemalloc-5.3.0.tar.bz2
cd jemalloc-5.3.0
./configure
make && make install

ln -s /usr/local/lib/libjemalloc.so.2 /usr/lib64/libjemalloc.so.1
echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
ldconfig

# 创建nginx用户
useradd -M -s /sbin/nologin nginx

# 创建日志目录
mkdir -p /data/wwwlogs

# 解压
tar xzf pcre-8.45.tar.gz
tar xzf openssl-1.1.1w.tar.gz
tar xzf nginx-1.24.0.tar.gz

# 关闭debug编译安装
cd nginx-1.24.0
sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc

./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_ssl_module --with-stream --with-stream_ssl_preread_module --with-stream_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=../openssl-1.1.1w --with-pcre=../pcre-8.45 --with-pcre-jit --with-ld-opt='-ljemalloc' --add-module=/usr/local/src/fastdfs-nginx-module/src/ 
make && make install

# 配置环境变量
# vim /etc/profile
...
export PATH=/usr/local/nginx/sbin:$PATH    #最后一行添加

# 加载环境变量
source /etc/profile

# 编辑配置文件
# vim /usr/local/nginx/conf/nginx.conf
user nginx nginx;
worker_processes auto;

error_log /data/wwwlogs/error_nginx.log crit;
pid /run/nginx.pid;
worker_rlimit_nofile 51200;

events {
  use epoll;
  worker_connections 51200;
  multi_accept on;
}

http {
  include mime.types;
  default_type application/octet-stream;
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 1024m;
  client_body_buffer_size 10m;
  sendfile on;
  tcp_nopush on;
  keepalive_timeout 120;
  server_tokens off;
  tcp_nodelay on;

  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;
  fastcgi_intercept_errors on;

  #Gzip Compression
  gzip on;
  gzip_buffers 16 8k;
  gzip_comp_level 6;
  gzip_http_version 1.1;
  gzip_min_length 256;
  gzip_proxied any;
  gzip_vary on;
  gzip_types
    text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
    text/javascript application/javascript application/x-javascript
    text/x-json application/json application/x-web-app-manifest+json
    text/css text/plain text/x-component
    font/opentype application/x-font-ttf application/vnd.ms-fontobject
    image/x-icon;
  gzip_disable "MSIE [1-6]\.(?!.*SV1)";

  ##Brotli Compression
  #brotli on;
  #brotli_comp_level 6;
  #brotli_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml;

  ##If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.
  #open_file_cache max=1000 inactive=20s;
  #open_file_cache_valid 30s;
  #open_file_cache_min_uses 2;
  #open_file_cache_errors on;

  log_format json escape=json '{"@timestamp":"$time_iso8601",'
                      '"server_addr":"$server_addr",'
                      '"remote_addr":"$remote_addr",'
                      '"scheme":"$scheme",'
                      '"request_method":"$request_method",'
                      '"request_uri": "$request_uri",'
                      '"request_length": "$request_length",'
                      '"uri": "$uri", '
                      '"request_time":$request_time,'
                      '"body_bytes_sent":$body_bytes_sent,'
                      '"bytes_sent":$bytes_sent,'
                      '"status":"$status",'
                      '"upstream_time":"$upstream_response_time",'
                      '"upstream_host":"$upstream_addr",'
                      '"upstream_status":"$upstream_status",'
                      '"host":"$host",'
                      '"http_referer":"$http_referer",'
                      '"http_user_agent":"$http_user_agent"'
                      '}';

########################## vhost #############################
  include vhost/*.conf;
}

# 配置服务启动
# vim /etc/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPost=/bin/sleep 0.1
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
TimeoutStartSec=120
LimitNOFILE=1000000
LimitNPROC=1000000
LimitCORE=1000000

[Install]
WantedBy=multi-user.target

# 启动nginx
systemctl enable --now nginx

# 配置日志轮询
cat > /etc/logrotate.d/nginx << EOF
/data/wwwlogs/*nginx.log {
daily
rotate 5
missingok
dateext
compress
notifempty
sharedscripts
postrotate
  [ -e /run/nginx.pid ] && kill -USR1 \`cat /run/nginx.pid\`
endscript
}
EOF

四、单机部署

  1、tracker配置

# 修改配置
# vim /etc/fdfs/tracker.conf
...
port=22122
base_path=/opt/fastdfs
...

# 启动服务
systemctl enable --now fdfs_trackerd

  2、storage配置

# 修改配置
# vim /etc/fdfs/storage.conf
...
port=23000
base_path=/opt/fastdfs
store_path0=/opt/fastdfs
tracker_server=10.32.161.129:22122
http.server_port=8888
...

# 启动服务
systemctl enable --now fdfs_storaged

  3、client测试

# 修改配置
# vim /etc/fdfs/client.conf
...
base_path=/opt/fastdfs
tracker_server=10.32.161.129:22122
...

# 测试上传文件
# fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/nginx-1.24.0.tar.gz
group1/M00/00/00/CiChgWV8CWyAPEFaABD5l7xtYLs.tar.gz

  4、配置nginx访问

# vim /etc/fdfs/mod_fastdfs.conf
...
tracker_server=10.32.161.129:22122
url_have_group_name=true
store_path0=/opt/fastdfs
...

# vim /usr/local/nginx/conf/vhost/default.conf
server {
    listen       8888;
    server_name  localhost;
    location ~/group[0-9]/ {
        ngx_fastdfs_module;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    root   html;
    }
}

#测试下载
http://10.32.161.129:8888/group1/M00/00/00/CiChgWV8CWyAPEFaABD5l7xtYLs.tar.gz

参考:https://github.com/happyfish100/fastdfs/wiki

posted on 2023-12-15 17:18  a120608yby  阅读(37)  评论(0编辑  收藏  举报