centos7安装btsearch

首先安装mongod3.6

vi /etc/yum.repos.d/mongodb-org-3.6.repo

写入以下内容:

[mongodb-org-3.6]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc

安装 MongoDB 软件包

yum install -y mongodb-org -y

为防止意外升级,请固定包装。要固定包,请在您的/etc/yum.conf文件中添加以下exclude指令:

exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools

启动数据库:

systemctl start mongod

查看版本:

mongod --version

安装python3.x
编译环境

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make -y

去官网下载编译安装包或者直接执行以下命令下载

wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz

解压

tar -xvJf  Python-3.6.2.tar.xz

切换进入

cd Python-3.6.2

编译安装

./configure prefix=/usr/local/python3
make && make install

安装完毕,/usr/local/目录下就会有python3了
因此我们可以添加软链到执行目录下/usr/bin

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

安装Docker
#CentOS 7、Debian、Ubuntu系统

curl -sSL https://get.docker.com/ | sh
systemctl start docker
systemctl enable docker

拉取源码:

git clone https://github.com/ludashi2020/btSearch

在/etc/sysctl.conf文件最后添加一行

vm.max_map_count=262144

执行

/sbin/sysctl -p

立即生效

Elasticsearch dockerp配置

docker run --restart=always -p 9200:9200 -p 9300:9300 --name=tmp docker.elastic.co/elasticsearch/elasticsearch:5.6.0

安装analysis-ik分词器

docker ps
docker exec -it $dockid /bin/bash
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.6.0/elasticsearch-analysis-ik-5.6.0.zip

配置elasticsearch的数据存放目录

mkdir -p /data/docker
docker cp $dockid:/usr/share/elasticsearch/ /data/docker
chmod 777 -R /data/

停止docker服务

docker stop $dockid
docker rm $dockid

运行Elasticsearch docker服务

docker run --restart=always -p 9200:9200 -p 9300:9300 --name=es \
-e ES_JAVA_OPTS="-Xms4g -Xmx4g" \
-v /data/docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /data/docker/elasticsearch/data:/usr/share/elasticsearch/data \
-v /data/docker/elasticsearch/logs:/usr/share/elasticsearch/logs \
-v /data/docker/elasticsearch/config:/usr/share/elasticsearch/config \
-v /data/docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-v /etc/localtime:/etc/localtime \
-v /etc/timezone:/etc/timezone \
docker.elastic.co/elasticsearch/elasticsearch:5.6.0

配置正确的话执行下面命令可以看到当前Elasticsearch的运行状态

curl --user elastic:changeme -XGET 'http://127.0.0.1:9200/_cat/health'

配置Elasticsearch默认分词器

curl --user elastic:changeme -XPUT http://127.0.0.1:9200/bavbt -H 'Content-Type: application/json'
curl --user elastic:changeme -XPOST '127.0.0.1:9200/bavbt/_close'
curl --user elastic:changeme -XPUT 127.0.0.1:9200/bavbt/_settings?pretty -H 'Content-Type: application/json' -d '{
"index":{
"analysis" : {
            "analyzer" : {
                "default" : {
                    "type" : "ik_max_word"
                }
            },
			"search_analyzer" : {
                "default" : {
                    "type" : "ik_max_word"
                }
            }
        }
    }
}'
curl --user elastic:changeme -XPUT http://127.0.0.1:9200/bavbt/_settings?preserve_existing=true -H 'Content-Type: application/json' -d '{
"max_result_window" : "2000000000"
}'
curl --user elastic:changeme -XPOST '127.0.0.1:9200/bavbt/_open'

设置Mongodb配置副本集

systemctl stop mongod
vi /etc/mongod.conf

添加

replication:
  #oplogSizeMB: 97280
  replSetName: rs1

启动数据库

systemctl start mongod

设置root密码

mongod --dbpath /var/run/mongodb --logpath /var/log/mongodb/mongod.log --fork
mongo
use admin
db.createUser({user:"root",pwd:"root",roles:[{role:"root",db:"admin"}]})
db.auth("root","root")

初始化副本集

rs.initiate()

显示如下信息,表示正常

{
        "info2" : "no configuration specified. Using a default configuration for the set",
        "me" : "127.0.0.1:27017",
        "ok" : 1,
        "operationTime" : Timestamp(1645696651, 1),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1645696651, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        }
}

运行
首先需要配置您的conf文件

[mongodb]
musername=
mpassword=
database=bavbt
collection=torrent
addr=127.0.0.1:27017
[elasticsearch]
url=http://127.0.0.1:9200/bavbt/torrent/
eusername=elastic
epassword=changeme
[webServer]
webServerAddr=127.0.0.1:7878

安装mongo-connector,这个东西的主要作用是把mongodb的数据同步到es内:

pip3 install mongo-connector
pip3 install elastic2-doc-manager[elastic5]
pip3 install mongo-connector[elastic5]

装好之后降级pymongo,否则后续报错运行不了:

pip3 install pymongo==3.12.3

建立短链接

ln -s /usr/local/python3/bin/mongo-connector /usr/bin/mongo-connector

开启同步命令:

mongo-connector -m mongodb://127.0.0.1:27017/?unicode_decode_error_handler=ignore -t http://elastic:[email protected]:9200/torrent -d elastic2_doc_manager -n bavbt.torrent -i name,length,hot,create_time,category,infohash
点赞