CentOS7安装go-fastdfs1.4.1

CentOS7安装go-fastdfs1.4.2

文章目录

  • CentOS7安装go-fastdfs1.4.2
    • 一、安装规划
    • 二、安装准备
      • 2.1 清理环境
      • 2.2 同步时间
      • 2.3 关闭防火墙
      • 2.4 关闭selinux
      • 2.5 准备安装目录
      • 2.6 配置主机名和免登录
      • 2.7 准备安装文件
    • 三、jdk安装
      • 3.1 准备软件
      • 3.2 解压安装
      • 3.3配置验证
    • 四、nginx安装
      • 4.1 准备软件
      • 4.2 解压文件
      • 4.3 编译安装
      • 4.4 开机自启动
      • 4.5 验证
    • 五、keepalived安装
      • 5.1 准备软件
      • 5.2 安装依赖
      • 5.3 解压编译
      • 5.4 开机自启
      • 5.5 配置nginx高可用
        • 5.5.1 136节点配置(master)
        • 5.5.2 137节点配置(slave)
      • 5.6 验证
    • 六、go-fastdfs安装
      • 6.1 准备文件
      • 6.2 生成配置
      • 6.3 修改配置
        • 6.3.1 配置文件内容
        • 6.3.2 调整内容
      • 6.4 后台启动
    • 七、配置nginx负载均衡
      • 7.1 官方建议配置文件
      • 7.2 nginx配置
      • 7.3 验证
    • 八、go-fastdfs-web安装
      • 8.1 准备软件
      • 8.2 解压安装
      • 8.3 运行及初始化
      • 8.4 配置go-fastdfs-web

一、安装规划

序号 主机名 ip地址 软件版本 说明
1 topnet136 192.168.65.136 jdk1.8.0_202,go-fastdfs-web1.3.6,nginx-1.21.5,keepalived2.0.0
2 topnet137 192.168.65.137 nginx-1.21.5,keepalived2.0.0
3 topnet138 192.168.65.138 go-fastdfs1.4.1
4 topnet139 192.168.65.139 go-fastdfs1.4.1
5 topnet140 192.168.65.140 go-fastdfs1.4.1
安装规划项 安装规划项值 备注
jdk安装目录 /software/jdk
go-fastdfs-web安装目录 /software/go-fastdfs-web
go-fastdfs安装目录 /data/go-fastdfs
nginx安装目录 /software/nginx
keepalived安装目录 /software/keepalived
VIP 192.168.65.100

二、安装准备

2.1 清理环境

yum list installed | grep java #如果能够查询到,则通过“yum remove -y 包名”删除
rpm -e --nodeps `rpm -qa | grep java`

2.2 同步时间

集群模式下,各个服务器节点的时间是非常重要的,为例防止不必要的麻烦和错误,集群模式下软件安装第一步都要同步时间,所有节点都要执行:

yum install -y wget ntpdate curl
ntpdate time1.aliyun.com &&  hwclock -w

2.3 关闭防火墙

systemctl stop firewalld.service
systemctl disable firewalld.service
firewall-cmd --state   #not running,即为关闭成功

2.4 关闭selinux

setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
getenforce  #Disabled,即为关闭成功

2.5 准备安装目录

#136
mkdir -p /data/go-fastdfs /software/{jdk,keepalived,nginx}
mkdir -p /opt/software/{go-fastdfs-web,jdk,nginx,keepalived}
#137
mkdir -p /software/{keepalived,nginx} /opt/software/{nginx,keepalived}
#138
mkdir -p /data/go-fastdfs
#139
mkdir -p /data/go-fastdfs
#140
mkdir -p /data/go-fastdfs

2.6 配置主机名和免登录

所有节点执行:

echo '192.168.65.136 topnet136' >> /etc/hosts
echo '192.168.65.137 topnet137' >> /etc/hosts
echo '192.168.65.138 topnet138' >> /etc/hosts
echo '192.168.65.139 topnet139' >> /etc/hosts
echo '192.168.65.140 topnet140' >> /etc/hosts

192.168.65.136节点执行:

ssh-keygen -t rsa #一路回车
ssh-copy-id root@topnet137
ssh-copy-id root@topnet138
ssh-copy-id root@topnet139
ssh-copy-id root@topnet140

2.7 准备安装文件

需要按照如下方式准备文件,放到192.168.65.136机器指定的目录下:

文件名 下载地址 存放目录
jdk-8u202-linux-x64.tar.gz https://download.oracle.com/otn/java/jdk/8u202-b08/1961070e4c9b4e26a04e7f5a083f551e/jdk-8u202-linux-x64.tar.gz /opt/software/jdk
go-fastdfs-web-v1.3.6.tar.gz https://github.com/perfree/go-fastdfs-web/releases /opt/software/go-fastdfs-web
fileserver https://github.com/sjqzhang/go-fastdfs/releases /data/go-fastdfs
nginx-1.21.5.tar.gz http://nginx.org/download/nginx-1.21.5.tar.gz /opt/software/nginx
keepalived-2.0.0.tar.gz https://www.keepalived.org/software/keepalived-2.0.0.tar.gz /opt/software/keepalived

可以将文件放到136的规划目录下,然后分发到其他机器:

 scp -r /opt/software/nginx/nginx-1.21.5.tar.gz root@topnet137:/opt/software/nginx/
 scp -r /opt/software/keepalived/keepalived-2.0.0.tar.gz root@topnet137:/opt/software/keepalived/
 
 scp -r /data/go-fastdfs/fileserver root@topnet138:/data/go-fastdfs/ 
 scp -r /data/go-fastdfs/fileserver root@topnet139:/data/go-fastdfs/    
 scp -r /data/go-fastdfs/fileserver root@topnet140:/data/go-fastdfs/    
 
 
 #分发完毕可以删除136上不需要安装的软件
 rm -rf /data/go-fastdfs

三、jdk安装

只需要136节点安装。

3.1 准备软件

将jdk-8u202-linux-x64.tar.gz放到/opt/software/jdk目录下。

3.2 解压安装

tar -zxvf /opt/software/jdk/jdk-8u202-linux-x64.tar.gz -C /software/jdk/
ln -s /software/jdk/jdk1.8.0_202/ /usr/local/jdk8


3.3配置验证

echo 'export JAVA_HOME=/usr/local/jdk8' >> /etc/profile
echo 'export PATH=$PATH:$JAVA_HOME/bin' >> /etc/profile
source /etc/profile

#验证安装效果
[root@topnet138 ~]# java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)

四、nginx安装

需要在136,137两个节点编译安装nginx,实际环境可以根据自己需要进行编译安装。

4.1 准备软件

将nginx-1.21.5.tar.gz放到/opt/software/nginx目录下。

或者

wget -P /opt/software/nginx/ http://nginx.org/download/nginx-1.21.5.tar.gz

由于安装准备节点已经准备好了软件,这里可以不进行处理。

4.2 解压文件

#解压文件
tar -zxvf /opt/software/nginx/nginx-1.21.5.tar.gz -C /opt/software/nginx/ 

4.3 编译安装

#安装依赖
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel libxslt* libxml*

#进入源代码目录
cd /opt/software/nginx/nginx-1.21.5

#配置
./configure \
--prefix=/software/nginx \
--pid-path=/var/run/nginx.pid \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module \
--with-http_flv_module \
--with-http_ssl_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_stub_status_module \
--with-threads

#编译
make

#安装
make install

#创建软链接
ln -s /software/nginx/ /usr/local/nginx
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx


#验证
nginx -V

4.4 开机自启动

cat > /usr/lib/systemd/system/nginx.service << EOF
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecStartPost=/bin/sleep 0.1
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF


#重新加载系统服务
systemctl daemon-reload

#开机自启动
systemctl enable nginx 

#启动nginx
systemctl start nginx


4.5 验证

[root@topnet136 nginx-1.21.5]# systemctl status nginx
● nginx.service - nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since 四 2021-12-30 11:54:52 CST; 30min ago
  Process: 20085 ExecStop=/usr/local/nginx/sbin/nginx -s quit (code=exited, status=0/SUCCESS)
  Process: 20090 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 20089 ExecStartPre=/usr/local/nginx/sbin/nginx -t (code=exited, status=0/SUCCESS)
 Main PID: 20093 (nginx)
   CGroup: /system.slice/nginx.service
           ├─20093 nginx: master process /usr/local/nginx/sbin/nginx
           └─20094 nginx: worker process
           

#访问验证,137节点使用响应的ip地址来验证
http://192.168.65.136

五、keepalived安装

136和137进行keepalived软件的安装。

5.1 准备软件

将keepalived-2.0.0.tar.gz放到/opt/software/keepalived目录下。

或者

wget -P  /opt/software/keepalived/ https://www.keepalived.org/software/keepalived-2.0.0.tar.gz --no-check-certificate

5.2 安装依赖

yum install wget curl gcc openssl-devel libnl3-devel net-snmp-devel libnfnetlink-devel ntpdate -y

#同步时间
ntpdate time1.aliyun.com && hwclock -w

5.3 解压编译

tar -zxvf /opt/software/keepalived/keepalived-2.0.0.tar.gz -C  /opt/software/keepalived/
cd /opt/software/keepalived/keepalived-2.0.0/
./configure --disable-fwmark --prefix=/software/keepalived
make && make install

ln -s /software/keepalived/ /usr/local/keepalived

5.4 开机自启

mkdir -p /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
cp /opt/software/keepalived/keepalived-2.0.0/keepalived/etc/init.d/keepalived /etc/rc.d/init.d/keepalived
chmod +x /etc/rc.d/init.d/keepalived
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/keepalived
ln -s /usr/local/keepalived/sbin/keepalived /usr/bin/

#开启防火墙vrrp
firewall-cmd --add-rich-rule='rule protocol value="vrrp" accept' --permanent
firewall-cmd --reload

#启动keepalived
systemctl start keepalived
#开机自启动keepalived
systemctl enable keepalived
#查看keepalived启动状态
systemctl status keepalived

5.5 配置nginx高可用

5.5.1 136节点配置(master)
cat > /etc/keepalived/keepalived.conf << EOF
! Configuration File for keepalived
global_defs {
   router_id nginx_master
}

vrrp_script check_nginx {
    script "/etc/keepalived/check_nginx_status.sh"
    interval 3
    weight -5
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.65.100 dev eth0
    }
    
    track_script {
        check_nginx
    }
}
EOF


vim /etc/keepalived/check_nginx_status.sh
#添加如下的内容
#!/bin/bash
A=`ps -C nginx --no-header |wc -l`        
if [ $A -eq 0 ];then                            
    systemctl start nginx                
    if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
        exit 1
    else
        exit 0
    fi
else
    exit 0
fi


#给脚本添加执行权限
chmod a+x  /etc/keepalived/check_nginx_status.sh

#重启keepalived
systemctl restart keepalived
5.5.2 137节点配置(slave)
cat >  /etc/keepalived/keepalived.conf << EOF
! Configuration File for keepalived
global_defs {
   router_id nginx_slave
}

vrrp_script check_nginx {
    script "/etc/keepalived/check_nginx_status.sh"
    interval 3
    weight -5
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.65.100 dev eth0
    }
    
    track_script {
        check_nginx
    }
}
EOF

vim /etc/keepalived/check_nginx_status.sh
#添加如下的内容
#!/bin/bash
A=`ps -C nginx --no-header |wc -l`        
if [ $A -eq 0 ];then                            
    systemctl start nginx                
    if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
        exit 1
    else
        exit 0
    fi
else
    exit 0
fi


#给脚本添加执行权限
chmod a+x  /etc/keepalived/check_nginx_status.sh

#重启keepalived
systemctl restart keepalived

5.6 验证

#宿主机访问VIP
http://192.168.65.100/

#停止掉136的nginx,宿主机也能正常访问http://192.168.65.100/

六、go-fastdfs安装

​ go-fastdfs需要在138,139,140机器上安装。

6.1 准备文件

将fileserver文件分别放到138,139,140的/data/go-fastdfs目录下。

MySQL版本:8.0.16

eagle版本:2.0.8

6.2 生成配置

由于go-fastdfs只有一个安装文件,没有配置,需要运行一次生成配置。

#给文件添加执行权限
chmod +x /data/go-fastdfs/fileserver

#执行一次
cd /data/go-fastdfs  #必须在该目录下
./fileserver


#可以看到生成如下的目录结构
[root@topnet138 go-fastdfs]# ll
总用量 10916
drwxr-xr-x 2 root root       21 1230 13:10 conf
drwxr-xr-x 4 root root       55 1230 13:10 data
drwxr-xr-x 3 root root       17 1230 13:10 files
-rwxr-xr-x 1 root root 11177984 1230 11:22 fileserver
drwxr-xr-x 2 root root       42 1230 13:10 log
drwxr-xr-x 2 root root        6 1230 13:10 static

6.3 修改配置

6.3.1 配置文件内容

/data/go-fastdfs/conf/cfg.json

{
	"绑定端号": "端口",
	"addr": ":8080",
	"是否开启https": "默认不开启,如需启开启,请在conf目录中增加证书文件 server.crt 私钥 文件 server.key",
	"enable_https": false,
	"PeerID": "集群内唯一,请使用0-9的单字符,默认自动生成",
	"peer_id": "2",
	"本主机地址": "本机http地址,默认自动生成(注意端口必须与addr中的端口一致),必段为内网,自动生成不为内网请自行修改,下同",
	"host": "http://192.168.65.138:8080",
	"集群": "集群列表,注意为了高可用,IP必须不能是同一个,同一不会自动备份,且不能为127.0.0.1,且必须为内网IP,默认自动生成",
	"peers": ["http://192.168.65.138:8080"],
	"组号": "用于区别不同的集群(上传或下载)与support_group_manage配合使用,带在下载路径中",
	"group": "group1",
	"是否支持按组(集群)管理,主要用途是Nginx支持多集群": "默认支持,不支持时路径为http://10.1.5.4:8080/action,支持时为http://10.1.5.4:8080/group(配置中的group参数)/action,action为动作名,如status,delete,sync等",
	"support_group_manage": true,
	"是否合并小文件": "默认不合并,合并可以解决inode不够用的情况(当前对于小于1M文件)进行合并",
	"enable_merge_small_file": false,
    "允许后缀名": "允许可以上传的文件后缀名,如jpg,jpeg,png等。留空允许所有。",
	"图片是否缩放": "默认是",
	"enable_image_resize": true,
	"图片最大宽度": "默认值2000",
	"image_max_width": 2000,
	"图片最大高度": "默认值1000",
	"image_max_height": 1000,
	"extensions": [],
	"重试同步失败文件的时间": "单位秒",
	"refresh_interval": 1800,
	"是否自动重命名": "默认不自动重命名,使用原文件名",
	"rename_file": false,
	"是否支持web上传,方便调试": "默认支持web上传",
	"enable_web_upload": true,
	"是否支持非日期路径": "默认支持非日期路径,也即支持自定义路径,需要上传文件时指定path",
	"enable_custom_path": true,
	"下载域名": "用于外网下载文件的域名",
	"download_domain": "",
	"场景列表": "当设定后,用户指的场景必项在列表中,默认不做限制(注意:如果想开启场景认功能,格式如下:'场景名:googleauth_secret' 如 default:N7IET373HB2C5M6D ",
	"scenes": [],
	"默认场景": "默认default",
	"default_scene": "default",
	"是否显示目录": "默认显示,方便调试用,上线时请关闭",
	"show_dir": true,
	"邮件配置": "",
	"mail": {
		"user": "[email protected]",
		"password": "abc",
		"host": "smtp.163.com:25"
	},
	"告警接收邮件列表": "接收人数组",
	"alarm_receivers": [],
	"告警接收URL": "方法post,参数:subject,message",
	"alarm_url": "",
	"下载是否需带token": "真假",
	"download_use_token": false,
	"下载token过期时间": "单位秒",
	"download_token_expire": 600,
	"是否自动修复": "在超过1亿文件时出现性能问题,取消此选项,请手动按天同步,请查看FAQ",
	"auto_repair": true,
	"文件去重算法md5可能存在冲突,默认md5": "sha1|md5",
	"file_sum_arithmetic": "md5",
	"管理ip列表": "用于管理集的ip白名单,如果放开所有内网则可以用 0.0.0.0 ,注意为了安全,不对外网开放",
	"admin_ips": ["127.0.0.1"],
	"是否启用迁移": "默认不启用",
	"enable_migrate": false,
	"文件是否去重": "默认去重",
	"enable_distinct_file": true,
	"是否开启跨站访问": "默认开启",
	"enable_cross_origin": true,
	"是否开启Google认证,实现安全的上传、下载": "默认不开启",
	"enable_google_auth": false,
	"认证url": "当url不为空时生效,注意:普通上传中使用http参数 auth_token 作为认证参数, 在断点续传中通过HTTP头Upload-Metadata中的auth_token作为认证参数,认证流程参考认证架构图",
	"auth_url": "",
	"下载是否认证": "默认不认证(注意此选项是在auth_url不为空的情况下生效)",
	"enable_download_auth": false,
	"默认是否下载": "默认下载",
	"default_download": true,
	"本机是否只读": "默认可读可写",
	"read_only": false,
	"是否开启断点续传": "默认开启",
	"enable_tus": true,
	"同步单一文件超时时间(单位秒)": "默认为0,程序自动计算,在特殊情况下,自已设定",
	"sync_timeout": 0
}
	
6.3.2 调整内容

138,139,140三个go-fastdfs节点都需要调整。

vim /data/go-fastdfs/conf/cfg.json

修改"peers"的内容,即将集群节点调整为:

"peers": ["http://192.168.65.138:8080","http://192.168.65.139:8080","http://192.168.65.140:8080"],

为了使得能被web管理,这里放开对内网的访问:

 "admin_ips": ["0.0.0.0"],

实际情况根据自己的软件机器规划来填写。

6.4 后台启动

138,139,140三个节点分别执行:

vim  /data/go-fastdfs/control
#添加下面的内容,如果执行有问题,请删除汉语注释

#!/bin/bash

WORKSPACE=$(cd $(dirname $0)/; pwd)
cd $WORKSPACE

mkdir -p log conf

module=
appname=$(basename $WORKSPACE)
## 注意:这里每个应用的启动命令是不一样的,
## 启动命令必须在前端运行(即不需要nohup)运行,
## 系统会自动加上nohup运行 
## 例如:run_cmd=java -jar spring-hello.jar
run_cmd="./fileserver server"
conf=conf/cfg.json
pidfile=conf/app.pid
logfile=log/app.log

function check_pid() {
    if [ -f $pidfile ];then
        pid=`cat $pidfile`
        if [ -n $pid ]; then
            running=`ps -p $pid|grep -v "PID TTY" |wc -l`
            return $running
        fi
    fi
    return 0
}
#应用发布接口
function deploy() {
#自定义发布
#例如修改配置,移动文件夹等。。。
echo "请修改deploy接口,以满足你的发布需求。"

}

#应用启动接口
function start() {
    check_pid
    running=$?
    if [ $running -gt 0 ];then
        echo -n "$appname now is running already, pid="
          cat $pidfile
        return 1
    fi
    
    nohup $run_cmd   &> $logfile &
    echo $! > $pidfile
    #echo "$appname started..., pid=$!"
	sleep 3
	status
}
#停止应用接口
function stop() {
    pid=`cat $pidfile`
    kill $pid
    echo "$appname stoped..."
}

function restart() {
    stop
    sleep 1
    start
}
#应用状态检测接口
function status() {
    check_pid
    running=$?
    if [ $running -gt 0 ];then
        echo -n "$appname now is running, pid="
        cat $pidfile
		#注意:以下输出不能修改,程序会自动根据这个输出做状态判断 
		echo "app_status:running"
    else
	    #注意:以下输出不能修改,程序会自动根据这个输出做状态判断 
        echo "$appname is stoped"
		echo "app_status:stoped"
    fi
}

function tailf() {
    timeout 50 tail -f $logfile
}
#应用构建接口
function build() {
    # 注意:如果需要定制编译命令,可以修改这里
	git log -1 --pretty=%h > gitversion
	if [[ -f ./build.sh ]];then
		sh ./build.sh #custom
	elif [[ -f ./pom.xml ]];then
		mvn install #java
	elif [[ -f ./package.json ]];then
		npm install #node
		npm run product
	fi

    if [ $? -ne 0 ]; then
        exit $?
    fi
}

function pack() {
    build
    version=`cat gitversion`
    file_list="control $appname"
    tar zcf $appname-$version.tar.gz gitversion $file_list
}

function packbin() {
    build
    git log -1 --pretty=%h > gitversion
    version=`cat gitversion`
    tar zcvf $appname-bin-$version.tar.gz $appname gitversion
}

function help() {
    echo "$0 start|stop|restart|status|tail|build|pack|deploy|help"
}

if [ "$1" == "" ]; then
    help
elif [ "$1" == "stop" ];then
    stop
elif [ "$1" == "start" ];then
    start
elif [ "$1" == "build" ];then
    build
elif [ "$1" == "deploy" ];then
    deploy
elif [ "$1" == "restart" ];then
    restart
elif [ "$1" == "pack" ];then
    pack
elif [ "$1" == "status" ];then
    status
elif [ "$1" == "tail" ];then
    tailf
else
    help
fi



#给control文件执行权限
chmod +x /data/go-fastdfs/control

开始运行,请确保control文件和fileserver文件在同一个目录,并且必须切换到/data/go-fastdfs目录下执行:

cd /data/go-fastdfs


#启动
./control start #还可以支持stop|status|restart参数

七、配置nginx负载均衡

7.1 官方建议配置文件

worker_processes  auto;
events {
        worker_connections  1024;
}
http {
        include       mime.types;
        default_type  application/html;
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
        access_log  /var/log/nginx/access.log  main;
        error_log  /var/log/nginx/error.log  error;
        sendfile        on;
        keepalive_timeout  65;
        rewrite_log on;
        client_max_body_size 0;
        proxy_redirect ~/(\w+)/big/upload/(.*) /$1/big/upload/$2;  #继点续传一定要设置(注意)
        #以下是一下横向扩展的配置,当前统一大集群容量不够时,只要增加一个小集群,也就是增加一个
        #upstream ,一个小群集内按业务需求设定副本数,也就是机器数。
        upstream gofastdfs-group1 {
                server 10.1.51.70:8082;
                #server 10.1.14.37:8082;
                ip_hash;     #notice:very important(注意)
        }
    upstream gofastdfs-group2 {
        server 10.1.51.70:8083;
                #server 10.1.14.36:8083;
                ip_hash;     #notice:very important(注意)
        }

        server {
                listen       8001;
                server_name  localhost;


        if ( $request_uri ~ /godfs/group ) {
                    # 注意group会随组的前缀改变而改变
            rewrite ^/godfs/(.*)$ /$1 last;
                }
                location ~ /group(\d) { 
                    #统一在url前增加godfs,以便统一出入口。
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
                    proxy_pass http://gofastdfs-group$1;
                }
                location ~ /godfs/upload { 
                    #这是一个横向扩展配置,前期可能只有一个集群group1,当group1满后,只需将上传指向group2,
                    #也就是将rewrite , proxy_pass 中的group1改为group2即可。
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
                    rewrite ^/godfs/upload /group1/upload break;
                    proxy_pass http://gofastdfs-group1;
                }
                location ~ /godfs/big/upload { 
                    #以上上类似。
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
                    rewrite ^/godfs/upload /group1/big/upload break;
                    proxy_pass http://gofastdfs-group1;
                }

        }
}

7.2 nginx配置

136,137nginx所在节点配置:

vim  /software/nginx/conf/nginx.conf 

#用如下内容替换nginx.conf中的内容,注意这里不要使用cat追加
worker_processes  auto;
events {
        worker_connections  1024;
}
http {
        include       mime.types;
        default_type  application/html;
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
        access_log  /software/nginx/logs/access.log  main;
        error_log  /software/nginx/logs/error.log  error;
        sendfile        on;
        keepalive_timeout  65;
        rewrite_log on;
        client_max_body_size 0;
        proxy_redirect ~/(\w+)/big/upload/(.*) /$1/big/upload/$2; 
        upstream gofastdfs-group1 {
                server 192.168.65.138:8080;
                server 192.168.65.139:8080;
                server 192.168.65.140:8080;
                ip_hash;
        }
       
        server {
                listen       8001;
                server_name  localhost;

	
		if ( $request_uri ~ /godfs/group ) {
		    rewrite ^/godfs/(.*)$ /$1 last;
                }
                location ~ /group(\d) { 
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
                    proxy_pass http://gofastdfs-group$1;
                }
                location ~ /godfs/upload { 
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
                    rewrite ^/godfs/upload /group1/upload break;
                    proxy_pass http://gofastdfs-group1;
                }
                location ~ /godfs/big/upload { 
                    proxy_set_header Host $host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
                    rewrite ^/godfs/upload /group1/big/upload break;
                    proxy_pass http://gofastdfs-group1;
                }

        }
}

7.3 验证

宿主机访问:

http://192.168.65.100:8001/group1

八、go-fastdfs-web安装

按照规划,该软件只在136节点安装。注意:go-fastdfs-web依赖jdk,运行该软件必须确保jdk已经安装好并且配置了环境变量。

8.1 准备软件

将go-fastdfs-web-v1.3.6.tar.gz放到/opt/software/go-fastdfs-web/目录下,如果2.7已经准备,这里可以省略这一步的工作。

8.2 解压安装

tar -zxvf /opt/software/go-fastdfs-web/go-fastdfs-web-v1.3.6.tar.gz -C /software/
 

8.3 运行及初始化

#解决脚本错误问题
sed -i 's/\r//' /software/go-fastdfs-web/goFastDfsWeb.sh


cd /software/go-fastdfs-web

#运行,其他命令为:stop | status | restart
./goFastDfsWeb.sh start

8.4 配置go-fastdfs-web

go-fastdfs-web默认监听的端口为8088.

宿主机访问http://192.168.65.136:8088,需要进行初始化配置:

配置项 配置值 备注
集群名称 北京拓普丰联信息工程有限公司 随便写
组名称 group1 这个是go-fastdfs中配置的:“group”: “group1”
服务地址 http://192.168.65.100:8001 VIP地址,端口为nginx的端口
访问域名 可以不填写
用户名 XXX 随便写
登录账号 admin 随便写
登录密码 admin 随便写
邮箱 [email protected] 根据实际情况填写

安装完毕之后可以使用admin/admin登录。

登录成功之后,可以通过web页面进行服务器监控和一些基本的文件操作。

你可能感兴趣的:(应用架构,fastDFS,系统架构设计师,golang,nginx,服务器)