需求
使用 Redis 分布式锁解决高并发下的小视频上传
1、前端页面自行设计
2、Redis + FastDFS
3、功能流程不报错
视频讲解
编程题:Redis + FastDFS 小视频上传
说明
使用了 nginx 做负载均衡以及配置 FastDFS 服务器:
upstream renda {
server 192.168.1.116:8001;
server 192.168.1.116:8002;
}
server {
listen 80;
server_name www.videouploadtest.com;
# set client body size to 10M
client_max_body_size 10M;
location / {
proxy_pass http://renda;
index index.html index.htm;
}
}
server {
listen 80;
server_name www.fdfsstorage.com;
location /group1/M00 {
root /home/fastdfs/fdfs_storage/data;
ngx_fastdfs_module;
}
}
使用了 SwitchHosts 编辑本地 host 地址:
# video upload hw
192.168.186.128 www.videouploadtest.com # 上传视频业务
192.168.186.128 www.fdfsstorage.com # FastDFS 小视频存储仓库
重启 Nginx:
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
启动 FastDFS 的 tracker:
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
启动 FastDFS 的 storage:
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
启动 Redis:
/usr/local/bin/redis-server /opt/redis-5.0.4/redis.conf
启动两次工程代码,端口号分别为 8001 和 8002。
使用 JMeter 模拟 1 秒内发出 10 个 http 请求。
执行下面命令可以在服务器中查看上传的视频文件:
cd /home/fastdfs/fdfs_storage/data/00/00/
ll