This tutorial will walk you through the process of installing the latest version of Odoo on CentOS 6. It is intended for those who might not be experienced Linux administrators but who want to run their own Odoo server. You can simply copy-paste the commands into your terminal or SSH window.
The tutorial is fully tested on CentOS 6.5 but should work for any 6.x version. Please see my other tutorial for CentOS 7 instructions.
First we will install the PostgreSQL database server, then install the necessary package dependencies. Next we will create a virtual Python environment (so we don’t interfere with the CentOS version) and install all the modules Odoo requires. Then it’s time to pull the latest Odoo code from GitHub and create a CentOS 6 compatible init script. Finally we will add the necessary firewall rules and connect to the server.
This tutorial assumes you have already performed a minimal install of the latest version of CentOS 6.5 on a server dedicated to just running Odoo. It also assumes you will be running Odoo on the same server as the PostgreSQL database. You will need at least 1GB of available RAM for lxml to install, although this can include SWAP space.
Odoo is a complicated installation with many dependencies and can be quite resource intensive. I highly recommend you install on a server (or real or virtual) that is dedicated to Odoo. Co-locating Odoo with existing websites/applications is likely to cause problems at some point.
1: Generate Odoo Passwords
Before starting installation we will generate two passwords. The first line generates a strong random password for the odoo server to access the PostgreSQL database that we will install. The second line is the master password you will use to create the Odoo database after the installation is complete. Don’t worry about these for now. After the installation is complete you will find both these passwords in the Odoo configuration file (/etc/odoo-server.conf).
Important: You must run these commands as the root user
代码语言:javascript复制ODOO_POSTGRES_PASSWORD=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-20};echo;`
ODOO_DB_ADMIN_PASSWORD=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-20};echo;`
2: Install and configure PostgreSQL
First will install the PostgreSQL version 9.3. Unfortunately the CentOS 6 official respository only contains older versions, so we will need to install directly from the PostgreSQL repositories. We use the repository rather than simply downloading an RPM because it’s easier to keep up to date with important security and maintenance updates. This command will add the PostgreSQL repository to your server:
代码语言:javascript复制rpm -ivh http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm
It’s important we exclude postgresql from the official CentOS repository files, otherwise we will encounter problems when we run updates:
代码语言:javascript复制sed -i 's/^gpgkey.*/&nexclude=postgresql*/' /etc/yum.repos.d/CentOS-Base.repo
Installing PostgreSQL and some associated libraries is now straightforward. We then need to initialise the database.
代码语言:javascript复制yum -y install postgresql93 postgresql93-server postgresql93-devel postgresql93-libs
service postgresql-9.3 initdb
Next we need to configure PostgreSQL so it will accept connections using MD5 hashed passwords so it’s compatible with the Python modules:
代码语言:javascript复制sed -i "/^host/s/ident/md5/g" /var/lib/pgsql/9.3/data/pg_hba.conf
Finally let’s add PostgreSQL to the list of services which will be enabled at startup. We then start the PostgreSQL server and add the Odoo user with the password we generated in step 1.
代码语言:javascript复制/sbin/chkconfig --level 35 postgresql-9.3 on
service postgresql-9.3 start
echo -e "$ODOO_POSTGRES_PASSWORDn$ODOO_POSTGRES_PASSWORDn" | su - postgres -c "createuser --createdb --username postgres --no-createrole --no-superuser --pwprompt odoo"
3: Installing Python
Odoo requires a modern version of Python lot of additional libraries. Potentially these could conflict with the Python libraries supplied in CentOS 6 and relied upon by the built in administration tools. So to avoid this risk we will create a virtual environment under the Odoo system user account which will be used solely by the Odoo server.
First lets install some package dependencies:
代码语言:javascript复制yum -y install wget gcc zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libffi-devel libxslt libxslt-devel libxml2 libxml2-devel openldap-devel libjpeg-turbo-devel openjpeg-devel libtiff-devel git libpng libXext libz.so.1 xorg-x11-fonts-Type1 curl cabextract
We also need the wkhtmltopdf package in order to generate PDF reports in Odoo. This link is for the 64bit version of CentOS. For 32bit change ‘amd64′ to ‘i386′ in the filename below.
代码语言:javascript复制rpm -ivh http://sourceforge.net/projects/wkhtmltopdf/files/0.12.2/wkhtmltox-0.12.2_linux-centos6-amd64.rpm/downloadln -s /usr/local/bin/wkhtmltopdf /usr/bin/
Optional: You may wish to install Microsoft’s Core Fonts so they are available when you generate reports in Odoo. First we need to install some dependencies, then the msttcore-fonts-installer rpm downloads the fonts from sourceforge, installs them and activates them on your CentOS server.
For 64 bit (x86) CentOS installs ONLY:
代码语言:javascript复制rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/libmspack-0.4-0.1.alpha.el6.x86_64.rpmrpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/cabextract-1.3-3.el6.x86_64.rpmrpm -ivh https://downloads.sourceforge.net/project/mscorefonts2/rpms/msttcore-fonts-installer-2.6-1.noarch.rpm
For 32 bit (i386) CentOS installs ONLY:
代码语言:javascript复制rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/libmspack-0.4-0.1.alpha.el6.i686.rpmrpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/cabextract-1.3-3.el6.i686.rpmrpm -ivh https://downloads.sourceforge.net/project/mscorefonts2/rpms/msttcore-fonts-installer-2.6-1.noarch.rpm
Now let’s download and install Python 2.7.8 from source. The first command removes any existing python2.7 installs from previous attempts. Note after compiling we use “altinstall” to prevent overwriting the CentOS default python installation. We will do the Python build in the root users home directory as some CentOS installs prevent the execution of compiled C programs in the /tmp/ directory for security reasons (see “noexec” in /etc/fstab):
代码语言:javascript复制rm -rf /usr/local/lib/python2.7
cd /root/
wget http://python.org/ftp/python/2.7.8/Python-2.7.8.tgztar -xzf Python-2.7.8.tgz
cd Python-2.7.8
./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make
make altinstall
With Python successfully installed it’s time to add the Python virtual environment (virtualenv) and the PIP module installation utility:
代码语言:javascript复制wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | /usr/local/bin/python2.7
/usr/local/bin/easy_install-2.7 pip virtualenv
Next let’s create an Odoo user and setup the virtual environment.
代码语言:javascript复制adduser odoo
DIR="/var/run/odoo /var/log/odoo /opt/odoo /opt/andromeda-addons"
for NAME in $DIR
do
if [ ! -d $NAME ]; then
mkdir $NAME
chown odoo.odoo $NAME
fi
done
4: Installing Python modules in a virtual environment
Odoo requires a lot of Python modules to run. With the Python virtual environment successfully created we now need to add all the additional modules.
Important note for WHM/cPanel users: If your hosting provider is using WHM/cPanel to manager your server, you must enable compiler access for the odoo user otherwise the Python and additional modules installation will fail. See here for instructions on how to enable compiler access. You can disable compiler access again after Odoo installation is completed.
Important: Commands in this section must be run as the odoo user
First let’s switch from root to the odoo user, then create a new virtual environment called odoo and activate it:
代码语言:javascript复制su - odoo
/usr/local/bin/virtualenv --python=/usr/local/bin/python2.7 odoo
source odoo/bin/activate
Before starting the module installation we need to add the path to the PostgreSQL binaries, otherwise the PsycoPG2 module install will fail:
代码语言:javascript复制export PATH=/usr/pgsql-9.3/bin:$PATH
Now let’s install all the Python modules. Note we are replacing PIL with pillow – it’s a better supporting fork of PIL and it plays nicely with the location of the CentOS development libraries.
代码语言:javascript复制pip install http://download.gna.org/pychart/PyChart-1.39.tar.gzpip install babel
pip install docutils
pip install feedparser
pip install gdata
pip install Jinja2
pip install mako
pip install mock
pip install psutil
pip install psycopg2
pip install pydot
pip install python-dateutil
pip install python-openid
pip install pytz
pip install pywebdav
pip install pyyaml
pip install reportlab
pip install simplejson
pip install unittest2
pip install vatnumber
pip install vobject
pip install werkzeug
pip install xlwt
pip install pyopenssl
pip install lxml
pip install python-ldap
pip install decorator
pip install requests
pip install pillow
pip install pyPdf
pip install passlib
5: Installing Odoo 8 from GitHub
Now it’s finally time to install Odoo itself. We are going to download the latest version of Odoo 8 from the GitHub repository. Note that we are installing into the /opt directory so we can easily manage the installation in a single location and keep it separate from the rest of the operating system.
Important: These commands must be run as the odoo user
代码语言:javascript复制cd /opt
git clone https://github.com/odoo/odoo.git --branch 8.0
chown -R odoo.odoo odoo
exit
Let’s create a basic Odoo server configuration file. The passwords we created earlier will be automatically populated. Note I’ve also disabled the various RPC modules for extra security as I don’t use them. I’ve also dialled back the logging so we only see warnings and fatal errors. I’m located in the UK, so the timezone is set to Europe/London.
Important: All the following commands must be run as the root user
代码语言:javascript复制cat > /etc/odoo-server.conf << EOF
[options]
; This is the password that allows database operations:
admin_passwd = $ODOO_DB_ADMIN_PASSWORD
; DATABASE OPTIONS
db_host = localhost
db_port = 5432
db_user = odoo
db_password = $ODOO_POSTGRES_PASSWORD
; MISC SETTINGS
addons_path = /opt/odoo/addons
load = web
timezone = Europe/London
without-demo=all
no-xmlrpc = True
no-xmlrpcs = True
no-netrpc = True
; LOG SETTINGS
logfile = /var/log/odoo/odoo-server.loglog_handler = werkzeug:WARNING
log_level = warn
no-logrotate = True
EOF
chown root.odoo /etc/odoo-server.confchmod 640 /etc/odoo-server.conf
I also like to enable logrotation using the built in CentOS tools so the logs are managed in the same way as all the other applications.
代码语言:javascript复制cat > /etc/logrotate.d/odoo-server << EOF
/var/log/odoo/*.log {
copytruncate
missingok
notifempty
}
EOF
Next we create a script to easily start and stop the Odoo server. We download a pre-created init script, then use a sed script to modify the startup command so it plays nicely with the virtual Python environment we created earlier.
代码语言:javascript复制wget -O /etc/init.d/odoo https://raw.githubusercontent.com/Johnzero/OE7/master/install/openerp-server.initsed -i "s/openerp/odoo/g" /etc/init.d/odoo
sed -i "s/OpenERP/Odoo/g" /etc/init.d/odoo
sed -i "s//usr/bin/setsid /usr/bin/odoo-server/~/odoo/bin/python /opt/odoo/openerp-server/" /etc/init.d/odoo
chmod x /etc/init.d/odoo
/sbin/chkconfig --level 35 odoo on
The final step in this section is to add the necessary firewall rules. The redirect command accepts connection on port 80 and redirects them to the default Odoo port 8069. This avoids your users having to remember to enter the port number each time.
代码语言:javascript复制/sbin/iptables -A INPUT -p tcp --dport 5432 -i lo -j ACCEPT -m comment --comment "Accept local connections to PostgreSQL"
/sbin/iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8069 -m comment --comment="Redirect Odoo HTTP requests to 8069"
/sbin/iptables -A INPUT -p tcp --dport 8069 -j ACCEPT -m comment --comment "Accept inbound Odoo connections"
/etc/init.d/iptables save
6: Launching Odoo and logging in
To start Odoo, simply run the init script:
代码语言:javascript复制/etc/init.d/odoo start
You should be able to open a browser and connect to your Odoo server IP address.
You can check the logfiles in /var/log/messages and /var/log/odoo/odoo-server.log to make sure everything started correctly. Note you can also use “/etc/init.d/odoo restart” and “/etc/init.d/odoo stop” to restart and stop Odoo as required.
代码语言:javascript复制tail -50f /var/log/odoo/odoo-server.log
Remember you can find your database admin password in the odoo configuration file: /etc/odoo-server.conf
7: Updating Odoo
If you want to update the Odoo code to the latest version you can easily do that by stopping the server then performing a “git pull”. Note that you must only do the git pull as the odoo user.
代码语言:javascript复制/etc/init.d/odoo stop
su - odoo
cd /opt/odoo
git pull
exit
/etc/init.d/odoo start
I hope this guide helps you get Odoo 8 up and running on CentOS 6.5. Let me know how you get on in the comment section, and also check out my other tutorials.