ERP hoặc hoạch định nguồn lực doanh nghiệp là một bộ ứng dụng doanh nghiệp được sử dụng để quản lý các quy trình kinh doanh cốt lõi. ERPNext là ứng dụng ERP tự lưu trữ miễn phí và mã nguồn mở được viết bằng Python. Nó sử dụng Node.js cho giao diện ngư��i dùng và MariaDB để lưu trữ dữ liệu của nó. ERPNext cung cấp giao diện web dễ sử dụng cho phép doanh nghiệp quản lý các công việc hàng ngày. Nó chứa các mô-đun cho kế toán, CRM, HRM, sản xuất, POS, quản lý dự án, mua hàng, quản lý bán hàng, quản lý kho, v.v. ERPNext có thể được sử dụng để quản lý các ngành công nghiệp khác nhau như nhà cung cấp dịch vụ, sản xuất, bán lẻ và trường học.
Trong hướng dẫn này, chúng tôi sẽ cài đặt ERPNext trên CentOS 7.
Điều kiện tiên quyết
Đối với hướng dẫn này, chúng tôi sẽ sử dụng erp.example.comlàm tên miền được trỏ đến máy chủ. Vui lòng đảm bảo thay thế tất cả các lần xuất hiện erp.example.combằng tên miền thực của bạn.
Cập nhật hệ thống cơ sở của bạn bằng hướng dẫn " Cách cập nhật CentOS 7 ". Khi hệ thống của bạn đã được cập nhật, hãy tiến hành cài đặt Python.
ERPNext cần Python phiên bản 2.7 để hoạt động. Python 2.7 được cài đặt theo mặc định trong tất cả các trường hợp máy chủ CentOS. Bạn có thể kiểm tra xem phiên bản Python đã cài đặt chưa bằng cách chạy:
python -V
Bạn sẽ nhận được đầu ra tương tự.
[user@vultr ~]$ python -V
Python 2.7.5
Mặc dù phiên bản cài đặt của Python không phải là phiên bản mới nhất, nhưng nó hoạt động mà không gặp trở ngại nào. Thay đổi phiên bản mặc định của Python có thể phá vỡ YUM.
Cài đặt các gói trong Development toolsnhóm được yêu cầu để biên dịch các tệp cài đặt.
sudo yum groupinstall -y "Development tools"
Cài đặt thêm một vài phụ thuộc:
sudo yum install -y redhat-lsb-core git python-setuptools python-devel openssl-devel libffi-devel
Cài đặt pipcông cụ Python . Pip là trình quản lý phụ thuộc cho các gói Python.
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
Lệnh trên sẽ cài đặt Pip vào hệ thống của bạn. Để đảm bảo rằng bạn có phiên bản mới nhất pipvà setuptools, hãy chạy:
sudo pip install --upgrade pip setuptools
Cài đặt Ansible bằng Pip. Ansible tự động hóa việc cung cấp phần mềm, quản lý cấu hình và triển khai ứng dụng.
sudo pip install ansible
Cài đặt máy chủ MariaDB
MariaDB là một nhánh của máy chủ cơ sở dữ liệu MySQL. Cài đặt MariaDB bằng cách chạy.
sudo yum -y install mariadb mariadb-server mysql-devel
The Barracuda storage engine is required for the creation of ERPNext databases, hence you will need to configure MariaDB to use the Barracuda storage engine. Edit the default MariaDB configuration file my.cnf.
sudo nano /etc/my.cnf
Add the following lines under the symbolic-links=0 line.
innodb-file-format=barracuda
innodb-file-per-table=1
innodb-large-prefix=1
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[mysql]
default-character-set = utf8mb4
Start MariaDB and enable it to automatically start at boot time.
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
Before configuring the database, you will need to secure MariaDB. You can secure it by running the mysql_secure_installation script:
sudo mysql_secure_installation
You will be asked for the current MariaDB root password. By default, there is no root password set on MariaDB. Press the "Enter" key to proceed. Set a strong password for the root user of your MariaDB server and answer "Y" to all of the other questions which are asked. The questions asked are self-explanatory.
Install Nginx, Nodejs and Redis
As the EPEL repository is installed by default in all Vultr CentOS 7 instances, you can directly install Redis and Nginx. But to install the latest version of Node.js, you will need to add the Nodesource repository into your system.
Add the Nodesource repository for Node.js 8.x.
sudo curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
Install Nginx, Nodejs and Redis:
sudo yum -y install nginx nodejs redis
Start Nginx and enable it to start at boot time by running:
sudo systemctl start nginx
sudo systemctl enable nginx
Start Redis and enable it to start at boot time by running:
sudo systemctl start redis
sudo systemctl enable redis
Install PDF Converter
The wkhtmltopdf program is a command line tool that converts HTML into PDF using the QT Webkit rendering engine. Install the required dependencies:
sudo yum -y install libXrender libXext xorg-x11-fonts-75dpi xorg-x11-fonts-Type1
Download the latest version of wkhtmltopdf.
wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
Extract the archive by running:
sudo tar -xf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz -C /opt
The above command will extract the archive to /opt/wkhtmltox. Create a softlink so that wkhtmltopdf and wkhtmltoimage can be executed globally as a command.
sudo ln -s /opt/wkhtmltox/bin/wkhtmltopdf /usr/bin/wkhtmltopdf
sudo ln -s /opt/wkhtmltox/bin/wkhtmltoimage /usr/bin/wkhtmltoimage
You can now run wkhtmltopdf -V command to check if it is working, you will see:
[user@vultr ~]$ wkhtmltopdf -V
wkhtmltopdf 0.12.4 (with patched qt)
At this point, we have all the required dependencies installed. You can now proceed to install Bench.
Install Bench
Bench is a command line utility provided by Frappe to install and manage the ERPNext application on a Unix-based system for both development and production purposes. Bench can also create and manage Nginx and supervisor configuration.
Create a new user to run Bench processes in the isolated environment.
sudo adduser bench -d /opt/bench
Change the password of the user.
sudo passwd bench
Provide sudo permissions to the bench user.
sudo usermod -aG wheel bench
Login as the newly created bench user:
sudo su - bench
Clone the Bench repository in /opt/bench:
cd /opt/bench
git clone https://github.com/frappe/bench bench-repo
Install Bench using pip.
sudo pip install -e bench-repo
Once Bench is installed, proceed further to install ERPNext using Bench.
Install ERPNext using Bench
Initialize a bench directory with frappe framework installed. To keep everything tidy, we will work under /opt/bench directory. Bench will also setup regular backups and auto updates once a day.
cd /opt/bench
bench init erpnext && cd erpnext
Create a new Frappe site:
bench new-site erp.example.com
The above command will prompt you for the MySQL root password. Provide the password which you have set for the MySQL root user earlier. It will also ask you to set a new password for the administrator account. You will need this password later to log into the administrator dashboard.
Download ERPNext installation files from the remote git repository using the Bench.
bench get-app erpnext https://github.com/frappe/erpnext
Install ERPNext on your newly created site:
bench --site erp.example.com install-app erpnext
ERPNext is installed on your server. You can start the application immediately to check if the application is started successfully:
bench start
However, you should stop the execution and proceed further to set up the application for production use.
Setup Supervisor and Nginx
By default, the ERPNext application listens on port 8000, not to the standard HTTP port 80. Also, running the built in web server for production use is not recommended as we will be exposing the server to the world. Hence, you should use a production web server as reverse proxy such as Apache or Nginx. In this tutorial, we will use Nginx as a reverse proxy as it can be automatically configured using Bench. Bench can automatically generate and install the configuration according to the ERPNext setup.
Although we can start the application using the above command, the execution of ERPNext will stop as soon as you close the terminal. To overcome this issue, I recommend to use Supervisor which is very helpful in running the application continuously in a production environment. Supervisor is a process control system that enables you to monitor and control a number of processes on Linux operating systems. Once Supervisor is configured, it will automatically start the application at boot time as well as on failures. Bench can automatically configure Supervisor for the ERPNext application.
Install Supervisor:
sudo yum -y install supervisor
Start Supervisor and enable it to automatically start at boot time:
sudo systemctl start supervisord
sudo systemctl enable supervisord
Setup Bench for production use:
sudo bench setup production bench
The above command may prompt you before replacing the existing Supervisor default configuration file with a new one. Choose y to proceed. Bench adds a number of processes to Supervisor configuration file. The above command will also ask you if you wish to replace the current Nginx configuration with a new one. Enter y to proceed. Once Bench has finished installing the configuration, provide other users to execute the files in your home directory of Bench user.
chmod o+x /opt/bench/
If you are running a firewall on your server, you will need to configure the firewall to set an exception for HTTP service. Allow Nginx reverse proxy to connect from outside the network.
sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload
You can now access the site on http://erp.example.com.
You can check the status of the processes by running:
sudo supervisorctl status all
You should see the following output:
[bench@vultr ~]$ sudo supervisorctl status all
erpnext-redis:erpnext-redis-cache RUNNING pid 2554, uptime 1:06:58
erpnext-redis:erpnext-redis-queue RUNNING pid 2553, uptime 1:06:58
erpnext-redis:erpnext-redis-socketio RUNNING pid 2555, uptime 1:06:58
erpnext-web:erpnext-frappe-web RUNNING pid 2559, uptime 1:06:58
erpnext-web:erpnext-node-socketio RUNNING pid 2556, uptime 1:06:58
erpnext-workers:erpnext-frappe-default-worker-0 RUNNING pid 2549, uptime 1:06:58
erpnext-workers:erpnext-frappe-long-worker-0 RUNNING pid 2551, uptime 1:06:58
erpnext-workers:erpnext-frappe-schedule RUNNING pid 2550, uptime 1:06:58
erpnext-workers:erpnext-frappe-short-worker-0 RUNNING pid 2552, uptime 1:06:58
To stop all of the ERPNext processes, use:
sudo supervisorctl stop all
To start all the ERPNext processes, use:
sudo supervisorctl start all
Setting Up SSL Using Let's Encrypt
Let's Encrypt provides free SSL certificates to the users. SSL can be installed manually or automatically through Bench. Bench can automatically install the Let's Encrypt client and obtain the certificates. Additionally, it automatically updates the Nginx configuration to use the certificates.
The domain name which you are using to obtain the certificates from the Let's Encrypt CA must be pointed towards the server. The client verifies the domain authority before issuing the certificates.
Enable DNS multi-tenancy for the ERPNext application.
bench config dns_multitenant on
Run Bench to set up Let's Encrypt on your site:
sudo bench setup lets-encrypt erp.example.com
During the execution of the script, the Let's Encrypt client will ask you to temporarily stop the Nginx web server. It will automatically install the required packages and Let's Encrypt client. The client will prompt for your email address. You will also need to accept the terms and conditions. Once the certificates have been generated, Bench will also generate the new configuration for Nginx which uses the SSL certificates. You will be asked before replacing the existing configuration. Bench also creates a crontab entry to automatically renew the certificates every month.
Finally, enable scheduler to automatically run the scheduled jobs:
bench enable-scheduler
You should see:
[bench@vultr erpnext]$ bench enable-scheduler
Enabled for erp.example.com
Wrapping Up
Once the process has finished, you can access your application at https://erp.example.com. Login with the username Administrator and the password you have set during installation. You will be taken to the desk where you will need to provide information to set ERPNext ERP according to your company. You can now use the application to manage your company.
Congratulations, you have a fully working ERPNext application installed on your CentOS 7 server.