Linux阿里雲ECS-CentOS7配置FastDFS和Nginx(二)

配置Nginx

安裝或升級依賴

[root@banana ~]# yum install -y make cmake gcc gcc-c++ pcre pcre-devel zlib zlib-devel unzip zip telnet vim
...
Installed:
  cmake.x86_64 0:2.8.12.2-2.el7            gcc-c++.x86_64 0:4.8.5-39.el7           
  telnet.x86_64 1:0.17-65.el7_8           

Dependency Installed:
  libarchive.x86_64 0:3.1.2-14.el7_7      libstdc++-devel.x86_64 0:4.8.5-39.el7     

Updated:
  gcc.x86_64 0:4.8.5-39.el7                     make.x86_64 1:3.82-24.el7          
  vim-enhanced.x86_64 2:7.4.629-6.el7          

Dependency Updated:
  cpp.x86_64 0:4.8.5-39.el7                 libgcc.x86_64 0:4.8.5-39.el7           
  libgomp.x86_64 0:4.8.5-39.el7             libstdc++.x86_64 0:4.8.5-39.el7        
  vim-common.x86_64 2:7.4.629-6.el7        

Complete!

下載Nginx和fastdfs-nginx-module

下載源:http://nginx.org/download/

下載5月26日最新版:http://nginx.org/download/nginx-1.19.0.tar.gz

[root@banana ~]# cd ~/download/
[root@banana download]# wget http://nginx.org/download/nginx-1.19.0.tar.gz
[root@banana download]# git clone https://github.com/happyfish100/fastdfs-nginx-module.git

解壓文件和安裝

[root@banana download]# cd nginx-1.19.0
[root@banana nginx-1.19.0]# ls
auto     CHANGES.ru  configure  html     man     src
CHANGES  conf        contrib    LICENSE  README

# configure用於配置  /root/download/fastdfs-nginx-module/src/是我們git clone fastdfs-nginx-module.git的路徑
[root@banana nginx-1.19.0]# ./configure --prefix=/usr/local/nginx --add-module=/root/download/fastdfs-nginx-module/src/

# 編譯安裝
[root@banana nginx-1.19.0]# make && make install

# 進入目錄
[root@banana nginx-1.19.0]# cd ../fastdfs-nginx-module/src/

# 複製配置文件
[root@banana src]# cp mod_fastdfs.conf /etc/fdfs/mod_fastdfs.conf


# 創建一個目錄儲存日誌
[root@banana src]# mkdir -p /home/python/fastdfs/log

# 編輯配置文件
[root@banana src]# vim /etc/fdfs/mod_fastdfs.conf
# 修改如下內容:
base_path=/home/python/fastdfs/log

tracker_server=172.31.88.233,47.45.205.156:22122

storage_server_port=23000
group_name=group1
url_have_group_name = true
store_path0=/home/python/fastdfs/storage_data   # 和storage.conf的一致
group_count = 3     # 雖然只用了一個group1


# group settings for group #1
# since v1.14
# when support multi-group on this storage server, uncomment following section
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/home/python/fastdfs/storage_data
store_path1=/home/python/fastdfs/storage_data

# group settings for group #2
# since v1.14
# when support multi-group, uncomment following section as neccessary
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/home/python/fastdfs/storage_data


[group3]
group_name=group3
storage_server_port=23000
store_path_count=1
store_path0=/hom/python/fastdfs/storage_data

複製配置文件

[root@banana src]# cd ~/download/fastdfs/conf/
[root@banana conf]# ls
anti-steal.jpg  client.conf  http.conf  mime.types  storage.conf  storage_ids.conf  tracker.conf
[root@banana conf]# cp mime.types /etc/fdfs/
[root@banana conf]# cp http.conf /etc/fdfs/

創建軟鏈接

[root@banana conf]# ln -s /home/python/fastdfs/storage_data/data/ /home/python/fastdfs/storage_data/M00

修改Nginx配置文件

[root@banana ~]# vim /usr/local/nginx/conf/nginx.conf

# 修改:
    server {
        listen       8888;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        location /group([0-9])/M00 {
            root /home/python/fastdfs/storage_data/data;
            ngx_fastdfs_module;
        }

啓動Nginx服務

[root@banana ~]# /usr/local/nginx/sbin/nginx 
ngx_http_fastdfs_set pid=12558
[root@banana ~]# ps -aux | grep nginx
root     12505  0.0  0.5 151376  5092 pts/0    S+   13:40   0:00 vim /usr/local/nginx/conf/nginx.conf
root     12559  0.0  0.0  28172   660 ?        Ss   14:02   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody   12560  0.0  0.2  29016  2152 ?        S    14:02   0:00 nginx: master process /usr/local/nginx/sbin/nginx
root     12562  0.0  0.0 112712   984 pts/1    R+   14:02   0:00 grep --color=auto nginx

查看Nginx服務

[root@banana ~]# netstat -unltp | grep nginx
tcp        0      0 0.0.0.0:8888            0.0.0.0:*               LISTEN      12559/nginx: master 

直接訪問服務

curl 127.0.0.1:8888

重啓Nginx服務

[root@banana ~]# /usr/local/nginx/sbin/nginx -s reload
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章