- 安装git
yum install git
- 克隆odoo13源码
git clone --depth=1 -b 13.0 https://github.com/odoo/odoo.git
- 安装pgsql-10
# 添加源
yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm -y
# 安装
yum install postgresql10-contrib postgresql10-server -y
# 初始化
/usr/pgsql-10/bin/postgresql-10-setup initdb
# 启动数据库
sudo systemctl start postgresql-10
# 设置开机启动
sudo systemctl enable postgresql-10.service
# 进入数据库设置密码
su - postgres
psql
ALTER USER postgres WITH PASSWORD 'postgres';
# 创建新用户
CREATE USER odoo13 CREATEDB LOGIN PASSWORD 'odoo13';
\q
exit
- 设置pgsql远程访问
vim /var/lib/pgsql/10/data/pg_hba.conf
最后一行添加
host all all 0.0.0.0/0 md5
# 最好将其他的host配置都设为md5
vim /var/lib/pgsql/10/data/postgresql.conf
找到以下行取消注释并改为
listen_addresses = '*'
port = 5432
# 重启pgsql
systemctl restart postgresql-10
- 安装python3及虚拟环境
# 安装依赖
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
# 新建目录
mkdir /usr/local/python3
cd /usr/local/python3
# 下载3.7安装包
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
# 解压编译
tar -xvJf Python-3.7.0.tar.xz
cd Python-3.7.0
./configure --prefix=/usr/local/python3
make && make install
# 创建软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
# 虚拟环境
# 更新pip
pip3 install --upgrade pip
# 安装virtualenv、virtualenvwrapper
pip3 install virtualenv
pip3 install virtualenvwrapper
# 编辑.bashrc
vim ~/.bashrc
# 写入以下内容
# virtualenvwrapper
export WORKON_HOME=/root/ENVS
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
# 运行.bashrc
source ~/.bashrc
# 可能出现报错找不到virtualenvwrapper.sh
find / -name "virtualenvwrapper.sh"
找到后将最后一行路径替换一下
# 创建虚拟环境
mkvirtualenv odoo13
# 其他常见的virtualenvwrapper命令
# 切换虚拟环境
workon my_env
# 退出虚拟环境
deactivate
# 删除虚拟环境
rmvirtualenv my_env
# 列出虚拟环境
lsvirtualenv / workon
# 进入到虚拟环境所在的目录
cdvirtualenv
- 安装需要的库
# 在odoo根目录下进入虚拟环境
workon odoo13
# 安装各种dev
yum install gcc libffi-devel python-devel openssl-devel -y
yum install libxml2-devel -y
yum install libxslt-devel -y
yum install openldap-devel -y
# 安装第三方库
pip3 install -r requirements.txt
# 记录一个坑,这里不能用sudo pip,不然就是全局安装了,那么虚拟环境就没有意义了
- 启动odoo
# 写配置文件
vim odoo.conf
# 写入
db_host = 127.0.0.1
db_port = 5432
db_user = odoo13
db_password = odoo13
# 运行
python3 odoo-bin --config odoo.conf
# 默认端口8069 云服务器记得开防火墙
更新 将odoo设置为服务
将odoo设置为init服务并开机自启
- 写入脚本 /etc/init.d/odoo13
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start odoo daemon at boot time
# Description: Enable service provided by daemon.
# X-Interactive: true
### END INIT INFO
## more info: http://wiki.debian.org/LSBInitScripts
. /lib/lsb/init-functions
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
DAEMON=/root/odoo/odoo13/odoo-bin # odoo-bin 路径
NAME=odoo13
DESC=odoo13
PYTHON=/root/ENVS/odoo_py3/bin/python # python虚拟环境
CONFIG=/root/odoo/odoo13/odoo13.conf # 配置文件
LOGFILE=/root/odoo/odoo13/odoo13.log # 日志
PIDFILE=/var/run/${NAME}.pid
USER=root
export LOGNAME=$USER
#test -x $DAEMON || exit 0 # 测试得确保odoo-bin文件有可执行权限
set -e
function _start() {
start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER:$USER --background --make-pidfile --exec $PYTHON $DAEMON -- --config $CONFIG --logfile $LOGFILE
}
function _stop() {
start-stop-daemon --stop --quiet --pidfile $PIDFILE --oknodo --retry 3
rm -f $PIDFILE
}
function _status() {
start-stop-daemon --status --quiet --pidfile $PIDFILE
return $?
}
case "$1" in
start)
echo -n "Starting $DESC: "
_start
echo "ok"
;;
stop)
echo -n "Stopping $DESC: "
_stop
echo "ok"
;;
restart|force-reload)
echo -n "Restarting $DESC: "
_stop
sleep 1
_start
echo "ok"
;;
status)
echo -n "Status of $DESC: "
_status && echo "running" || echo "stopped"
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0
- 给脚本设置权限及开机自启
sudo chown root: /etc/init.d/odoo13 #修改odoo的所有者为root
sudo chmod 755 /etc/init.d/odoo13 #修改odoo的权限
# 启动服务
sudo /etc/init.d/odoo13 start #或者service odoo13 start
# 开机自启
sudo update-rc.d odoo13 defaults
设置为systemd服务
两个服务都一样,随便按装一个就好了,有的系统可能没有systemd
- 写入脚本 /lib/systemd/system/odoo13.service
[Unit]
Description=Odoo13
After=postgresql.service
[Service]
Type=simple
User=root
Group=root
# 路径按自己的修改
ExecStart=/root/ENVS/odoo_py3/bin/python /root/odoo/odoo13/odoo-bin -c /root/odoo/odoo13/odoo13.conf
[Install]
WantedBy=multi-user.target
- 设置
# 扫描新的服务
sudo systemctl daemon-reload
# 启动服务
sudo systemctl start odoo13
# 开机自启
sudo systemctl enable odoo13
网友评论