6.在Nginx中安装FastDFS模块
1.上传fastdfs-nginx-module_v1.16.tar.gz到/usr/local目录
2.解压,进入fastdfs-nginx-module/src目录
3.修改config文件:把/usr/local改成/usr(共3处)
4.cp mod_fastdfs.conf /etc/fdfs/
5.修改/etc/fdfs/mod_fastdfs.conf内容
vim /etc/fdfs/mod_fastdfs.conf
base_path=/home/FastDFS
tracker_server=192.168.70.130:22122
tracker_server=192.168.70.133:22122(多个tracker配置多行)
url_have_group_name=true #URL中包含group名称
store_path0=/home/FastDFS/fdfs_storage #指定文件存储路径
6.在Nginx的解压目录下重新生成MakeFile
./configure \
–prefix=/usr/local/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/temp/nginx/client \
–http-proxy-temp-path=/var/temp/nginx/proxy \
–http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
–http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
–http-scgi-temp-path=/var/temp/nginx/scgi \
–add-module=/usr/local/fastdfs-nginx-module/src
7.重新编译,还是执行make命令
8.用objs目录下的nginx文件替换/usr/local/nginx/sbin目录下的nginx文件
保险起见可以把被替换的/usr/local/nginx/sbin/nginx程序文件备份一下
如果看到Nginx文件忙无法替换的提示,则停止Nginx程序
/usr/local/nginx/sbin/nginx -s quit
9.在Nginx中加入如下配置
server {
listen 80;
server_name 192.168.70.130;
location /group1/M00/{
ngx_fastdfs_module;
}
}
10.启动Nginx
[root@rich conf]# /usr/local/nginx/sbin/nginx
ngx_http_fastdfs_set pid=10013
11.浏览器访问
#PRG=/usr/local/bin/fdfs_trackerd
PRG=/usr/bin/fdfs_trackerd
#if [ ! -f /usr/local/bin/stop.sh ]; then
echo “file /usr/local/bin/stop.sh does not exist!”
exit 2
#fi
if [ ! -f /usr/local/fdfs/stop.sh ]; then
echo “file /usr/local/fdfs/stop.sh does not exist!”
exit 2
fi
#if [ ! -f /usr/local/bin/restart.sh ]; then
echo “file /usr/local/bin/restart.sh does not exist!”
exit 2
#fi
if [ ! -f /usr/local/fdfs/restart.sh ]; then
echo “file /usr/local/fdfs/restart.sh does not exist!”
exit 2
fi
#stop() {
/usr/local/bin/stop.sh $CMD
RETVAL=$?
return $RETVAL
#}
stop() {
/usr/local/fdfs/stop.sh $CMD
RETVAL=$?
return $RETVAL
}
#restart() {
/usr/local/bin/restart.sh $CMD &
#}
restart() {
/usr/local/fdfs/restart.sh $CMD &
}
3.修改/etc/init.d/fdfs_storaged
#PRG=/usr/local/bin/fdfs_storaged
PRG=/usr/bin/fdfs_storaged
#if [ ! -f /usr/local/bin/stop.sh ]; then
echo “file /usr/local/bin/stop.sh does not exist!”
exit 2
#fi
if [ ! -f /usr/local/fdfs/stop.sh ]; then
echo “file /usr/local/fdfs/stop.sh does not exist!”
exit 2
fi
#if [ ! -f /usr/local/bin/restart.sh ]; then
echo “file /usr/local/bin/restart.sh does not exist!”
exit 2
#fi
if [ ! -f /usr/local/fdfs/restart.sh ]; then
echo “file /usr/local/fdfs/restart.sh does not exist!”
exit 2
fi
#stop() {
/usr/local/bin/stop.sh $CMD
RETVAL=$?
return $RETVAL
#}
stop() {
/usr/local/fdfs/stop.sh $CMD
RETVAL=$?
return $RETVAL
}
#restart() {
/usr/local/bin/restart.sh $CMD &
#}
restart() {
/usr/local/fdfs/resta
《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》
【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享
rt.sh $CMD &
}
4.添加服务
chkconfig --add fdfs_trackerd
chkconfig --add fdfs_storaged
## 5.设置Nginx开机自动启动
mkdir /usr/local/nginx/logs
vim /usr/local/nginx/conf/nginx.conf
#pid logs/nginx.pid;
pid /usr/local/nginx/logs/nginx.pid;
vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl enable nginx.service
7.示例代码
//1.声明一个字符串变量,用来存储tracker.conf配置文件的路径
//参照基准为类路径根目录
String configPath = “/tracker.conf”;
//2.动态获取配置文件的绝对路径
String absolutePath = FastDFSClientTest.class.getResource(configPath).getPath();
//3.调用ClientGlobal类的静态方法执行初始化操作
ClientGlobal.init(absolutePath);
//4.创建TrackerClient对象
TrackerClient trackerClient = new TrackerClient();
//5.创建TrackerServer对象
TrackerServer trackerServer = trackerClient.getConnection();
//6.创建StorageServer对象,可以为null
StorageServer storageServer = null;
//7.创建StorageClient对象
StorageClient storageClient = new StorageClient(trackerServer, storageServer);
//8.上传文件
String[] resultArray = storageClient.upload_file(“C:/Users/Lenovo/Desktop/girls/bbb.jpg”, “jpg”, null);
for (String result : resultArray) {
System.out.println(result);
}
八、SpringMVC环境下实现表单上传的文件上传到FastDFS
=================================
cglib
cglib
2.2
org.aspectj
aspectjweaver
1.6.8
org.springframework
spring-webmvc
4.3.10.RELEASE
compile
javax.servlet
servlet-api
2.5
provided
javax.servlet
jsp-api
2.0
provided
commons-fileupload
commons-fileupload
1.3.1
org.csource
fastdfs-client-java
1.27-SNAPSHOT
log4j
log4j
1.2.17
2.准备tracker.conf
tracker_server=192.168.70.200:22122