龙芯平台(centos)移植mongodb镜像

MongoDB 是一个高性能分布式文件存储数据库

1.拉取并运行镜像

docker pull loongsongd/loongnix-base:1.0
docker run -itd --name mongo --privileged=true loongsongd/loongnix-base:1.0 /usr/sbin/init
docker exec -it mongo /bin/bash

2.安装软件包

yum install pcre-devel python-devel scons mogodb -y

3.添加mongodb 用户和配置
useradd mongodb -M -s /sbin/nologin

创建目录,根据需要进行自定义

 mkdir -pv /etc/mongo                      //配置文件路径
mkdir -pv /var/lib/mongo                 //数据存储路径
mkdir -pv /var/log/mongo                //日志文件路径
mkdir -pv /var/run/mongodb            //Pid 路径

//将源码包中的配置文件复制到 /etc/mongo 下

cp mongodb-src/rpm/mongod.conf /etc/mongo

//给予日志和数据路径mongodb用户组访问权限

 chown -R mongodb.mongodb /var/log/mongodb
 chown -R mongodb.mongodb /var/lib/mongodb
  1. 创建并编辑配置文件
    touch /etc/mongo/mongod.conf
    vi /etc/mongo/mongod.conf
    —–配置参考下面的路径进行或查阅配置说明文档——
dbpath = /var/lib/mongo
logpath = /var/log/mongo
pidfilepath = /var/run/mongodb/mongod.pid
directoryperdb = true
logappend = true
noauth = true
port = 27017
maxConns = 1024
fork = true
rest = true
quota = true
quotaFiles = 1024
nssize = 16

5.配置开机启动文件
将下列脚本保存为 mongod 并存放在/etc/rc.d/init.d/ 下,并给与执行权限

#!/bin/sh
#
# mongodb      init file for starting up the MongoDB server
#
# chkconfig:   - 20 80
# description: Starts and stops the MongDB daemon that handles all \
#              database requests.

# Source function library.
. /etc/rc.d/init.d/functions

exec="/usr/local/mongo/bin/mongod"
prog="mongod"
logfile="/var/log/mongodb/mongodb.log"
options=" -f /etc/mongo/mongod.conf"

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile="/var/lock/subsys/mongod"

start() {
    [ -x $exec ] || exit 5
    echo -n $"Starting $prog: "
    daemon --user mongodb "$exec --quiet $options run >> $logfile 2>&1 &"
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    stop
    start
}

reload() {
    restart
}

force_reload() {
    restart
}

rh_status() {
    # run checks to determine if the service is running or use generic status
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}


case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2
esac
exit $?

chmod 777 mongod
service mongodb start

此时出现报错:Failed to start mongod.service: Unit not found
原因是安装包缺少配置文件

6.创建配置文件:sudo nano /etc/systemd/system/mongodb.service

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target

[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target

再次执行service mongodb start


mongodb已成功运行
参考:https://www.sulabs.net/?p=359

推荐阅读更多精彩内容