×
Community Blog How to Setup a Leanote Server on ECS with CentOS 7

How to Setup a Leanote Server on ECS with CentOS 7

In this tutorial, we will learn how to install and configure Leanote on an Alibaba Cloud Elastic Compute Service (ECS) instance with CentOS 7.

By Hitesh Jethva, Alibaba Cloud Community Blog author.

Leanote is a free and open source alternative to Evernote written in Golang. It is simple, lightweight and has all the functionalities you have used on Evernote. Leanote allows you to keep the notes on a self-hosted server and sync it with Android/iOS. It can work on Mac, Windows and Linux. Leanote provides very useful features such as, cross-platform support, writing in the MarkDown syntax, public or private blogging, knowledge gathering and sharing, and team collaboration.

In this tutorial, we will explain how to install Leanote server on CentOS-7 server with an Alibaba Cloud Elastic Compute Service (ECS) instance.

Prerequisites

  • A fresh Alibaba Cloud instance with CentOS 7 installed.
  • A valid domain name node1.example.com is set up to your CentOS 7 server instance.
  • A root password is set up to your instance.

Launch an Alibaba Cloud ECS Instance

Create a new ECS instance, choosing CentOS 7 as the operating system with at least 2GB RAM, and connect to your instance as the root user.

Once you are logged into your CentOS 7 instance, run the following command to update your base system with the latest available packages.

yum update -y

Getting Started

Before starting, you will need to disable Selinux on your server. You can do this by editing /etc/selinux/config file:

nano /etc/selinux/config

Make the following changes:

SELINUX=disabled

Save and close the file. Then, restart your server to apply the changes.

Install MongoDB

Next, you will need to install MongoDB to your server. By default, MongoDB is not available in the CentOS 7 default repository. So you will need to install the repository for that. You can add the MongoDB repository by creating the following file:

nano /etc/yum.repos.d/mongodb-org.repo

Add the following lines:

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

Save and close the file. Then, install MongoDB with the following command:

yum install mongodb-org

After installing MongoDB, check the status of MongoDB with the following command:

systemctl status mongod.service

You should expect to see "Active: active (running)"

Install Leanote

First, you will need to download the latest version of Leanote from SourceForge. You can download it with the following command:

wget https://sourceforge.net/projects/leanote-bin/files/2.6.1/leanote-linux-amd64-v2.6.1.bin.tar.gz

Once the download is completed, extract the downloaded file with the following command:

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

Next, you will need to import the Leanote data into MongoDB. You can do it with the following command:

rm leanote/mongodb_backup/leanote_install_data/.DS_Store

mongorestore --host localhost -d leanote --dir leanote/mongodb_backup/leanote_install_data/

Configure MongoDB

For security reasons, it is recommended to enable access control to MongoDB. To do so, you will need to create MongoDB user administrator account and database administrator account.

First, log in to MongoDB shell with the following command:

mongo --host 127.0.0.1:27017

Next, change the database to admin and cretae a user administrator account with the following command:

> use admin
> db.createUser({ user: "useradmin", pwd: "password", roles: [{ role: "userAdminAnyDatabase", db: "admin" }] })

Next, change the database to leanote and create a database administrator account with the following command:

> use leanote
> db.createUser({ user: "leanoteadmin", pwd: "password", roles: [{ role: "dbOwner", db: "leanote" }] })

After creating both accounts, confirm the user administrator account with the following command:

> use admin
> db.auth("useradmin", "password")

Confirm the database administrator account with the following command:

> use leanote
> db.auth("leanoteadmin", "password")

Both will output 1 as confirmation.

Now, exit from the MongoDB shell:

> exit
bye

Next, enable the MongoDB access control by editing /etc/mongod.conf file:

nano /etc/mongod.conf

Add the following lines:

security:
authorization: enabled

Save and close the file. Then, restart MongoDB to apply the changes:

systemctl restart mongod

Configure Leanote

Next, you will need to edit Leanote default configuration file and make some changes:

nano leanote/conf/app.conf

Make the following changes:

site.url=http://node1.example.com:9000

# admin username
adminUsername=admin

# mongdb
db.host=127.0.0.1
db.port=27017
db.dbname=leanote
db.username= leanoteadmin
db.password= password

Save and close the file, when you are finished.

Access Leanote Web Interface

Now, start the Leanote server with the following command:

bash leanote/bin/run.sh

Leanote server is now running and listening on port 9000.

Now, open your web browser and type the URL http://node1.example.com:9000. You will be redirected to the following page:

1

Now, click on the Sign in button. You should see the Leanote log in page:

2

Now, provide default username and password as admin / abc123 and click on the Sign in button. You should see the Leanote default dashboard in the following page:

3

Configure Nginx as a Reverse Proxy

By default, Leanote runs on port 9000. So you will need to configure Nginx as a reverse proxy to access Leanote through port 80.

First, install Nginx with the following command:

yum install nginx -y

Next, open Nginx default configuration file:

nano /etc/nginx/nginx.conf

Comment the following lines:

#    server {
#    listen       80 default_server;
#      listen       [::]:80 default_server;
#    server_name  _;
#    root         /usr/share/nginx/html;
#    include /etc/nginx/default.d/*.conf;
#    location / {
#    }
#    error_page 404 /404.html;
#           location = /40x.html {
#    }
#    error_page 500 502 503 504 /50x.html;
#           location = /50x.html {
#      }
#   }

Save and close the file. Then, create a new virtual host file for Leanote:

nano /etc/nginx/conf.d/leanote.conf

Add the following lines:

server {
listen 80 default_server;
   server_name node1.example.com ;
   access_log off;
   error_log off;
   location / {
      proxy_pass http://127.0.0.1:9000;
      proxy_redirect off;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_max_temp_file_size 0;
      client_max_body_size 10m;
      client_body_buffer_size 128k;
      proxy_connect_timeout 90;
      proxy_send_timeout 90;
      proxy_read_timeout 90;
      proxy_buffer_size 4k;
      proxy_buffers 4 32k;
      proxy_busy_buffers_size 64k;
      proxy_temp_file_write_size 64k;
   }
}

Save and close the file. Then, restart Nginx service to apply the changes:

systemctl restart nginx

Next, open Leanote default configuration file:

nano leanote/conf/app.conf

Find the following line:

site.url=http://node1.example.com:9000

Replace it with:

site.url=http://node1.example.com

Save and close the file.

Configure Supervisor to Manage Leanote Service

Next, you will need to install and configure Supervisor to auto-start the Leanote service if it crashes.

First, install Supervisor with the following command:

yum install supervisor -y

After installing Supervisor, create a new Supervisor file for Leanote:

nano /etc/supervisord.d/leanote.ini

Add the following lines:

[program:leanote]
command=bash /root/leanote/bin/run.sh
directory=/root/leanote/bin/
priority=999
autostart=true
autorestart=true
user=root
redirect_stderr=true

Save and close the file. Then, start Supervisor and Leanote service using the following command:

supervisord -c /etc/supervisord.conf

You can check the status of Supervisor with the following command:

supervisorctl status leanote

Output:

leanote                          RUNNING   pid 5754, uptime 0:00:21

Now, open your web browser and type the URL http://node1.example.com to access the Leanote web interface.

1 0 0
Share on

Hiteshjethva

38 posts | 4 followers

You may also like

Comments

5161971968365326 April 17, 2020 at 4:30 am

How to setup reverse proxy with Let's Encrypt?

Hiteshjethva

38 posts | 4 followers

Related Products

  • Platform For AI

    A platform that provides enterprise-level data modeling services based on machine learning algorithms to quickly meet your needs for data-driven operations.

    Learn More
  • VPC

    A virtual private cloud service that provides an isolated cloud network to operate resources in a secure environment.

    Learn More
  • Machine Translation

    Relying on Alibaba's leading natural language processing and deep learning technology.

    Learn More
  • Super App Solution for Telcos

    Alibaba Cloud (in partnership with Whale Cloud) helps telcos build an all-in-one telecommunication and digital lifestyle platform based on DingTalk.

    Learn More