利用IPFS搭建一个电子书搜索系统

项目地址

SaltyLeo/i-book.in_Archive (github.com)

介绍

基于IPFS的存储,搭建的索引电子书网站~!
已有大佬搭建的:http://ipls.cf/

搭建

下面是一个简单的安装教程,我尽可能写的明白了,如有不清楚的,可以到作者的tg群组讨论 : https://t.me/SaltyLeo_blog

基本需求

python3、docker

搭建说明

首先安装一系列必须的插件与更新。

apt install python3-pip
pip3 install flask
pip3 install elasticsearch
pip3 install flask_bootstrap

安装 docker版es

curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh get-docker.sh && docker pull elasticsearch:6.7.0

cd  /
mkdir -p mnt/elasticsearch
cd  mnt/elasticsearch
mkdir config
mkdir master
mkdir slave
chmod 777 master
chmod 777 slave
cd config
touch master.yml
touch slave.yml
nano master.yml

将下列参数粘贴到打开的nano编辑器内。

cluster.name: elasticsearch-cluster
node.name: master
network.bind_host: 0.0.0.0
network.publish_host: 127.0.0.1
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300","127.0.0.1:9301"]

修改线程限制

nano /etc/sysctl.conf
#添加这个
vm.max_map_count=262144 
#保存后执行这个命令
sysctl -p

初始化 es搜索引擎

docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 127.0.0.1:9200:9200 -p 127.0.0.1:9300:9300 -v /mnt/elasticsearch/config/master.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /mnt/elasticsearch/master:/usr/share/elasticsearch/data --name es-master elasticsearch:6.7.0

下载源码

wget https://github.com/SaltyLeo/i-book.in_Archive/raw/master/i-book.in.tar.gz && tar -zxvf i-book.in.tar.gz && cd web

#墙内无法访问GitHub使用下面这个
wget https://ibookin-1252237247.cos.ap-shanghai.myqcloud.com/i-book.in.tar.gz && tar -zxvf i-book.in.tar.gz && cd web

将索引数据导入到ES

python3 add2es.py

可能会弹出以下错误,但请忽略即可。

/usr/local/lib/python3.6/dist-packages/elasticsearch/connection/base.py:177: ElasticsearchDeprecationWarning: the default number of shards will change from [5] to [1] in 7.0.0; if you wish to continue using the default of [5] shards, you must manage this on the create index request or with an index template
  warnings.warn(message, category=ElasticsearchDeprecationWarning)

运行demo

python3 web.py

这时候打开你的服务器IP+端口7743即可打开搜索引擎,例:127.0.0.1:7743,如下图:

image.png

注意事项

  1. 网站索引文件按照test.json格式导入即可,请注意,add2es这个脚本每次都会清空es索引后再执行导入。

| | {"name":"这里是名字","author":"这里写作者","press":"这里是出版社","isbn":"这里是ISBN","douban":"这里是豆瓣评分","tags":"这里是标签","ids":"d349f1c701ff48c1bff9d95859049ee4","link":"这里是链接","img":"这个是图片链接","intor":"这里你可以放上这个东西的详细介绍。","guess":"yes","size":"2954637","type":"《mobi》《epub》《azw3》"} |
| -- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| | {"name":"测试书名","author":"SaltyLeo","press":"星际出版社","isbn":"123456789009","douban":"10.0","tags":"NBlity","ids":"d349f1c701ff48c1bff9d95859049e22","link":"这里是链接","img":"这个是图片链接","intor":"这个是一个测试的条目,你需要自己修改。","guess":"yes","size":"20954637","type":"《pdf》"} |

  1. 各种链接按需修改,请注意web.py改了return的话,前端html文件也需要改,否则flask会报错。
  2. 偶尔docker会卡死使用这个命令重启所有docker docker restart $(docker ps -a | awk '{ print $1}' | tail -n +2)


标题:利用IPFS搭建一个电子书搜索系统
作者:xxr
地址:HTTP://wink.winkxrq.tk/articles/2021/07/24/1627110764886.html
喜欢就可以打赏一下噢,请我喝瓶水嘛~
    评论
    0 评论
avatar

取消