在本文中,我们将讲述如何在CentOS7服务器下的Python虚拟环境中安装配置Odoo13,源码从Github的存储库中下载,并使用Nginx作为反向代理。
通过SSH
以root
身份登录到服务器:
ssh root@your_server_ip
如需检查计算机上安装的CentOS的版本,可以运行以下命令:
cat /etc/redhat-release
在本案例中,我们所得到的结果如下
CentOS Linux release 7.7.1908 (Core)
运行以下命令更新服务器:
yum update
更新服务器后,输入以下内容启用EPEL 资源库 :
yum install epel-release
需要切换到root
用户:
sudo root
yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum install libffi-devel -y
cd /opt # 待安装的目录
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
tar -xvJf Python-3.7.0.tar.xz
mkdir /usr/local/python3
cd Python-3.7.0
./configure --prefix=/usr/local/python3
make && make install
ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
python3 -V
pip3 -V
会得到以下结果:
Python 3.7.0
pip 10.0.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
yum install git gcc wget nodejs-less libxslt-devel bzip2-devel openldap-devel libjpeg-devel freetype-devel
创建一个用于运行Odoo名为oodo13的系统用户,主目录为/opt/odoo13
:
sudo useradd -m -d /opt/odoo13 -U -r -s /bin/bash odoo13
*注:
首先列举出可用的软件包:
yum list postgresql*
在本教程中,我们选用PostgreSQL 9.6
版本。 若用户没有此版本的列表,可以使用以下命令从Postgres Yum
存储库中手动添加:
yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-redhat96-9.6-3.noarch.rpm -y
执行以下命令安装PostgreSQL 9.6:
yum install postgresql96 postgresql96-server postgresql96-contrib postgresql96-libs -y
初始化数据库:
/usr/pgsql-9.6/bin/postgresql96-setup initdb
开启 PostgreSQL服务:
systemctl start postgresql-9.6.service
可以配置PostgreSQL服务开机自启:
systemctl enable postgresql-9.6.service
最后,创建一个PostgreSQL用户,需要和已经为Odoo创建的用户(本例中用户名为odoo13)使用相同的名称。
sudo su - postgres -c "createuser -s odoo13"
wkhtmltopdf
软件包是Odoo用来将PDF
格式的HTML
制成以便可以打印PDF
报告的开源工具。 本案例中安装0.12.5版本,该版本在CentOS 7官方存储库中不可用。 为了下载并安装此版本,需要运行以下命令:
cd /opt/
wget https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox-0.12.5-1.centos7.x86_64.rpm
yum localinstall wkhtmltox-0.12.5-1.centos7.x86_64.rpm
首先,需要更改为用户“odoo13”:
su - odoo13
从Github的存储库中下载Odoo 13源代码:
git clone https://www.github.com/odoo/odoo --depth 1 --branch 13.0 /opt/odoo13/odoo
下载完成后,为Odoo创建一个新的Python
虚拟环境:
cd /opt/odoo13
python3 -m venv odoo13-venv
激活所创建的Python
虚拟环境:
source odoo-venv/bin/activate
pip install --upgrade pip
pip install --upgrade setuptools
pip3 install wheel
使用pip3
安装所有必需的Python模块:
pip3 install -r odoo/requirements.txt
完成后,通过键入以下命令停用环境并退出:
deactivate && exit
我们将创建一个包含第三方插件新目录,并将该目录的所有者更改为odoo13:
mkdir /opt/odoo13/odoo13-custom-addons
chown odoo: /opt/odoo13/odoo13-custom-addons
修改数据库连接的配置信息:
vi /var/lib/pgsql/9.6/data/pg_hba.conf
将数据库访问的配置信息修改如下:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 ident
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 ident
#host replication postgres ::1/128 iden
创建Odoo13的配置文件:
vi /etc/odoo13.conf
配置文件的内容如下:
[options]
; This is the password that allows database operations:
admin_passwd = admin_password
db_host = False
db_port = False
db_user = odoo13
db_password = False
addons_path = /opt/odoo13/odoo/addons,/opt/odoo13/odoo-custom-addons
*注:
admin_password
的内容。创建一个名为odoo13.service
的服务单元文件:
sudo vi /etc/systemd/system/odoo13.service
系统单元文件的内容如下:
[Unit]
Description=Odoo13
Requires=postgresql-9.6.service
After=network.target postgresql-9.6.service
[Service]
Type=simple
SyslogIdentifier=odoo13
PermissionsStartOnly=true
User=odoo13
Group=odoo13
ExecStart=/opt/odoo13/odoo13-venv/bin/python3 /opt/odoo13/odoo/odoo-bin -c /etc/odoo13.conf
StandardOutput=journal+console
[Install]
WantedBy=multi-user.target
然后重新加载守护程序,使之在systemd
中创建的新单元:
systemctl daemon-reload
可以启动Odoo13的服务:
systemctl start odoo13
可以查看Odoo13的服务状态:
systemctl status odoo13
得到启动的状态如下
● odoo13.service - Odoo13
Loaded: loaded (/etc/systemd/system/odoo13.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2019-11-19 15:21:40 CST; 2h 20min ago
Main PID: 28867 (python3)
CGroup: /system.slice/odoo13.service
└─28867 /opt/odoo13/odoo13-venv/bin/python3 /opt/odoo13/odoo/odoo-bin -c /etc/odoo13.conf
如果没有出现错误,可以使用以下命令启用Odoo13的服务开机自启:
systemctl enable odoo13
要查看Odoo日志的消息,可以使用以下命令:
journalctl -u odoo13
进入修改文件目录:
cd /var/lib/pgsql/9.6/data/
编译配置文件:
vi pg_hba.conf
修改文件末尾处 # IPv4 local connections
的内容:
host all all 127.0.0.1/32 ident # 在本行下面添加
host all all 0.0.0.0/0 trust # 添加内容
编译配置文件:
vi postgresql.conf
修改Connection Settings
为以下内容:
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
输入以下指令进入数据库:
su – postgres
进入数据库后,输入以下指令:
-bash-4.2$ psql
psql (9.6.12)
Type "help" for help.
修改“odoo13”用户的初始密码:
postgres=# alter user odoo with password 'odoo';
修改密码后,退出数据库:
postgres=# \q
-bash-4.2$ exit
Logout
打开浏览器并输入:http://
,成功安装则会进入以下界面:
*注:
Master Password
即为配置文件中所写的admin_passwd
。执行以下命令从Nginx官网中获取Centos的源地址:
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
通过yum search nginx
查看是否添加源成功,如果成功则执行下列命令安装Nginx:
sudo yum install -y nginx
可以启动Nginx的服务:
sudo systemctl start nginx.service
如果没有出现错误,可以使用以下命令启用Nginx的服务开机自启:
sudo systemctl enable nginx.service
修改Nginx的配置文件:
vi /usr/local/nginx/conf/nginx.conf
配置成以下内容:
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream direction{
server 127.0.0.1:8069; # 反向服务地址
}
server {
listen 80;
server_name _; # set all
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://direction; # 代理转发
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
完成后保存文件并重新启动Nginx服务:
sudo systemctl restart nginx.service