内容纲要

redis

vim /etc/systemd/system/redis.service
[Unit]
Description=Redis Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/opt/redis/bin/redis-server /opt/redis/redis.conf
ExecStop=/opt/redis/bin/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target

mongo

  • 安装服务时老退出,是因为 mongodb.conf 配置了以 fork 方式启动
dbpath=/opt/mongodb/data
logpath=/opt/mongodb/log/mongod.log
logappend=true
port=27017
bind_ip=0.0.0.0
vim /etc/systemd/system/mongod.service 
[Unit]
Description=MongoDB
After=network.target

[Service]
User=mongod
Group=mongod
ExecStart=/opt/mongodb/bin/mongod -f /opt/mongodb/mongodb.conf
ExecStop=/opt/mongodb/bin/mongod -f /opt/mongodb/mongodb.conf --shutdown
Restart=always

[Install]
WantedBy=multi-user.target                                        

创建用户名密码

$ mongo
use admin

db.createUser(
  {
    user: "root", 
    pwd: "test", 
    roles: [ { role: "root", db: "admin" } ]
  }
)

quit()

配置文件添加 auth=true

dbpath=/opt/mongodb/data
logpath=/opt/mongodb/log/mongod.log
logappend=true
port=27017
bind_ip=0.0.0.0
auth=true

mongo 备份

mongodump.exe -h 127.0.0.1 --port 27017 -u root -p zuhaowan_mongo -d middle_ware -o ..\bak  --authenticationDatabase admin

防火墙设置

发表评论

电子邮件地址不会被公开。 必填项已用*标注