zoukankan      html  css  js  c++  java
  • 蚂蚁笔记私有部署

    说明

    其实官方的教程中已经写得很清楚了,我写这个主要是为了记录一下我自己当时安装的过程,方便后续查询

    官方文档请查阅:https://github.com/leanote/leanote/wiki

    环境要求

    • CentOS6.5+Nginx+MongoDB
    • 最小配置:16G内存+4CPU+500G硬盘
    • 推荐配置:32G内存+4CPU+1T硬盘

    安装过程

    • 安装 CentOS 6.5

    最小化安装,分区如下,推荐基于LVM,后面维护比较方便:

      /boot    500M
      swap     8G
      /        20G
      /data    剩下所有
    
    • 系统优化

    关闭SELinux

    sed -i 's/SELINUX=enforcing/SELINUX=disabled/'/etc/s
    

    精简启动项

    LANG=en
    for root in `chkconfig --list|grep 3:on|awk '{print 1}'`;do chkconfig --level 3 root off;done
    for root in crond network rsyslog sshd iptables;do chkconfig --level 3 $root on;done   
    chkconfig --list|grep 3:on
    
    • 安装软件

      安装Nginx

    安装Nginx的YUM源
    rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
    yum -y install nginx
    

    安装其他软件

    yum -y install vim wget curl lsof net-tools openssl
    
    • 安装Mongodb

    编辑mongodb的YUM源

    #vim /etc/yum.repos.d/mongodb-org-3.4.repo
    #添加入一下内容
    [mongodb-org-3.4]
    name=MongoDB Repository
    baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
    gpgcheck=1
    enabled=1
    gpgkey=https://www.mongodb.org/static/pgp/server-3.4.as
    

    安装mongodb

    yum -y install mongodb-org
    
    • 自定义Mondodb数据库

    修改数据库存储路径,将dbpath自定义成自己的data分区,首先需要创建目录并赋予权限

    mkdir -p /data/db
    chown -Rf mongod:mongod /data/db
    chmod -Rf 755 /data/db
    

    更改MongoDB数据库存储路径,修改dbPath

    # vim /etc/mongod.conf
    ...
    systemLog:
      destination: file
      logAppend: true
      path: /var/log/mongodb/mongod.log
      # Where and how to store data.
         storage:
         dbPath: /data/db/        //我们需要指定库文件的存放目录
         journal:
         enabled: true
      # how the process runs
         processManagement:
         fork: true  # fork and run in background
      pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile
      # network interfaces
         net:
         port: 27017
         bindIp: 127.0.0.1
    ...
    
    • 启动Mongodb并加入开机自启
    service mongod start
    chkconfig mongod on
    
    • 部署蚂蚁笔记

    下载蚂蚁笔记

    cd /data
    wget https://sourceforge.net/projects/leanote-bin/files/2.5/leanote-linux-amd64-v2.5.bin.tar.gz
    

    解压文件

    tar -zxvf leanote-linux-amd64-v2.5.bin.tar.gz
    

    导入初始化数据库

    mongorestore -h localhost -d leanote --dir /data/leanote/mongodb_backup/leanote_install_data/
    

    给mongodb添加数据库用户

    mongo
    首先切换到leanote数据库下
    > use leanote;
    添加一个用户root, 密码是abc123,这个密码是可以自定义的
    > db.createUser({
         user: 'root',
         pwd: 'abc123',
         roles: [{role: 'dbOwner', db: 'leanote'}]
     });
    测试下是否正确
    > db.auth("root", "abc123");
     1    
    返回1表示正确
    

    修改app.conf

    # vim /data/leanote/conf/app.conf
    ...
     db.host=localhost
     db.port=27017
     db.dbname=leanote
     db.username=root
     db.password=abc123
    ...
    

    重启数据库服务

     service mongod restart
    

    尝试运行

    bash /data/leanote/bin/run.sh
    

    如果终端提示如下就说明配置是正确的

    ...
    TRACE 2013/06/06 15:01:27 watcher.go:72: Watching: /home/life/leanote/bin/src/github.com/leanote/leanote/conf/routes
    Go to /@tests to run the tests.
    Listening on :9000
    ...
    
    • 尝试访问,记得先关闭下防火墙

    恭喜你, 打开浏览器输入: http://localhost:9000体验leanote吧!

    • 配置支持https

    创建证书

    首先,创建证书和私钥的目录
    # mkdir -p /etc/nginx/cert
    # cd /etc/nginx/cert
    创建服务器私钥,命令会让你输入一个口令:
    # openssl genrsa -des3 -out nginx.key 2048
    创建签名请求的证书(CSR):
    # openssl req -new -key nginx.key -out nginx.csr
    在加载SSL支持的Nginx并使用上述私钥时除去必须的口令:
    # cp nginx.key nginx.key.org
    # openssl rsa -in nginx.key.org -out nginx.key
    最后标记证书使用上述私钥和CSR:
    # openssl x509 -req -days 365 -in nginx.csr -signkey nginx.key -out nginx.crt
    

    配置Nginx

    配置nginx.conf

    # vim /etc/nginx/nginx.conf  添加入一下内容
    #本配置只有http部分, 不全, 详细配置请百度Nginx相关知识
    http {
         include       /etc/nginx/mime.types;
         default_type  application/octet-stream;
    
         upstream  note.cloud.top  {
             server   localhost:9000;
         }
    
         # http
         server
         {
             listen  80;
             server_name  note.cloud.top;
    
             # 强制https
             # 如果不需要, 请注释这一行rewrite
             rewrite ^/(.*) https://note.cloud.top/$1 permanent;
    
             location / {
                 proxy_pass        http://note.cloud.top;
                 proxy_set_header   Host             $host;
                 proxy_set_header   X-Real-IP        $remote_addr;
                 proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
             }
         }
    
         # https
         server
         {
             listen  443 ssl;
             server_name  note.cloud.top;
             ssl_certificate     /etc/nginx/cert/nginx.crt; # 修改路径, 到nginx.crt, 下同
             ssl_certificate_key /etc/nginx/cert/nginx.key;
             location / {
                 proxy_pass        http://note.cloud.top;
                 proxy_set_header   Host             $host;
                 proxy_set_header   X-Real-IP        $remote_addr;
                 proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
             }
         }
     }
    

    启动Nginx

    service nginx start
    chkconfig nginx on
    
    • 笔记系统开机自启

    注意

    官方文档并没有给出这项设置,其实最简单的办法就是向rc.local文件中添加一条命令,开机自动执行,但是这里推荐使用supervisor服务进行管理,supervisor的详细介绍见:http://www.supervisord.org/**

    方法1:

    # vim /etc/rc.d/rc.local  
    添加下面的内容,这样的化开机后就不会有影响
    nohup bash /data/leanote/bin/run.sh &
    

    方法2-推荐使用
    使用supervisor服务进行管理的优点是服务异常后自动重启,可靠性较高

    • 安装supervisor服务
    yum install epel-release -y && yum install supervisor -y
    
    • 配置supervisor
    vim /etc/supervisord.conf   在文件末尾加入以下内容
     ···
    [program:webvirtmgr]
    command=bash /data/leanote/bin/run.sh
    autostart=true
    autorestart=true
    logfile=/dev/null
    log_stderr=true
    user=root
     ···
    

    logfile我们定义到磁盘黑洞中,就不用占用磁盘的空间,同时减少部分磁盘IO开销

    • 启动supervisor服务并添加到开机自启中
    # chkconfig supervisord on && service supervisord start
    
    • 防火墙配置
    #清空配置
    iptables -F
    iptables -X
    #如果是远程ssh连接配置务必先执行这条命令,否则会断开ssh连接,无法进行后续工作
    iptables -A INPUT -p tcp --dport 22 -j ACCEPT     
    iptables -P INPUT DROP
    iptables -P OUTPUT ACCEPT
    iptables -P FORWARD DROP
    #允许80、443、9000、53(DNS)端口
    iptables -A INPUT -p tcp --dport 80 -j ACCEPT      
    iptables -A INPUT -p tcp --dport 443 -j ACCEPT
    iptables -A INPUT -p tcp --dport 9000 -j ACCEPT
    iptables -A INPUT -p tcp --sport 53 -j ACCEPT
    iptables -A INPUT -p udp --sport 53 -j ACCEPT
    #允许ping
    iptables -A INPUT -p icmp -j ACCEPT
    #允许loopback!(不然会导致DNS无法正常关闭等问题)               
    iptables -A INPUT -i lo -p all -j ACCEPT
    #丢弃坏的TCP包
    iptables -A FORWARD -p TCP ! --syn -m state --state NEW -j DROP
    #处理IP碎片数量,防止攻击,允许每秒100个
    iptables -A FORWARD -f -m limit --limit 100/s --limit-burst 100 -j ACCEPT
    #设置ICMP包过滤,允许每秒1个包,限制触发条件是10个包   
    iptables -A FORWARD -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT
    service iptables save
    service iptables restart
    
    • 其它配置

    修改leanote运行端口

    比如想以8080端口启动.修改conf/app.conf:

    http.port=8080
    site.url=http://note.cloud.top:8080
    

    请重启Leanote, 使用http://note.cloud.top:8080

    绑定域名

    提示

    site.url其实是自己可以自定义的,因为在浏览器中我们登录注销后url会自动变成这个语句设置的值,所以务必设置正确。

    site.url=http://note.cloud.top
    或
    site.url=https://note.cloud.top
    请重启Leanote, 使用http://note.cloud.top 或者 https:////note.cloud.top 进行访问
    
  • 相关阅读:
    关于这个 blog
    P6499 [COCI2016-2017#2] Burza 题解
    CF1172F Nauuo and Bug 题解
    CF1479D Odd Mineral Resource 题解
    CF1442E Black, White and Grey Tree 题解
    CF1442D Sum 题解
    CF1025D Recovering BST 题解
    CF1056E Check Transcription 题解
    CF1025F Disjoint Triangles 题解
    红包算法的PHP实现
  • 原文地址:https://www.cnblogs.com/DevOpsTechLab/p/7732754.html
Copyright © 2011-2022 走看看