在Ubuntu 18.04系統上安裝frappe ERPNext

blank

在Ubuntu 18.04系統上安裝frappe ERPNext

我的電腦Thinkpad T450s,win10,英特爾處理器,VM虛擬機中安裝Ubuntu18.04.2

Vmware版本VMware-workstation-full-16.1.1-17801498

Ubuntu版本 ubuntu-18.04.2-live-server-amd64

本篇 柒元 是想研究frappe,教程到安裝frappe並創建網站完畢,安裝erpnext繼續安裝一個app即可

柒元 安裝時,基本參考了梁海川的操作docs.qq.com/doc/DZWNjZH

部分與阿裡雲不同的坑我經過測試可能是填平了

歡迎更多朋友一起討論frappe和erpnext

root使用者

建立root使用者:

sudo passwd root //会让你输入当前用户密码。输入按下回车输入两次root密码

使用root使用者:

su root //提示输入root密码。输入即可

系統更新

sudo apt-get update   更新列表
sudo apt-get upgrade  更新应用

安裝git

sudo apt-get install git

安裝Python3

sudo apt-get install python3-dev

更改python為python3

blog.csdn.net/zyx_ly/ar

先查看系統中有那些Python版本:

$ ls /usr/bin/python*

/usr/bin/python            /usr/bin/python2-config  /usr/bin/python3m

/usr/bin/python2           /usr/bin/python3         /usr/bin/python-config

/usr/bin/python2.7         /usr/bin/python3.5

/usr/bin/python2.7-config  /usr/bin/python3.5m

先刪除預設的Python軟連結(如果之前沒有python的軟連接不需要做此步驟):

sudo rm /usr/bin/python

創建一個新的軟連結指向需要的Python版本:

sudo ln -s /usr/bin/python3 /usr/bin/python

python3 -V 查看 python3版本,返回3.6.9

python -V 查看 python版本

安裝pip3

sudo apt-get install python3-setuptools python3-pip   安装管理工具和py3
sudo pip3 install --upgrade pip    更新pip3,这个指令是最佳的

更改pip指向pip3

sudo ln -s /usr/bin/pip3 /usr/bin/pip

安裝wkhtmltopdf

sudo apt-get install wkhtmltopdf 國內不要用這條安裝命令

這條安裝在阿裡雲是預設安裝0.12.4,列印會有問題,如顯示{{body}}。 外國伺服器會預設最新。

這裡用root用戶進行安裝,如下

cd ~    打开root的根目录
sudo apt-get install -y software-properties-common  是个字库转换的软件
sudo apt-add-repository -y "deb http://security.ubuntu.com/ubuntu bionic-security main" 

add-apt-repository是以一个包管理软件
阿里云没有wkhtmltox_0.12.5-1.bionic_amd64指定要的库libpng12-0
sudo apt-get -yq update     更新一下apt-get
sudo apt-get install -y libxrender1 libfontconfig1 libx11-dev
sudo apt-get install -y libjpeg62 libxtst6 fontconfig 
sudo apt-get install -y xfonts-75dpi xfonts-base libpng12-0 

安装wkhtmltopdf需要的字体库等等,实际安装时好像少了个
我日志没保存急不得了,反正看下报错,然后继续sudo apt-get install -y XXX就可以了

這裡如果安裝libpng12-0出錯可能是由於ubuntu不支援libpng12-0導致的,下面的方法可解決

方式1

#这个适用于Ubuntu18
wget "https://launchpadlibrarian.net/377985746/libpng12-0_1.2.54-1ubuntu1.1_amd64.deb"

方式2

#这个适用于Ubuntu19和以上
apt --fix-boken install   
 #上面这句话,如果下面几个安装不成功可以执行一下试试
 #libxrender1 libfontconfig1 libx11-dev libjpeg62 libxtst6 fontconfig 
 # xfonts-75dpi xfonts-base

sudo add-apt-repository ppa:linuxuprising/libpng12
sudo apt update
sudo apt install libpng12-0

參考:
問題解決:ubuntu20 無法安裝libpng12-0的解決辦法
libpng12 : “Linux Uprising” team (launchpad.net)

wkhtmltopdf安裝

wget "https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb"   
//国内很难下载,或者你安装的时候已经路径不对了!!!!用下面办法下载去。

最新版是0.12.6了,下面的網站上可以下載【用評論說只支援0.12.5版本,0.12.6好像也支援】

由於SSH預設一般是非root用戶連接的,所以外部下載下來的檔沒法直接拖到root目錄下,可以現放在登錄使用者的資料夾下,然後切換root使用者(實際上的操作安裝wkhtmltopdf全程root使用者下進行的),移動到root目錄下

mv /home/【SSH登录的用户名】/wkhtmltox_0.12.5-1.bionic_amd64.deb  ~

安裝(安裝wkhtmltopdf全程root使用者)

dpkg -i wkhtmltox_0.12.5-1.bionic_amd64.deb   //无权限换root用户(最好就)
sudo apt-get -f install   //到这里完成安装wkhtmltopdf
wkhtmltopdf -V   //检查下版本对不对,返回wkhtmltopdf 0.12.5 (with patched qt)

測試wkhtmltopdf是否可用:

wkhtmltopdf http://www.baidu.com  baidu.pdf  可将网页转换为pdf文档保存在当前文件夹

然後這裡會發現中文字體都是方框

需要找個這個 simsun.ttc拷貝到,伺服器/usr/share/fonts/目錄下

simsun.tc 下載位址 a.xzfile.com/down3/simsun_downcc.com.zip 點擊直接下載

上面哪個不能用就在這裡下載吧 downcc.com/font/7664.ht

我是放到用户文件夹下,然后用root账户移动过去
# mv /home/【用户名】/simsun.ttc  /usr/share/fonts

安裝資料庫MariaDB 10.3

sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://mirrors.tuna.tsinghua.edu.cn/mariadb/repo/10.3/ubuntu bionic main'
sudo apt update
sudo apt install mariadb-server    输入两遍数据库管理密码

【mysql】

sudo apt-get install libmysqlclient-dev

【配置MySQL】

sudo vim /etc/mysql/my.cnf   我更喜欢vim编辑

【添加以下內容】

[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

[mysql]
default-character-set = utf8mb4

【重啟MariaDB】

sudo service mysql restart       重启服务

安裝Redis

sudo apt-get install redis-server

安装完成后,Redis服务器会自动启动。
使用ps -aux|grep redis命令可以看到服务器系统进程默认端口6379
redis      2890  0.2  0.1  41872  6064 ?        Ssl  14:17   0:07 /usr/bin/redis-server 127.0.0.1:6379     
hzlarm     3222  0.0  0.0  11324   780 pts/2    S+   15:02   0:00 grep --color=auto redis 

使用netstat -nlt|grep 6379命令可以看到redis服务器状态
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN
使用sudo /etc/init.d/redis-server status命令可以看到Redis服务器状态

參考:blog.csdn.net/hzlarm/ar

安裝node.js 12

root 使用者下用 nvm 安裝 node,切換到新使用者用不了,很麻煩不折騰了,apt-get安裝很香

sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
日志提示
## Run sudo apt-get install -y nodejs to install Node.js 13.x and npm
## You may also need development tools to build native addons:
     sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:【这里还告诉了怎么装yarn】
     curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
     echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
     sudo apt-get update && sudo apt-get install yarn
sudo apt-get install -y nodejs

這裡的node.js如果上面的方式安裝失敗(上面的我再美國的阿裡雲上一直不成功),可以試試下面的方法

#Ubuntu 上 Node.js 安装和卸载#2、Ubuntu 卸载 Node.Js
sudo apt-get remove nodejs
#1、Ubuntu 安装 Node.Js#1.1、执行检查可更新的软件:
sudo apt-get update
#1.2、先用普通的apt工具安装低版本的node,然后再升级最新。
sudo apt-get install nodejs
sudo apt install nodejs-legacy    #这句执行失败也没关系
sudo apt install npm
#1.3、更换淘宝的镜像,这个是必须的,用过的node的人都知道。
set registry https://registry.npm.taobao.org
#1.4、安装更新版本的工具N,执行:   
sudo npm install n -g
#1.5、更新新node版本,执行:
sudo n stable
#例如   sudo n 14

安裝yarn

sudo npm install -g yarn

如需要執行以下命令: 命令在使用者主目錄下執行( cd ~)

sudo apt-get remove yarn //卸载 yarn
sudo apt-get autoremove 
sudo npm install -g yarn //安装 yarn

安裝google API

臨時引用清華源,更快速

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple   google-api-core

pip安裝frappe-bench(安裝bench)

sudo -H pip3 install frappe-bench 
这是使用带有-H任意标志的sudo将使工作台可用于系统中的每个用户

如果以其他方式安裝的bench不生效可以卸載

pip list   查看安装列表
pip uninstall frappe-bench  卸载

pip install frappe-bench 失敗報錯

WARNING: The script virtualenv is installed in '/home/yanglijun/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. 
WARNING: The script honcho is installed in '/home/yanglijun/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script bench is installed in '/home/yanglijun/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

sudo pip install frappe-bench 失敗報錯

WARNING: The directory '/home/yanglijun/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.

大概是由于pip需要建立缓存,因此在你的$HOME/XXX文件夹下建立了.cache/pip的文件夹,但进入这个文件夹却出现了拒绝访问,

下面指令可能可以解决
sudo chown -R root /home/【用户名】/.cache/pip/ 

sudo chown -R root /home/【用户名】/.cache/pip/http/

使用bench

bench init frappe001
yanglijun@yanglijun:~$ bench init frappe001
$ /home/yanglijun/.local/bin/virtualenv -q env -p python3

Getting frappe
$ git clone https://github.com/frappe/frappe.git  --depth 1 --origin upstream
Cloning into 'frappe'...
remote: Enumerating objects: 3048, done.
remote: Counting objects: 100% (3048/3048), done.
remote: Compressing objects: 100% (2869/2869), done.
remote: Total 3048 (delta 404), reused 1100 (delta 107), pack-reused 0
Receiving objects: 100% (3048/3048), 16.07 MiB | 959.00 KiB/s, done.
Resolving deltas: 100% (404/404), done.

Installing frappe
$ frappe001/env/bin/python -m pip install -q -U -e frappe001/apps/frappe 
WARNING: You are using pip version 21.0.1; however, version 21.1.1 is available.
You should consider upgrading via the '/home/yanglijun/frappe001/env/bin/python -m pip install --upgrade pip' command.
$ yarn install
yarn install v1.22.5
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning " > [email protected]" has unmet peer dependency "[email protected] - 3".
warning " > [email protected]" has unmet peer dependency "popper.js@^1.16.0".
warning Workspaces can only be enabled in private projects.
[4/4] Building fresh packages...
$ yarn run snyk-protect
yarn run v1.22.5
$ snyk protect
Successfully applied Snyk patches

Done in 36.14s.
Done in 121.23s.
Updating node packages...

Installing node dependencies for frappe
$ yarn install
yarn install v1.22.5
[1/4] Resolving packages...
success Already up-to-date.
$ yarn run snyk-protect
yarn run v1.22.5
$ snyk protect
Successfully applied Snyk patches

Done in 6.76s.
Done in 8.17s.
$ bench build
Retrieving assets...

✔ Downloaded Frappe assets from http://assets.frappeframework.com/3875004d7e5c4cbd1bd7154cd5c0b6c9e5c8e4e3.tar.gz

Extracting assets...

✔ Restored js/barcode_scanner.min.js
✔ Restored js/chat.js.map
✔ Restored js/control.min.js
✔ Restored js/user_profile_controller.min.js.map
✔ Restored js/web_form.min.js
✔ Restored js/data_import_tools.min.js.map
✔ Restored js/dialog.min.js
✔ Restored js/report.min.js
✔ Restored js/libs.min.js
✔ Restored js/checkout.min.js.map
✔ Restored js/web_form.min.js.map
✔ Restored js/control.min.js.map
✔ Restored js/form.min.js
✔ Restored js/bootstrap-4-web.min.js.map
✔ Restored js/frappe-web.min.js
✔ Restored js/chat.js
✔ Restored js/frappe-recorder.min.js
✔ Restored js/report.min.js.map
✔ Restored js/data_import_tools.min.js
✔ Restored js/desk.min.js.map
✔ Restored js/checkout.min.js
✔ Restored js/dialog.min.js.map
✔ Restored js/user_profile_controller.min.js
✔ Restored js/frappe-web.min.js.map
✔ Restored js/moment-bundle.min.js
✔ Restored js/bootstrap-4-web.min.js
✔ Restored js/list.min.js
✔ Restored js/barcode_scanner.min.js.map
✔ Restored js/desk.min.js
✔ Restored js/list.min.js.map
✔ Restored js/frappe-recorder.min.js.map
✔ Restored js/form.min.js.map
✔ Restored css/printview.css
✔ Restored css/rollup.manifest.css
✔ Restored css/email.css
✔ Restored css/desk.min.css
✔ Restored css/frappe-rtl.css
✔ Restored css/frappe-web-b4.css
✔ Restored css/report.min.css
✔ Restored css/frappe-chat-web.css
✔ Restored css/login.css
✔ Restored css/web_form.css
yarn run v1.22.5
$ FRAPPE_ENV=production node rollup/build.js --skip_frappe
Production mode
✔ Built js/moment-bundle.min.js
✔ Built js/libs.min.js
Done in 1.87s.
SUCCESS: Bench frappe001 initialized

切換目錄並啟動,這時啟動訪問會404,在下一步創建網站

cd  frappe001
bench start

啟動時報錯

07:55:21 watch.1          | Rebuilding frappe-web-b4.css
07:55:21 watch.1          | Error in: undefined
07:55:21 watch.1          | Error: ENOSPC: System limit for number of file watchers reached, watch '/home/yanglijun/frappe001/apps/frappe/frappe/public/less/chat.less'
07:55:21 watch.1          |     at FSWatcher.start (internal/fs/watchers.js:210:26)
07:55:21 watch.1          |     at Object.watch (fs.js:1444:11)
07:55:21 watch.1          |     at new FileWatcher (/home/yanglijun/frappe001/apps/frappe/node_modules/rollup/dist/rollup.js:37956:33)
07:55:21 watch.1          |     at addTask (/home/yanglijun/frappe001/apps/frappe/node_modules/rollup/dist/rollup.js:37890:36)
07:55:21 watch.1          |     at Task.watchFile (/home/yanglijun/frappe001/apps/frappe/node_modules/rollup/dist/rollup.js:38209:9)
07:55:21 watch.1          |     at /home/yanglijun/frappe001/apps/frappe/node_modules/rollup/dist/rollup.js:38194:27
07:55:21 watch.1          |     at Array.forEach (<anonymous>)
07:55:21 watch.1          |     at /home/yanglijun/frappe001/apps/frappe/node_modules/rollup/dist/rollup.js:38193:34

因為限額問題,執行下面兩條可解決

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

 sudo sysctl --system

創建網站

bench new-site frappe001.com
yanglijun@yanglijun:~/frappe001$ bench new-site frappe001.com 
MySQL root password:
Installing frappe...
Updating DocTypes for frappe        : [========================================] 100%
Updating country info               : [========================================] 100%
Set Administrator password:
Re-enter Administrator password:
*** Scheduler is disabled ***
Current Site set to [frappe001.com](http://frappe001.com)

啟動網站

yanglijun@yanglijun:~/frappe001$ bench start
08:19:40 system | redis_cache.1 started (pid=77276)
08:19:40 system | redis_queue.1 started (pid=77281)
08:19:40 system | redis_socketio.1 started (pid=77286)
08:19:40 system | web.1 started (pid=77285)
08:19:40 system | socketio.1 started (pid=77294)
08:19:40 redis_cache.1 | 77282:C 05 May 08:19:40.108 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
08:19:40 redis_queue.1 | 77290:C 05 May 08:19:40.108 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
08:19:40 redis_queue.1 | 77290:C 05 May 08:19:40.108 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=77290, just started
08:19:40 redis_queue.1 | 77290:C 05 May 08:19:40.108 # Configuration loaded
08:19:40 redis_queue.1 | 77290:M 05 May 08:19:40.109 * Increased maximum number of open files to 10032 (it was originally set to 1024).
08:19:40 redis_socketio.1 | 77292:C 05 May 08:19:40.113 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
08:19:40 redis_socketio.1 | 77292:C 05 May 08:19:40.113 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=77292, just started
08:19:40 redis_socketio.1 | 77292:C 05 May 08:19:40.114 # Configuration loaded
08:19:40 redis_cache.1 | 77282:C 05 May 08:19:40.116 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=77282, just started
08:19:40 redis_socketio.1 | 77292:M 05 May 08:19:40.117 * Increased maximum number of open files to 10032 (it was originally set to 1024).
08:19:40 redis_cache.1 | 77282:C 05 May 08:19:40.117 # Configuration loaded
08:19:40 redis_cache.1 | 77282:M 05 May 08:19:40.119 * Increased maximum number of open files to 10032 (it was originally set to 1024).
08:19:40 redis_cache.1 | 77282:M 05 May 08:19:40.129 * Running mode=standalone, port=13000.
08:19:40 redis_cache.1 | 77282:M 05 May 08:19:40.130 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
08:19:40 redis_cache.1 | 77282:M 05 May 08:19:40.135 # Server initialized
08:19:40 redis_cache.1 | 77282:M 05 May 08:19:40.142 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
08:19:40 redis_socketio.1 | 77292:M 05 May 08:19:40.142 * Running mode=standalone, port=12000.
08:19:40 redis_cache.1 | 77282:M 05 May 08:19:40.143 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
08:19:40 redis_queue.1 | 77290:M 05 May 08:19:40.144 * Running mode=standalone, port=11000.
08:19:40 redis_queue.1 | 77290:M 05 May 08:19:40.144 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
08:19:40 redis_queue.1 | 77290:M 05 May 08:19:40.144 # Server initialized
08:19:40 redis_queue.1 | 77290:M 05 May 08:19:40.144 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
08:19:40 redis_queue.1 | 77290:M 05 May 08:19:40.144 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
08:19:40 redis_queue.1 | 77290:M 05 May 08:19:40.144 * Ready to accept connections
08:19:40 redis_socketio.1 | 77292:M 05 May 08:19:40.144 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
08:19:40 redis_cache.1 | 77282:M 05 May 08:19:40.145 * Ready to accept connections
08:19:40 redis_socketio.1 | 77292:M 05 May 08:19:40.150 # Server initialized
08:19:40 redis_socketio.1 | 77292:M 05 May 08:19:40.150 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.08:19:40 redis_socketio.1 | 77292:M 05 May 08:19:40.150 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
08:19:40 redis_socketio.1 | 77292:M 05 May 08:19:40.150 * Ready to accept connections
08:19:40 system | worker_short.1 started (pid=77299)
08:19:40 system | schedule.1 started (pid=77314)
08:19:40 system | watch.1 started (pid=77300)
08:19:40 system | worker_default.1 started (pid=77316)
08:19:40 system | worker_long.1 started (pid=77315)
08:19:43 socketio.1 | listening on *: 9000
08:19:45 web.1 |  * Running on http://0.0.0.0:8000/ (Press CTRL+C to quit)
08:19:45 web.1 |  * Restarting with inotify reloader
08:19:46 watch.1 | yarn run v1.22.5
08:19:46 watch.1 | $ node rollup/watch.js
08:19:47 web.1 |  * Debugger is active!
08:19:47 web.1 |  * Debugger PIN: 273-583-408
08:19:51 watch.1 | 
08:19:51 watch.1 | Rollup Watcher Started
08:19:51 watch.1 | 
08:19:51 watch.1 | Watching...
08:19:56 watch.1 | Rebuilding frappe-web-b4.css
08:19:57 watch.1 | Rebuilding frappe-chat-web.css
08:19:57 watch.1 | Rebuilding chat.js
08:20:00 watch.1 | Rebuilding frappe-recorder.min.js

frappe安裝完畢,訪問127.0.0.1:8000可打開網站,登錄

帳號是 administrator

密碼是 創建網站時設置的

柒元

What do you think?

Written by marketer

blank

小微企業數字化轉型的思考

ERPNext 低代碼開發平臺中battery included 自帶電池的概念解析