美文网首页藏兵谷wordLinux的小折腾
Centos7 使用 宝塔面板 搭建私人网盘

Centos7 使用 宝塔面板 搭建私人网盘

作者: 请叫我雯子小姐的小爷 | 来源:发表于2019-04-23 16:37 被阅读1598次

    ​项目预览

    本文中的代码部分有乱码情况,请点击此链接点击查看,或者关注微信公众号‘微电脑’查看。

    第一步,使用下面命令安装宝塔面板(请确保纯净系统安装)

    yum install -y wget && wget -O install.shhttp://download.bt.cn/install/install_6.0.sh && sh install.sh

    安装大概需要2-15分钟,因机器配置不同而不同,完成后会出现一下内容

    Bt-panel: http://***:8888

    username: ******

    password: ******

    复制Bt-panel后面的网址到浏览器,可以打开宝塔面板的后台,使用username和password登录即可。

    第二步,安装LAMP或者LNMP环境,编译安装或者急速安装都可。

    第三步,点击左侧‘软件管理’,安装宝塔插件中的’宝塔一键部署源码‘。

    第四步,打开一键部署源码,选择可道云进行一键部署

    域名栏填写电脑的路由IP(一般为192.168. * . * )和公网IP(在terminal中输入curl ifconfig.me可得到),备注可随意填写,根目录自行选择,最后点击提交

    第五步,设置路由器端口转发规则,登录路由器界面,设置外网80端口转发到你的路由IP的80端口(仅看最后一条规则)

    至此,云盘已经搭建完成,可以在浏览器中输入http://127.0.0.1:80进行访问,局域网内其他电脑通过http://你的路由IP:80进行访问,其余情况下可使用http://你的公网IP:80进行访问

    以下教程为附属教程,因为宝塔面板的面板设置中,在教育网或者集团网中服务器IP地址获取不正确,故有时不能通过公网IP进行访问,可按照以下步骤操作

    Problem 1 :纠正宝塔面板服务器IP地址

    Solution:修改这个宝塔面板的配置文件 ‘sudo vi /www/server/panel/class/public.py’,更改以下内容

    defGetLocalIp():    #~O~V~\~\~V~QIPtry:importre;filename='data/iplist.txt'

    ipaddress=readFile(filename)

    ifnot ipaddress:

    importurllib2

    importjson           

    #url = 'http://pv.sohu.com/cityjson?ie=utf8'

    url="https://ifconfig.me/all.json"

    opener=urllib2.urlopen(url)str=opener.read()           

    #ipaddress = re.search('\d+.\d+.\d+.\d+',str).group(0)

    ipaddress=json.loads(str.decode())

    ipaddress=ipaddress['ip_addr']

    writeFile(filename,ipaddress)​ipaddress=re.search('\d+.\d+.\d+.\d+',ipaddress).group(0);

    return ipaddress

    except:try:url=web.ctx.session.home + '/Api/getIpAddress';

    opener=urllib2.urlopen(url)returnopener.read()

    except:importweb

    returnweb.ctx.host.split(':')[0];

    并且使用 'sudo rm /www/server/panel/data/iplist.txt' 删除已经保存的IP信息,这样就配置好了

    Problem 2:公网无法访问云盘

    Solution:使用自动脚本重置域名配置文件,以Apache为例

    #!/usr/bin/python

    #Need to runasroot, crontab -e

    import os

    import smtplib

    from email.mime.textimport MIMEText

    import pickle

    import requests

    import time​

    ###Getpublicip ###

    pub_ip = requests.get("https://ifconfig.me")

    pub_ip = pub_ip.text

    ​try:

        fin =open('.pubip.pkl','rb')   

        ip = pickle.load(fin)

    except:

        ip = {'pub_ip':'000.000.000.000'}

        fout =open('.pubip.pkl','wb')

        pickle.dump(ip,fout)   

        fout.close()

        fin =open('.pubip.pkl','rb')   

         ip = pickle.load(fin)

    if ip['pub_ip'] == pub_ip:

        pass #print"public ip don't change, nothing to do"

    else:

        ip['pub_ip'] = pub_ip

        fout =open('.pubip.pkl','wb')

        pickle.dump(ip,fout)

        msm ="Mr Cloud has been changed, The new address: http://"+pub_ip+".p.scnu.edu.cn"

        f =open("/www/server/panel/vhost/apache/192.168.1.101.conf","w")

        f.write('''ServerAdminwebmaster@example.comDocumentRoot"/www/wwwroot/192.168.1.101"ServerName78c7ee6f.192.168.1.101ServerAlias192.168.1.101127.0.0.1{0}errorDocument404/404.htmlErrorLog"/www/wwwlogs/192.168.1.101-error_log"CustomLog"/www/wwwlogs/192.168.1.101-access_log"combined​#DENYFILESOrderallow,denyDenyfrom all​#PHPSetHandler"proxy:unix:/tmp/php-cgi-54.sock|fcgi://localhost"​#PATHSetOutputFilterDEFLATEOptionsFollowSymLinksAllowOverrideAllRequireall grantedDirectoryIndexindex.php index.html index.htmdefault.phpdefault.htmldefault.htm'''.format(pub_ip))​

    time.sleep(3)os.system("/etc/init.d/bt restart") #此处不是必须time.sleep(3)os.system("/etc/init.d/httpd restart") #必须有这句,用来重启Apache服务

    此脚本需要添加可执行权限(chmod 777 apache.py)添加到root用户的自动化任务中,使用以下命令(crontab -e)

    */30 ** ** /PATH/apache.py

    Problem 3:挂载移动硬盘到用户www下

    Solution:将下面的命令添加到 'sudo vi /etc/fstab'中

    /dev/sdb1 /media/sdb1  ntfs rw,noauto,users,uid=1000,gid=1000,permissions 0 2

    相关文章

      网友评论

        本文标题:Centos7 使用 宝塔面板 搭建私人网盘

        本文链接:https://www.haomeiwen.com/subject/nmxbgqtx.html