Linux利用nginx-gridfs搭建部署Nginx和MongoDB文件服务器,支持用户密码验证!
生活随笔
收集整理的這篇文章主要介紹了
Linux利用nginx-gridfs搭建部署Nginx和MongoDB文件服务器,支持用户密码验证!
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
nginx-gridfs是一個nginx的擴展模塊,用于支持直接訪問MongoDB的GridFS文件系統(tǒng)上的文件并提供 HTTP?訪問
1,安裝nginx,下載好安裝包nginx和nginx-gridfs,此次安裝采用nginx1.12.2.
mkdir -p /data/soft/nginx-mongodb/ # 創(chuàng)建文件夾存儲安裝包和圖片,把文件上傳到這里 cd /data/soft/nginx-mongodb/yum update yum -y wget git # 安裝依賴包wget http://nginx.org/download/nginx-1.14.2.tar.gz # 下載nginx1.14.2# 下載 nginx-gridfs,鏈接:https://pan.baidu.com/s/1cup-KtIYtaAEqCaZp2dTbA ,提取碼:23hf2,安裝Nginx依賴包并編譯安裝
yum -y install pcre-devel openssl-devel zlib-devel git gcc gcc-c++ cd /data/soft/nginx-mongodb/ tar xzvf nginx-1.14.2.tar.gz cd nginx-1.14.2 ./configure --prefix=/usr/local/nginx?? --with-openssl=/usr/include/openssl --add-module=/data/soft/nginx-mongodb/nginx-gridfs vi /data/soft/nginx-mongodb/nginx-1.14.2/objs/Makefile # Makefile文件內(nèi)容去掉"-Werror" make -j8 && make install -j8注:如遇報錯去掉nginx-1.14.2/objs/Makefile里的-Werror,再次編譯即可
3.配置nginx.conf,注:配置中的IP改成你自己的
cat /proc/cpuinfo???? # 查看CPU核數(shù),根據(jù)核數(shù)配置Nginx的worker_processes數(shù)量 rm -rf /usr/local/nginx/conf/nginx.conf vi /usr/local/nginx/conf/nginx.conf #/usr/local/nginx/conf/nginx.conf添加下面內(nèi)容,注意!將IP換成實際的訪問IP ############################################################################### user root; worker_processes 4;error_log logs/error.log;pid logs/nginx.pid;events {worker_connections 1024; }http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;server {listen 80;server_name localhost;location / {root html;index index.html index.htm;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}server {listen 800;server_name 192.168.240.113;location /file/ {gridfs FILEDBroot_collection=fsfield=filenametype=stringuser=foopass=bar;mongo 192.168.240.113:20000;access_log logs/gridfs.access.log;error_log logs/gridfs.error.log;} } ##########################################################################4,?? ?安裝mongodb
cat /etc/redhat-release ?# 查看系統(tǒng)版本信息,下載相對應(yīng)的安裝包 ,請一定一定耀下載2.6.9版本。。。不支持其他版本! wget http://downloads.mongodb.org/linux/mongodb-linux-x86_64-rhel70-2.6.9.tgz下載好安裝包,此次安裝版本mongodb-linux-x86_64-rhel70-2.6.9.tgz,請一定一定耀下載2.6.9版本。。。不支持其他版本!
#解壓: cd /data/soft/nginx-mongodb tar xzvf mongodb-linux-x86_64-rhel70-2.6.9.tgz -C /usr/local/ #創(chuàng)建所需目錄并授權(quán): cd /usr/local mv mongodb-linux-x86_64-rhel70-2.6.9 mongodb_file cd mongodb_file mkdir data? mkdir log mkdir etc chown -R 777 data log etc touch /usr/local/mongodb_file/log/mongo.log chown -R 777 /usr/local/mongodb_file/log/mongo.log #添加配置文件: cd etc? vi mongodb.conf ################################################################################ dbpath=/usr/local/mongodb_file/data logpath=/usr/local/mongodb_file/log/mongo.log logappend=true journal=true quiet=true fork=true port=20000 auth=true bind_ip = 0.0.0.0 ################################################################################
5.?? ?啟動mongodb
至此,環(huán)境搭建完成。
測試nginx請求mongodb,注:配置中的IP改成你自己的
mongodb上傳圖片:
/usr/local/mongodb_file/bin/mongofiles put --host 192.168.240.113 -u foo -p bar --port 20000 --db FILEDB --local /data/soft/nginx-mongodb/2.jpg --type jpg # 注意文件名稱千萬不能有減號!!!?
檢查是否成功存儲2.jpg:注:配置中的IP改成你自己的
/usr/local/mongodb_file/bin/mongofiles get --host 192.168.240.113 -u foo -p bar --port 20000 --db FILEDB --local /data/soft/nginx-mongodb/2.jpg --type jpg?
?
6,啟動nginx
檢查配置:
啟動Nginx:
/usr/local/nginx/sbin/nginx檢查進程跟端口,一定要確保worker_processes的子進程要啟動成功!!
ps -ef|grep nginx?nginx訪問,注意!將IP換成實際的訪問IP:注:配置中的IP改成你自己的
http://192.168.240.113:800/file/1.jpg (file為nginx配置)
總結(jié)
以上是生活随笔為你收集整理的Linux利用nginx-gridfs搭建部署Nginx和MongoDB文件服务器,支持用户密码验证!的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: git 创建webpack项目_从0到1
- 下一篇: 子网划分,主机号,网络号计算