在Ubuntu 16.04上安装Odoo8
一、安装依赖组件
sudo apt-get -yq install adduser ghostscript postgresql-client-9.5 python python-pip python-imaging python-pychart python-libxslt1 xfonts-base xfonts-75dpi libxrender1 libxext6 fontconfig python-zsi python-lasso libzmq3-dev libpq-dev python-dev libffi-dev libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev libssl-dev libjpeg8-dev
二、安装wkhtmltopdf
wget http://download.gna.org/wkhtmltopdf/0.12/0.12.1/wkhtmltox-0.12.1_linux-trusty-amd64.deb
sudo dpkg -i wkhtmltox-0.12.1_linux-trusty-amd64.deb
三、安装Postgres
1、安装
sudo apt-get install postgresql
2、创建数据库用户
sudo su postgres
createuser --createdb --username postgres --no-createrole --pwprompt odoo
创建用户时,密码设定为odoo,如果不是odoo,则下面的配置文件中需要相应修改
四、创建系统用户
sudo adduser odoo
五、获取Odoo代码
1、安装git
sudo apt-get install git
2、下载代码
su - odoo
cd
git clone https://github.com/Odoo/odoo.git --depth 1 --branch 8.0 --single-branch odoo
六、升级pip
pip install --upgrade pip
七、安装Python依赖库
sudo pip install -r /home/odoo/odoo/requirements.txt
通过豆瓣镜像安装:
sudo pip install -r /home/odoo/odoo/requirements.txt -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
通过中科大镜像安装:
sudo pip install -r /home/odoo/odoo/requirements.txt -i http://pypi.mirrors.ustc.edu.cn/simple/ --trusted-host pypi.mirrors.ustc.edu.cn
通过阿里云镜像安装:
sudo pip install -r /home/odoo/odoo/requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
八、配置odoo
在/home/odoo/目录下创建odoo-server.conf,填入以下内容
[options]
admin_passwd = admin
xmlrpc = True
xmlrpc_port = 8069
db_host = 127.0.0.1
db_port = 5432
db_user = odoo
db_password = odoo
addons_path = /home/odoo/odoo/addons,/home/odoo/odoo/openerp/addons
基于上面的配置文件,启动命令如下:
/home/odoo/odoo/openerp-server -c /home/odoo/odoo-server.conf
九、安装报表中文字体:
sudo apt-get install ttf-wqy-zenhei
sudo apt-get install ttf-wqy-microhei
十、配置启动脚本:
1、启动脚本内容如下:
#!/bin/bash
### BEGIN INIT INFO
# Provides: odoo.py
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# 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=/home/odoo/odoo/odoo.py
NAME=odoo
DESC=odoo
CONFIG=/home/odoo/odoo.conf
LOGFILE=/home/odoo/odoo-server.log
PIDFILE=/home/odoo/${NAME}.pid
USER=odoo
export LOGNAME=$USER
test -x $DAEMON || exit 0
set -e
function _start() {
start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER:$USER --background --make-pidfile --exec $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
2、把启动脚本复制到
/etc/init.d/odoo
并设置自动启动:
sudo su -
chmod +x /etc/init.d/odoo
update-rc.d odoo defaults
# =====================================================
# 下面是自动安装脚本
# =====================================================
#!/bin/bash ################################################################################ # Script for installing Odoo V8 on Ubuntu 16.04 LTS (could be used for other version too) # Author: Youfu Sheng([email protected]) #------------------------------------------------------------------------------- # This script will install Odoo on your Ubuntu 16.04 server. It can install multiple Odoo instances # in one Ubuntu because of the different xmlrpc_ports #------------------------------------------------------------------------------- # Make a new file: # sudo nano odoo-install.sh # Place this content in it and then make the file executable: # sudo chmod +x odoo-install.sh # Execute the script to install Odoo: # ./odoo-install ################################################################################ ##fixed parameters #odoo OE_USER="odoo" #OE_HOME="/$OE_USER" OE_HOME="/opt/odoo" OE_HOME_EXT="$OE_HOME/${OE_USER}-server" #Set to true if you want to install it, false if you don't need it or have it already installed. INSTALL_WKHTMLTOPDF="True" #The default port where this Odoo instance will run under (provided you use the command -c in the terminal) #Set the default Odoo port (you still have to use -c /etc/odoo-server.conf for example to use this.) OE_PORT="8069" #Choose the Odoo version which you want to install. For example: 9.0, 8.0, 7.0 or saas-6. When using 'trunk' the master version will be installed. #IMPORTANT! This script contains extra libraries that are specifically needed for Odoo 9.0 OE_VERSION="8.0" #set the superadmin password OE_SUPERADMIN="admin" OE_CONFIG="${OE_USER}-server" #Flag for switch to upgrade OS or not UPGRADE_OS="False" #Flag for switch to install less or not(Needed by ODOO9) INSTALL_NODE="False" #-------------------------------------------------- # Update Server #-------------------------------------------------- if [ $UPGRADE_OS = "True" ]; then echo -e "\n---- Update Server ----" sudo apt-get update sudo apt-get upgrade -y fi #-------------------------------------------------- # Install PostgreSQL Server #-------------------------------------------------- echo -e "\n---- Install PostgreSQL Server ----" sudo apt-get install postgresql -y echo -e "\n---- PostgreSQL $PG_VERSION Settings ----" sudo sed -i s/"#listen_addresses = 'localhost'"/"listen_addresses = '*'"/g /etc/postgresql/9.5/main/postgresql.conf echo -e "\n---- Creating the ODOO PostgreSQL User ----" sudo su - postgres -c "createuser -s $OE_USER" 2> /dev/null || true #-------------------------------------------------- # Install Dependencies #-------------------------------------------------- echo -e "\n---- Install tool packages ----" if [ OE_VERSION = "9.0" ]; then #For Odoo9 sudo apt-get install wget subversion git bzr bzrtools python-pip gdebi-core -y echo -e "\n---- Install python packages ----" sudo apt-get install python-dateutil python-feedparser python-ldap python-libxslt1 python-lxml python-mako python-openid python-psycopg2 python-pybabel python-pychart python-pydot python-pyparsing python-reportlab python-simplejson python-tz python-vatnumber python-vobject python-webdav python-werkzeug python-xlwt python-yaml python-zsi python-docutils python-psutil python-mock python-unittest2 python-jinja2 python-pypdf python-decorator python-requests python-passlib python-pil -y echo -e "\n---- Install python libraries ----" sudo pip install gdata psycogreen ofxparse else #For Odoo8 sudo apt-get -yq install adduser ghostscript postgresql-client-9.5 python python-pip python-imaging python-pychart python-libxslt1 xfonts-base xfonts-75dpi libxrender1 libxext6 fontconfig python-zsi python-lasso libzmq3-dev libpq-dev python-dev libffi-dev libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev libssl-dev libjpeg8-dev fi if [ INSTALL_NODE = "True" ]; then echo -e "\n--- Install other required packages" sudo apt-get install node-clean-css -y sudo apt-get install node-less -y sudo apt-get install python-gevent -y fi #-------------------------------------------------- # Install Wkhtmltopdf if needed #-------------------------------------------------- if [ $INSTALL_WKHTMLTOPDF = "True" ]; then echo -e "\n---- Install wkhtml and place shortcuts on correct place for ODOO 9 ----" sudo wget http://download.gna.org/wkhtmltopdf/0.12/0.12.1/wkhtmltox-0.12.1_linux-trusty-amd64.deb sudo dpkg -i wkhtmltox-0.12.1_linux-trusty-amd64.deb sudo ln -s /usr/local/bin/wkhtmltopdf /usr/bin sudo ln -s /usr/local/bin/wkhtmltoimage /usr/bin else echo "Wkhtmltopdf isn't installed due to the choice of the user!" fi echo -e "\n---- Create ODOO system user ----" sudo adduser --system --quiet --shell=/bin/bash --home=$OE_HOME --gecos 'ODOO' --group $OE_USER #The user should also be added to the sudo'ers group. sudo adduser $OE_USER sudo echo -e "\n---- Create Log directory ----" sudo mkdir /var/log/$OE_USER sudo chown $OE_USER:$OE_USER /var/log/$OE_USER #-------------------------------------------------- # Install ODOO #-------------------------------------------------- echo -e "\n==== Installing ODOO Server ====" sudo git clone --depth 1 --branch $OE_VERSION https://www.github.com/odoo/odoo $OE_HOME_EXT/ echo -e "\n---- Create custom module directory ----" sudo su $OE_USER -c "mkdir $OE_HOME/custom" sudo su $OE_USER -c "mkdir $OE_HOME/custom/addons" echo -e "\n---- Setting permissions on home folder ----" sudo chown -R $OE_USER:$OE_USER $OE_HOME/* echo -e "* Create server config file" sudo cp $OE_HOME_EXT/debian/openerp-server.conf /etc/${OE_CONFIG}.conf sudo chown $OE_USER:$OE_USER /etc/${OE_CONFIG}.conf sudo chmod 640 /etc/${OE_CONFIG}.conf echo -e "* Change server config file" sudo sed -i s/"db_user = .*"/"db_user = $OE_USER"/g /etc/${OE_CONFIG}.conf sudo sed -i s/"; admin_passwd.*"/"admin_passwd = $OE_SUPERADMIN"/g /etc/${OE_CONFIG}.conf sudo su root -c "echo 'logfile = /var/log/$OE_USER/$OE_CONFIG$1.log' >> /etc/${OE_CONFIG}.conf" sudo su root -c "echo 'addons_path=$OE_HOME_EXT/addons,$OE_HOME/custom/addons' >> /etc/${OE_CONFIG}.conf" echo -e "* Create startup file" sudo su root -c "echo '#!/bin/sh' >> $OE_HOME_EXT/start.sh" sudo su root -c "echo 'sudo -u $OE_USER $OE_HOME_EXT/openerp-server --config=/etc/${OE_CONFIG}.conf' >> $OE_HOME_EXT/start.sh" sudo chmod 755 $OE_HOME_EXT/start.sh #-------------------------------------------------- # Upgrade pip #-------------------------------------------------- echo -e "\n---- Upgrade pip ----" # sudo pip install --upgrade pip sudo pip install --upgrade pip #-------------------------------------------------- # Install chinese fonts for PDF: #-------------------------------------------------- echo -e "\n==== Installing Chinese font for PDF ====" sudo apt-get install ttf-wqy-zenhei sudo apt-get install ttf-wqy-microhei #-------------------------------------------------- # Install Dependencies #-------------------------------------------------- echo -e "\n---- Install requirements ----" #Set to use douban mirror for chinese mainland users,other users remove the mirror address to use offical source sudo pip install -r $OE_HOME_EXT/requirements.txt -i http://pypi.douban.com/simple --trusted-host pypi.douban.com #-------------------------------------------------- # Adding ODOO as a deamon (initscript) #-------------------------------------------------- echo -e "* Create init file" cat <~/$OE_CONFIG #!/bin/sh ### BEGIN INIT INFO # Provides: $OE_CONFIG # Required-Start: \$remote_fs \$syslog # Required-Stop: \$remote_fs \$syslog # Should-Start: \$network # Should-Stop: \$network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Enterprise Business Applications # Description: ODOO Business Applications ### END INIT INFO PATH=/bin:/sbin:/usr/bin DAEMON=$OE_HOME_EXT/openerp-server NAME=$OE_CONFIG DESC=$OE_CONFIG # Specify the user name (Default: odoo). USER=$OE_USER # Specify an alternate config file (Default: /etc/openerp-server.conf). CONFIGFILE="/etc/${OE_CONFIG}.conf" # pidfile PIDFILE=/var/run/\${NAME}.pid # Additional options that are passed to the Daemon. DAEMON_OPTS="-c \$CONFIGFILE" [ -x \$DAEMON ] || exit 0 [ -f \$CONFIGFILE ] || exit 0 checkpid() { [ -f \$PIDFILE ] || return 1 pid=\`cat \$PIDFILE\` [ -d /proc/\$pid ] && return 0 return 1 } case "\${1}" in start) echo -n "Starting \${DESC}: " start-stop-daemon --start --quiet --pidfile \$PIDFILE \ --chuid \$USER --background --make-pidfile \ --exec \$DAEMON -- \$DAEMON_OPTS echo "\${NAME}." ;; stop) echo -n "Stopping \${DESC}: " start-stop-daemon --stop --quiet --pidfile \$PIDFILE \ --oknodo echo "\${NAME}." ;; restart|force-reload) echo -n "Restarting \${DESC}: " start-stop-daemon --stop --quiet --pidfile \$PIDFILE \ --oknodo sleep 1 start-stop-daemon --start --quiet --pidfile \$PIDFILE \ --chuid \$USER --background --make-pidfile \ --exec \$DAEMON -- \$DAEMON_OPTS echo "\${NAME}." ;; *) N=/etc/init.d/\$NAME echo "Usage: \$NAME {start|stop|restart|force-reload}" >&2 exit 1 ;; esac exit 0 EOF echo -e "* Security Init File" sudo mv ~/$OE_CONFIG /etc/init.d/$OE_CONFIG sudo chmod 755 /etc/init.d/$OE_CONFIG sudo chown root: /etc/init.d/$OE_CONFIG echo -e "* Change default xmlrpc port" sudo su root -c "echo 'xmlrpc_port = $OE_PORT' >> /etc/${OE_CONFIG}.conf" echo -e "* Start ODOO on Startup" sudo update-rc.d $OE_CONFIG defaults echo -e "* Starting Odoo Service" sudo su root -c "/etc/init.d/$OE_CONFIG start" echo "-----------------------------------------------------------" echo "Done! The Odoo server is up and running. Specifications:" echo "Port: $OE_PORT" echo "User service: $OE_USER" echo "User PostgreSQL: $OE_USER" echo "Code location: $OE_USER" echo "Addons folder: $OE_USER/$OE_CONFIG/addons/" echo "Start Odoo service: sudo service $OE_CONFIG start" echo "Stop Odoo service: sudo service $OE_CONFIG stop" echo "Restart Odoo service: sudo service $OE_CONFIG restart" echo "-----------------------------------------------------------"