一步一步安装erpnext - iverson999/erpnext GitHub Wiki
环境:腾讯云轻量应用服务器
系统:Ubuntu 22.04 LTS
APP版本:Frappe / ERPNext
原贴地址:
我的安装手记要往下翻
Table of Contents:
- Step 1: Server Setup
- Step 2: Install Required Packages
- Step 3: Configure MySQL Server
- Step 4: Install CURL, Node, NPM, Yarn
- Step 5: Install Frappe Bench
- Step 6: Install ERPNext and other Apps
- Step 7: Setup Production Server
PRE-REQUISITES:
- Operating System: Linux Ubuntu 22.04 LTS
- Minimum Recommended Hardware: 2 CPU | 2 GB RAM | 10 GB Disk
- Root shell access to the server (via SSH)
SERVER SETUP
1.1 Login to the server as root user
1.2 Setup correct date and timezone (important step as it impacts ERPNext usage)
Check the server’s current timezone
date
Set correct timezone as per your region
timedatectl set-timezone "Asia/Kolkata"
1.3 Update & upgrade server packages
sudo apt-get update -y
sudo apt-get upgrade -y
1.4 Create a new user We create this user as a security measure to prevent root user access. This user will be assigned admin permissions and will be used as the main Frappe Bench user
sudo adduser [frappe-user]
usermod -aG sudo [frappe-user]
su [frappe-user]
cd /home/[frappe-user]/
Note: Replace [frappe-user] with your username. Eg. sudo adduser myname
INSTALL REQUIRED PACKAGES
Frappe Bench and ERPNext requires many packages to run smoothly. In this step we will install all the required packages for the system to work correctly.
Note: During the installation of these packages the server might prompt you to confirm if you want to continue installing the package [Y/n]. Just hit “y” on your keyboard to continue.
2.1 Install GIT
sudo apt-get install git
Check if GIT is correctly installed by running git --version
2.2 Install Python
sudo apt-get install python3-dev python3.10-dev python3-setuptools python3-pip python3-distutils
2.3 Install Python Virtual Environment
sudo apt-get install python3.10-venv
Check if Python is correctly installed by running python3 -V
2.4 Install Software Properties Common (for repository management)
sudo apt-get install software-properties-common
2.5 Install MariaDB (MySQL server)
sudo apt install mariadb-server mariadb-client
Check if MariaDB is correctly installed by running mariadb --version
2.6 Install Redis Server
sudo apt-get install redis-server
2.7 Install other necessary packages (for fonts, PDFs, etc)
sudo apt-get install xvfb libfontconfig wkhtmltopdf
sudo apt-get install libmysqlclient-dev
CONFIGURE MYSQL SERVER
3.1 Setup the server
sudo mysql_secure_installation
During the setup process, the server will prompt you with a few questions as given below. Follow the instructions to continue the setup;
- Enter current password for root: (Enter your SSH root user password)
- Switch to unix_socket authentication [Y/n]: Y
- Change the root password? [Y/n]: Y It will ask you to set new MySQL root password at this step. This can be different from the SSH root user password.
- Remove anonymous users? [Y/n] Y
- Disallow root login remotely? [Y/n]: N This is set as N because we might want to access the database from a remote server for using business analytics software like Metabase / PowerBI / Tableau, etc.
- Remove test database and access to it? [Y/n]: Y
- Reload privilege tables now? [Y/n]: Y
3.2 Edit the MySQL default config file
sudo vim /etc/mysql/my.cnf
Add the below code block at the bottom of the file;
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[mysql]
default-character-set = utf8mb4
If you don’t know how to use VIM:
- Once the file is open, hit “i” key to start editing the file.
- After you’re done editing the file hit “Esc + :wq” to save the file
3.3 Restart the MySQL server (for the config to take effect)
sudo service mysql restart
Instal CURL, Node, NPM and Yarn
4.1 Install CURL
sudo apt install curl
4.2 Install Node
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.profile
nvm install 16.15.0
4.3 Install NPM
sudo apt-get install npm
4.4 Install Yarn
sudo npm install -g yarn
Check if Node is correctly installed by running node --version
INSTALL FRAPPE BENCH
5.1 Install Frappe Bench
sudo pip3 install frappe-bench
Check if Frappe Bench is correctly installed by running bench --version
5.2 Initialize Frappe Bench
bench init --frappe-branch version-14 frappe-bench
5.3 Go to Frappe Bench directory This will be the main directory from where we will be running all the commands. The full path of this directory will be: /home/[frappe-user]/frappe-bench/
cd frappe-bench/
5.4 Change user directory permissions This will allow execution permission to the home directory of the frappe user we created in step 1.4
chmod -R o+rx /home/[frappe-user]/
5.5 Create a New Site We will use this as the default site where ERPNext and other apps will be installed.
bench new-site site1.local
Install ERPNext and other Apps
Finally, we’re at the last stage of the installation process!
6.1 Download the necessary apps to our server Download the payments apps . This app is required during ERPNext installation
bench get-app payments
Download the main ERPNext app
bench get-app --branch version-14 erpnext
Download the HR & Payroll app (optional)
bench get-app hrms
Download the ecommerce integrations apps (optional)
bench get-app ecommerce_integrations --branch main
Check if all the apps are correctly downloaded by running bench version --format table
6.2 Install all the Apps
Install the main ERPNext app
bench --site site1.local install-app erpnext
Install the HR & Payroll app (optional)
bench --site site1.local install-app hrms
Install the ecommerce integrations apps (optional)
bench --site site1.local install-app ecommerce_integrations
SETUP PRODUCTION SERVER
7.1 Enable scheduler service
bench --site site1.local enable-scheduler
7.2 Disable maintenance mode
bench --site site1.local set-maintenance-mode off
7.3 Setup production config
sudo bench setup production [frappe-user]
7.4 Setup NGINX web server
bench setup nginx
7.5 Final server setup
sudo supervisorctl restart all
sudo bench setup production [frappe-user]
When prompted to save new/existing config files, hit “Y”
Ready to Go!
You can now go to your server [IP-address]:80 and you will have a fresh new installation of ERPNext ready to be configured
安装步骤
-
设置root密码
sudo passwd root #密码root
-
切换用户到root
su - root
-
新建一个ERP系统用户
adduser ows usermod -aG sudo ows
-
更新并重启
apt update && apt upgrade -y && shutdown -r now
1.sudo npm install yarn -g 在这里插入图片描述
2.输入sudo su 再输入su - 切换到root目录后再进行安装 5. 重启后以前面新建的用户登录,下载node.js
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
-
安装操作系统所需的各种依赖
sudo apt install -y python3.10-dev python3-setuptools python3-pip python3-distutils python3.10-venv software-properties-common mariadb-server mariadb-client redis-server nodejs xvfb libfontconfig wkhtmltopdf libmysqlclient-dev nginx
-
用nano编辑my.cnf文件
sudo nano /etc/mysql/my.cnf
将光标移动到最后空白行,复制以下文本内容,粘贴后注意格式和换行要同下方,ctrl + X返回命令行,保存cy.cnf。
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[mysql]
default-character-set = utf8mb4
- 重启sql
sudo service mysql restart
- mysql的安全配置
sudo mysql_secure_installation
第一个输入数据库密码对话框出来的时候,直接敲回车代表没有密码,剩下的按照下面选择:
# 注:运行结果用 ··· 代替
Enter current password for root (enter for none): # 输入root(mysql)的密码,初次安装默认没有,直接回车
...
Switch to unix_socket authentication [Y/n] n # 是否切换到unix套接字身份验证[Y/n]
...
Change the root password? [Y/n] y #是否设置root用户密码
New password: # 新密码
Re-enter new password: # 再次输入密码
...
Remove anonymous users? [Y/n] y # 是否删除匿名用户,建议删除
...
Disallow root login remotely? [Y/n] n # 是否禁止root远程登录,建议不开启
...
Remove test database and access to it? [Y/n] n # 是否删除test数据库,可以保留
...
Reload privilege tables now? [Y/n] y # 是否重新加载权限表,也可以直接回车
...
Thanks for using MariaDB! # 看到这句话证明设置成功
##如果要设置root远程登录数据库,初始化 MariaDB 完成后,以 MySQL 的 root 身份登录
mysql -uroot -p密码
## 赋予 root 用户远程连接权限
grant all privileges on *.* to 'root'@'%' identified by 'admin';
flush privileges;
## 但一般不建议这么干!
- 安装yarn
sudo npm install -g yarn
#yarn config get registry查看源, 如果官方源请设置为以下国内源
yarn config set registry https://registry.npmmirror.com/ --global && \
yarn config set disturl https://npmmirror.com/package/dist --global && \
yarn config set sass_binary_site https://cdn.npmmirror.com/binaries/node-sass --global && \
yarn config set electron_mirror https://registry.npmmirror.com/binary.html?path=electron/ --global && \
yarn config set puppeteer_download_host https://registry.npmmirror.com/binary.html --global && \
yarn config set chromedriver_cdnurl https://cdn.npmmirror.com/binaries/chromedriver --global && \
yarn config set operadriver_cdnurl https://cdn.npmmirror.com/binaries/operadriver --global && \
yarn config set phantomjs_cdnurl https://cdn.npmmirror.com/binaries/phantomjs --global && \
yarn config set selenium_cdnurl https://cdn.npmmirror.com/binaries/selenium --global && \
yarn config set node_inspector_cdnurl https://cdn.npmmirror.com/binaries/node-inspector --global
npm set registry https://registry.npmmirror.com/ && \
npm set disturl https://npmmirror.com/package/dist && \
npm set sass_binary_site https://cdn.npmmirror.com/binaries/node-sass && \
npm set electron_mirror https://registry.npmmirror.com/binary.html?path=electron/ && \
npm set puppeteer_download_host https://registry.npmmirror.com/binary.html && \
npm set chromedriver_cdnurl https://cdn.npmmirror.com/binaries/chromedriver && \
npm set operadriver_cdnurl https://cdn.npmmirror.com/binaries/operadriver && \
npm set phantomjs_cdnurl https://cdn.npmmirror.com/binaries/phantomjs && \
npm set selenium_cdnurl https://cdn.npmmirror.com/binaries/selenium && \
npm set node_inspector_cdnurl https://cdn.npmmirror.com/binaries/node-inspector && \
npm cache clean --force
已经改了源,但安装过程中还是从官方镜像下载导致超时报网络问题的,换个时间也许就好了。这是因为esbuild这个东西是新东西,比较时髦,国内用的比较少,国内源都没有收录这个包,国内源没有的包就会去官方找,当下载超时了就报错了。
-
查看版本,对照一下,这一步不做也行
node -v && npm -v && python3 -V && pip3 -V && yarn -v
-
安装bench,即erpnext系统的命令行管理工具,类似windows系统的程序管理器。
sudo -H pip3 install frappe-bench --ignore-exist
#直接安装装不上的时候,可以先指定5.6.0版本,再升级到最新版本 ```
-
使用bench命令安装frappe框架,记得把frappe-bench(下方的version-14后面的名字)改成自己想要的名字,这一步时间比较长,别着急,代码库已经加了码云地址参数。如果网络超时失败,可重新运行该命令,重新运行之前需使用命令
rm -r frappe-bench
删除之前生成的目录。如果上面没改yarn的镜像源,安装的等待时间会非常长。bench init --frappe-branch version-15 frappe-bench --frappe-path=https://gitee.com/mirrors/frappe --ignore-exist
-
再将安装的系统用户分配一下执行权限。
chmod -R o+rx /home/ows/
-
进入bench目录,同样记得改名
cd frappe-bench
-
新建站点,名字自己取,安装时会提示输入数据库root账号的密码, 新站点数据库及erp系统管理员账号administator 密码,其中数据库root账号密码须与上述数据库安装时密码一致。administrator密码请一定记住,这是初始化系统时使用的密码。
#新建一个站点,下面的命令示例站点名称为erpnext bench new-site erpnext #这里要输入mysql root的密码 #安装完后提示要设置系统用户administrator的密码
-
下载app
bench get-app https://gitee.com/phipsoft/payments bench get-app --branch version-15 erpnext https://gitee.com/mirrors/erpnext bench get-app https://gitee.com/qpchen888/hrms
-
安装app
bench --site erpnext3 install-app payments bench --site erpnext3 install-app erpnext bench --site erpnext3 install-app hrms #在安装hrms前需要先bench start,再开一个窗口来安装
-
设置为生产环境,即用supervisorctl管理所有进程,使用nginx做反向代理,USERNAME换成第3步新建的账号,大功告成。
sudo bench setup production ows #重要:设置成生产环境后,不用执行bench start进行启动!!! #这里的{USERNAME}要换成安装时用的用户名,比如用ubuntu用户时,这里的{USERNAME}就是ubuntu
-
安装完后可查看一下是否有活动的wokers
bench doctor #正常情况下会显示如下: -----Checking scheduler status----- Scheduler disabled for erpnext Scheduler inactive for erpnext Workers online: 3 -----erpnext Jobs-----
-
以上完成后查看一下安装了哪些app
bench version
正常会显示以下两个app
erpnext 14.x.x frappe 14.x.x
安装完访问的初始画面是错乱的,可用下面的命令解决
chmod 701 /home/{frappe-user} #这里的{frappe-user}要换成安装时用的用户名,比如用ubuntu用户时,这里的{frappe-user}就是ubuntu
常用app安装
ERPNext中文汉化
-
获取app
bench get-app https://gitee.com/yuzelin/erpnext_chinese.git
-
安装
bench --site owserp install-app erpnext_chinese
ERPNext开箱即用
-
拉app时先修改一个配置文件。
sudo nano /etc/supervisor/supervisord.conf [unix_http_server] file=var/tmp/supervisord.sock chmod=0700 chown=frappe:frappe #在这个位置加上这一行 改完后执行 sudo -A systemctl restart supervisor
-
获取app
bench get-app --branch version-14 https://gitee.com/yuzelin/erpnext_oob.git
-
安装
bench --site {sitename} install-app erpnext_oob
ERPNext权限优化
-
获取app
bench get-app https://gitee.com/yuzelin/zelin_permission.git
-
安装
bench --site owserp install-app zelin_permission
Ubuntu20.04 安装打印wkhtmltopdf 库(上面已经装有了,这部分仅做参考)
1、先下载适合我们系统的安装包并进行安装:
wget "https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-
1/wkhtmltox_0.12.6-1.focal_amd64.deb" -O /tmp/wkhtml.deb
2、下一步进行安装
sudo dpkg -i /tmp/wkhtml.deb
3、这时可能会显示缺少依赖的错误,以下命令可解决这一问题:
sudo apt -f install
4、现在,我们可以检查wkhtmltopdf 库是否正确安装并确认是否为所需版本:
wkhtmltopdf –version
显示wkhtmltopdf 0.12.6 (with patched qt)即是正确版本
其他注意:
apt install wkhtmltopdf
这条命令国内阿里云源自动安装版本0.12.5,非patched qt 版本,erpnext 不打印页面头部和底部。
如果wkhtmltopdf 库不是我们需要的版本,应对其进行卸载,命令如下:
sudo apt remove --purge wkhtmltopdf
其他常见问题
-
使用过程中突然无法连接服务器,页面出现报错。
原因:
生产环境的fail2ban在同一ip操作太频繁时视为受到DDOS攻击而触发自动保护。
处理方法:
打开/etc/fail2ban/jail.d/nginx-proxy.conf
sudo nano /etc/fail2ban/jail.d/nginx-proxy.conf
将maxtry数值改大一些,比如25,bantime改小一些,改完保存退出。
重启fail2ban
sudo systemctl restart fail2ban
更多问题见余老师在码云的问题库:
版本升级案例
Frappe/ERPNext v14升级v15
-
备份(数据库、快照、镜像)
-
把node.js从16升级到18
sudo apt update sudo npm install -g nsu sudo n 18
-
进入bench工作台目录,将v14版升级到最新
bench update --reset
-
将bench 版本升级到最新
sudo pip3 install -U frappe-bench
-
切换到v15
bench switch-to-branch version-15 frappe erpnext --upgrade
bench get -app --branch=version-15 frappe
-
依次执行以下命令
bench update --reset --no-backup bench update --requirements bench migrate owserp bench restart
bench --site erpnext --force reinstall
安装版本2
-
如果当前登录的是root用户,就请新建一个用于安装ERP的sudo用户。
adduser ows usermod -aG sudo ows
-
更新系统并重启系统。
apt update && apt upgrade -y && shutdown -r now
-
使用安装ERP所建好的sudo用户,下载node.js
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
-
安装操作系统所需的各种依赖包
sudo apt install -y python3.10-dev python3-setuptools python3-pip python3-distutils python3.10-venv software-properties-common mariadb-server mariadb-client redis-server nodejs xvfb libfontconfig libmysqlclient-dev nginx git ansible
-
将Python的pip源改成国内源,有助于后面安装frappe时提高速度和成功率。
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ pip config set install.trusted-host mirrors.aliyun.com
-
接下来开始配置MariaDB,用nano编辑my.cnf文件。
sudo nano /etc/mysql/my.cnf
将光标移动到最后空白行,复制以下文本内容,粘贴后注意格式和换行要同下方,ctrl + X返回命令行,保存cy.cnf。
[mysqld] character-set-client-handshake = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci [mysql] default-character-set = utf8mb4
-
重启sql
sudo service mysql restart
-
开始mysql的安全配置
sudo mysql_secure_installation
第一个输入数据库密码对话框出来的时候,直接敲回车代表没有密码,剩下的按照下面选择:
# 注:运行结果用 ··· 代替 Enter current password for root (enter for none): # 输入root(mysql)的密码,初次安装默认没有,直接回车 ... Switch to unix_socket authentication [Y/n] n # 是否切换到unix套接字身份验证[Y/n] ... Change the root password? [Y/n] y #是否设置root用户密码 New password: # 新密码 Re-enter new password: # 再次输入密码 ... Remove anonymous users? [Y/n] y # 是否删除匿名用户,建议删除 ... Disallow root login remotely? [Y/n] n # 是否禁止root远程登录,建议不开启 ... Remove test database and access to it? [Y/n] n # 是否删除test数据库,可以保留 ... Reload privilege tables now? [Y/n] y # 是否重新加载权限表,也可以直接回车 ... Thanks for using MariaDB! # 看到这句话证明设置成功
-
安装yarn
sudo npm install -g yarn #yarn config get registry查看源, 如果官方源请设置为以下国内源 yarn config set registry https://registry.npmmirror.com/ --global && \ yarn config set disturl https://npmmirror.com/package/dist --global && \ yarn config set sass_binary_site https://cdn.npmmirror.com/binaries/node-sass --global && \ yarn config set electron_mirror https://registry.npmmirror.com/binary.html?path=electron/ --global && \ yarn config set puppeteer_download_host https://registry.npmmirror.com/binary.html --global && \ yarn config set chromedriver_cdnurl https://cdn.npmmirror.com/binaries/chromedriver --global && \ yarn config set operadriver_cdnurl https://cdn.npmmirror.com/binaries/operadriver --global && \ yarn config set phantomjs_cdnurl https://cdn.npmmirror.com/binaries/phantomjs --global && \ yarn config set selenium_cdnurl https://cdn.npmmirror.com/binaries/selenium --global && \ yarn config set node_inspector_cdnurl https://cdn.npmmirror.com/binaries/node-inspector --global npm set registry https://registry.npmmirror.com/ && \ npm set disturl https://npmmirror.com/package/dist && \ npm set sass_binary_site https://cdn.npmmirror.com/binaries/node-sass && \ npm set electron_mirror https://registry.npmmirror.com/binary.html?path=electron/ && \ npm set puppeteer_download_host https://registry.npmmirror.com/binary.html && \ npm set chromedriver_cdnurl https://cdn.npmmirror.com/binaries/chromedriver && \ npm set operadriver_cdnurl https://cdn.npmmirror.com/binaries/operadriver && \ npm set phantomjs_cdnurl https://cdn.npmmirror.com/binaries/phantomjs && \ npm set selenium_cdnurl https://cdn.npmmirror.com/binaries/selenium && \ npm set node_inspector_cdnurl https://cdn.npmmirror.com/binaries/node-inspector
-
查看版本,对照一下,这一步不做也行.
node -v && npm -v && python3 -V && pip3 -V && yarn -v
-
安装bench,即erpnext系统的命令行管理工具,类似windows系统的程序管理器。
sudo -H pip3 install frappe-bench
-
使用bench命令安装frappe框架。frappe-bench是安装frappe框架的目录名称。
bench init --frappe-branch version-15 frappe-bench --frappe-path=https://gitee.com/mirrors/frappe --verbose
-
再将安装的系统用户分配一下执行权限。
chmod -R o+rx /home/userid
-
进入bench目录
cd frappe-bench
-
新建站点,下面是以erpnext作为站点名称。
bench new-site owserp
-
设置为生产环境,即用supervisorctl管理所有进程,使用nginx做反向代理。如果安装只是为了做开发,可以跳过这一步。bench start
sudo bench setup production userid
-
下载app
bench get-app https://gitee.com/phipsoft/payments bench get-app --branch version-15 erpnext https://gitee.com/mirrors/erpnext bench get-app --branch version-15 https://gitee.com/phipsoft/hrms
-
安装app
bench --site owserp install-app payments bench --site owserp install-app erpnext bench --site owserp install-app hrms
bench --site test(站点的名称) install-app erpnext ```
-
安装完后可查看一下是否有活动的wokers,同样的,如果没开启生产环境,这一步也可以略过。
bench doctor
-
查看所需的app是否安装正确,可以用这个命令
bench version
-
最后解决可能存在PDF打印中文显示乱码所需要的工具
wget https://gitee.com/qinyanwan/erpnext/releases/download/v13.29.0/wkhtmltox_0.12.6.1-2.jammy_amd64.deb
wkhtmltopdf –version wkhtmltopdf –version
如果安装提示有缺少依赖的错误,执行下面命令。
sudo apt -f install
现在,我们可以检查wkhtmltopdf 库是否正确安装并确认是否为所需版本:
wkhtmltopdf –version
显示wkhtmltopdf 0.12.6 (with patched qt)即是正确版本
其他
汉化、本地化请登录https://gitee.com/yuzelin/按需安装相关APP。