一、安装基础环境
- 1.1 更新系统
如下命令更新系统。
# 更新并重启
apt update && apt upgrade -y && shutdown -r now
- 1.2 下载node.js
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
- 1.3 安装程序运行所需依赖
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 cron vim git ttf-wqy-zenhei ttf-wqy-microhei
- 1.4 用Vim编辑器修改my.cnf文件
sudo vi /etc/mysql/my.cnf
# 将光标移动到最后,然后回车换行,复制以下文本内容,粘贴在光标处,按Esc,输入:wq 保存并退出。
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[mysql]
default-character-set = utf8mb4
- 1.5 重启sql
sudo service mysql restart
- 1.6 mysql的安全配置
sudo mysql_secure_installation
Enter current password for root (enter for none): # 输入root(mysql)的密码,初次安装默认没有,直接回车
Switch to unix_socket authentication [Y/n] n # 是否切换到unix套接字身份验证
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! # 看到这句话证明设置成功
- 1.7 安装yarn,并切换国内源
sudo npm install -g yarn
# 查看源
yarn config get registry
# 返回https://registry.yarnpkg.com表明为官方源,需要切换为国内源,以下为切换国内源代码
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
- 1.8 更改pip源
# 升级 pip 到最新版本 (>=10.0.0) 后进行配置:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# root用户也更新一下pip源
sudo pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
- 1.9 查看版本,对照一下
node -v && npm -v && python3 -V && pip3 -V && yarn -v
二、安装bench
sudo -H pip3 install frappe-bench
# 查看bench版本
bench --version
三、安装frappe框架
这一步时间比较长,代码库已经加了码云地址参数。如果网络超时失败,可重新运行该命令,重新运行之前需使用命令 rm -r frappe-bench 删除之前生成的目录。
bench init --frappe-branch version-14 frappe-bench --frappe-path=https://gitee.com/mirrors/frappe
四、安装新站点
# 安装的系统用户分配一下执行权限。
sudo chmod -R o+rx /home/erp/
# 进入bench目录
cd frappe-bench
#新建站点
bench new-site {sitename}
# 这里需要输入mariadb的root密码
# 安装完成后提示设置用户administrator的密码
五、安装app
- 5.1 下载app
bench get-app https://gitee.com/phipsoft/payments
bench get-app --branch version-14 erpnext https://gitee.com/mirrors/erpnext
bench get-app https://gitee.com/qpchen888/hrms
- 5.2 安装app
bench --site {sitename} install-app payments
bench --site {sitename} install-app erpnext
# 在安装hrms前需要先运行bench start,再开一个窗口来安装
bench --site {sitename} install-app hrms
六、设置为生产环境
即用supervisorctl管理所有进程,使用nginx做反向代理,USERNAME换成新建的账号
# 前面运行的bench 要停止再设置生产环境
bench运行的窗口按 Ctrl + c
# 设置为生产环境
sudo bench setup production erp
sudo vi /etc/supervisor/supervisord.conf
[unix_http_server]
file=var/tmp/supervisord.sock
chmod=0700
chown=erp:erp #在这个位置加上这一行,USERNAME如frappe:frappe
# 改完后执行
sudo -A systemctl restart supervisor
重要:设置成生产环境后,不用执行bench start进行启动!!!
安装完后可查看一下是否有活动的wokers
bench doctor
正常情况下会显示如下:
—–Checking scheduler status—–
Scheduler disabled for erpnext
Scheduler inactive for erpnext
Workers online: 3
—–erpnext Jobs—–
如果不成功,可以再设置一遍生产环境。
七、安装常用app
- 7.1 安装ERPNext界面汉化
# 获取app
bench get-app https://gitee.com/yuzelin/erpnext_chinese.git
# 安装app
bench --site {sitename} install-app erpnext_chinese
- 7.2 安装ERPNext开箱即用
# 获取app
bench get-app --branch version-14 https://gitee.com/yuzelin/erpnext_oob.git
# 安装app
bench --site {sitename} install-app erpnext_oob
- 7.3 安装ERPNext权限优化
# 获取app
bench get-app https://gitee.com/yuzelin/zelin_permission.git
# 安装app
bench --site {sitename} install-app zelin_permission
八、常见问题
使用过程中突然无法连接服务器,页面出现报错。
原因:
生产环境的fail2ban在同一ip操作太频繁时视为受到DDOS攻击而触发自动保护。
处理方法:
打开/etc/fail2ban/jail.d/nginx-proxy.conf
# 将maxtry数值改大一些,比如25,bantime改小一些,改完保存退出。
sudo vi /etc/fail2ban/jail.d/nginx-proxy.conf
# 重启fail2ban
sudo systemctl restart fail2ban
九、常用命令
更新app
bench update --apps erpnext --pull --reset
生产环境修改app的更新源
# 查看APP更新源
bench remote-urls
# 设置APP更新源
bench remote-set-url https://github.com/frappe/frappe.git