於 CentOS 7.0 安裝 odoo 9.0

此篇教學是使用 CentOS 7.0 Minimal ISO – CentOS-7-x86_64-Minimal-1611.iso 安裝初始系統

yum -y update
yum install -y open-vm-tools
yum install -y epel-release
yum install -y vim
yum install -y postgresql-server

初始化 PostgreSQL DB

postgresql-setup initdb

啟動 postgresql 並設定為開機服務

systemctl start postgresql
systemctl enable postgresql

設定 PostgreSQL 的預設登入密碼

sudo -u postgres psql
postgres=# \password postgres
Enter new password:
Enter it again:
postgres=# \q

建立 Odoo 9.0 的 yum repo

vim /etc/yum.repos.d/odoo.repo

輸入以下內容

[odoo-nightly]
name=Odoo Nightly repository
baseurl=http://nightly.odoo.com/9.0/nightly/rpm/
enabled=1
gpgcheck=1
gpgkey=https://nightly.odoo.com/odoo.key

安裝 Odoo 9.0

yum install -y odoo

啟動 odoo 並設定為開機服務

systemctl start odoo
systemctl enable odoo

編輯 odoo config 檔

vim /etc/odoo/openerp-server.conf

admin_passwd = 要使用的密碼
addons_path = /opt/apps_odoo9,/usr/lib/python2.7/site-packages/openerp/addons
workers = 17
limit_memory_hard = 805306368
limit_memory_soft = 671088640
limit_request = 8192
limit_time_cpu = 60
limit_time_real = 120
max_cron_threads = 2

設定完成後重新啟動 odoo

systemctl restart odoo

 

easy_install xlrd

 

要下載 WKHTMLTOPDF
yum -y install wkhtmltox-0.12.2.1_linux-centos7-amd64.rpm

http://linoxide.com/linux-how-to/setup-openerp-odoo-centos-7/

Install Odoo 8 (OpenERP) in CentOS & Red Hat Enterprise Linux


$ sudo yum-config-manager –add-repo=https://nightly.odoo.com/8.0/nightly/rpm/odoo.repo

Danger
to print PDF reports, you must install wkhtmltopdf yourself: the version of wkhtmltopdf available in Fedora/CentOS repositories does not support headers and footers so it can not be installed automatically. Use the version available on the wkhtmltopdf download page.
Configuration

The configuration file can be found at /etc/odoo/openerp-server.conf

When the configuration file is edited, Odoo must be restarted via SystemD:

$ sudo systemctl restart odoo
odoo location
/usr/lib/python2.7/site-packages/openerp/addons

odoo config file
/etc/odoo/openerp-server.conf
logfile = /var/log/odoo/odoo-server.log
apt-get -y install xfonts-75dpi xfonts-base wkhtmltox
dpkg -i wkhtmltox-0.12.2.1_linux-precise-i386.deb
cd /usr/share/fonts/
wget http://okay.googlecode.com/files/DejaVuSans-Oblique.ttf http://okay.googlecode.com/files/DejaVuSans-BoldOblique.ttf http://okay.googlecode.com/files/DejaVuSans-Bold.ttf http://okay.googlecode.com/files/DejaVuSans.ttf
fc-cache -fv

https://www.odoo.com/forum/help-1/question/how-to-use-custom-fonts-in-rml-reports-71030
參照上方的方式載入字型

接下來修改 rml report 中的 stylesheet
在用到的 paraStyle 中加入 fontName=”DejaVuSansYuanTi-Regular”
*******
如果要安裝report_xls or Export Current View 模組需要安裝相關的模組
easy_install xlwt
Aeroo report on CentOS 7.0

easy_install genshi lxml uno pyoo
yum install cairo-devel

cd /opt/odoo_apps
git clone https://github.com/aeroo/aeroolib.git
cd /opt/odoo_apps/aeroolib
python setup.py install
#9 sudo vi /etc/init.d/office

#!/bin/sh

/usr/bin/soffice –nologo –nofirststartwizard –headless –norestore –invisible “–accept=socket,host=localhost,port=8100,tcpNoDelay=1;urp;” &
yum install libreofficelibreoffice-headless libreoffice-pyuno

easy_install jsonrpc2 daemonize configparser
cd /opt/odoo_apps
git clone https://github.com/aeroo/aeroo_docs.git
cd aeroo_docs/
python /opt/odoo_apps/aeroo_docs/aeroo-docs start -c /etc/aeroo-docs.conf
ln -s ‘/opt/odoo_apps/aeroo_docs/aeroo-docs’ ‘/etc/systemd/system/multi-user.target.wants/aeroo-docs’
echo /opt/openoffice4/program |tee /usr/lib/python2.7/site-packages/unohelper.pth
python /opt/odoo_apps/aeroo_docs/aeroo-docs start -c /etc/aeroo-docs.conf

卡住了
sudo ldconfig -v /usr/lib/openoffice/program

systemctl start nginx.service
systemctl enable nginx.service
git clone https://github.com/aeroo/aeroolib.git
git clone https://github.com/aeroo/aeroolib.git

pyoo??
python-relatorio: A templating library able to output odt and pdf files
python-genshi: Toolkit for stream-based generation of output for the web
PyYAML: YAML parser and emitter for Python
pycairo: Python bindings for the cairo library
pycha (install through python self installer # easy_install pycha, not included in base Centos distribution)
python-openoffice: Python libraries for interacting with OpenOffice.org
openoffice.org-pyuno : Python bindings for OpenOffice.org
OpenOffice.org v.2.3.x or above.

 

參考資料:

How to install Odoo 9 on a CentOS 7 VPS

Setting Up OpenERP (Odoo) 9 with Nginx on RHEL/CentOS and Debian/Ubuntu

Mattermost 升級教學 3.6.2 to 3.7.2 on CentOS 7.0

Mattermost 升級教學 3.5.0 to 3.6.2 on CentOS 7.0

Tar 指令教學

PostgreSQL 啟用遠端存取功能

剛安裝完 PostgreSQL 時,只能接受本機(Localhost)連線

優點是安全性較高、但也無法將『程式』與『資料庫』分離、也無法使用遠端管理工具

 

以下是修改設定的過程

CentOS

su
vim /var/lib/pgsql/9.4/data/postgresql.conf

listen_addresses = 'locahost'

修改為

listen_addresses = '*'

再修改 pg_hba.conf

vim /var/lib/pgsql/9.4/data/pg_hba.conf

新增一行

host    all             all             192.168.5.0/24(要的網段)          md5

重新載入 postgresql 即可

service postgresql reload

 

ubuntu

sudo vim /etc/postgresql/9.3/main/postgresql.conf

listen_addresses = 'locahost'

修改為

listen_addresses = '*'

再修改 pg_hba.conf

sudo vim /etc/postgresql/9.3/main/pg_hba.conf

新增一行

host    all             all             192.168.5.0/24(要的網段)          md5

重新載入 postgresql 即可

sudo service postgresql reload

Mattermost 升級教學 3.3.0 to 3.5.0 on CentOS 7.0

在 VM 中增加 CentOS 的硬碟空間

公司內部使用的虛擬機硬碟空間初始配置的容量都不大(約 30GB)

經常使用很快就會遇到空間不足的問題,此時可直接透過系統工具加大容量

首先直接將 VM 的虛擬磁碟的空間加大,這部分不介紹(如有快照,需先移除,否則無法增加容量,增加後需重開機

安裝分割程式
yum -y update
yum -y install parted
事先確認空間使用量
df -h

檔案系統 /dev/mapper/centos-root 是我們想增加容量的對象

可以看到『 / 』有 58G 的容量,還剩下 47G

進行切割
parted
> print free

最下方顯示尚有 2147MB 的可用空間

> mkpart primary 64.4GB 66.6GB (請依據 print 的內容處理)
> print (確認新增磁區成功)
> set 4 lvm on (4 為新增磁碟區在 print 中顯示的磁碟編號)
> quit

fdisk -l

可以看到 /dev/sda4 是我們新切出來的空間

使用 lvs 指令查詢 VG(Vol Group)

lvs

可以看到 VG 名稱為 centos

使用 pvs 指令查詢 VG(Vol Group)對應的 PV(Physical Volume)

pvs

使用 pvcreate 建立 PV

pvcreate /dev/sda4

使用 vgextend 將新增的 PV 加入 VG 中

vgextend centos /dev/sda4

使用 pvscan 確認 pv 都被使用

pvscan

這邊可以看到目前還有剩餘空間 2.00G

使用 lvextend 將 2.00G 加入檔案系統(如果跳出空間不足,可以改小一點)

lvextend -L +2.00G /dev/mapper/centos-root

使用 resize2fs or xfs_growfs 調整 filesystem 的容量

CentOS 6.x
resize2fs /dev/mapper/centos-root(檔案系統名稱,可於 df -h 中查詢)

CentOS 7.x
xfs_growfs /dev/mapper/centos-root(檔案系統名稱,可於 df -h 中查詢)

最後使用 df -h 確認空間擴充完成了

df -h

可以看到『 / 』可用空間增加為 49 G了喔

參考資料:

在 VM 中增加 CentOS 6.5 的硬碟大小

http://blog.xuite.net/towns/hc/76469629-Linux+LVM%E7%AE%A1%E7%90%86+–+%E6%93%B4%E5%A4%A7%E8%88%87%E7%B8%AE%E5%B0%8FLV%E7%A9%BA%E9%96%93

加速 Magento – 讓 NGINX 支援 HTTP/2 與 ALPN

有鑑於支援 HTTP/2 後,網站連線速度加快不少(可參考 https://www.httpvshttps.com/

所以著手升級現有的系統加速 Magento 運行的速度

升級 OpenSSL 至 1.0.2+

ALPN 需要 OpenSSL 1.0.2 以上才支援,參照 CentOS 更新 OpenSSL 到最新版 1.0.2j or CentOS 更新 OpenSSL 到最新版 1.1.0 更新到最新版

下載並手動編譯 NGINX

可先用 YUM 將 NGINX 更新至最新版

su
yum -y update

再下載對應的 NGINX 來編譯,這樣子比較不會有問題

接下來檢查我們的 NGINX 版本與『編譯參數』

[root@www nginx-1.12.0]# nginx -V
nginx version: nginx/1.12.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

可以看出 NGINX 版本為 1.12.0,編譯的 OpenSSL 版本為 1.0.1e

最後方的 configure arguments 就是編譯的參數,重新編譯需要在最後加上『–with-openssl=/usr/src/openssl-1.1.0f』

讓 NGINX 將新版 OpenSSL 編譯進去

yum -y install libxslt-devel gd-devel perl-devel perl-ExtUtils-Embed GeoIP GeoIP-devel GeoIP-data
cd /root
wget http://nginx.org/download/nginx-1.12.0.tar.gz
tar zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --with-openssl=/usr/src/openssl-1.1.0f
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-openssl=/usr/local/openssl-1.0.2j/ --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic'
make
make install

編輯 NGINX conf 檔

於 /etc/nginx/conf.d/xxxx.conf 新增 http2 即可

server {
 listen 443 ssl http2;

檢查 NGINX 是否編譯成功

[root@www nginx-1.12.0]# nginx -V
nginx version: nginx/1.12.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
built with OpenSSL 1.1.0f 25 May 2017
TLS SNI support enabled

重新啟動後才會正式啟用 ALPN 的功能

service nginx restart

可來此網站測試是否成功

https://tools.keycdn.com/http2-test

參考資料:

本博客 Nginx 配置之完整篇

How to get already installed NGINX to use OpenSSL 1.0.2 for ALPN?

NGINX 下載頁面

CentOS 更新 OpenSSL 到最新版 1.0.2j

CentOS YUM 套件庫中的 OpenSSL 版本只到 1.0.1e

但 NGINX 有些功能需要升級到 1.0.2 才能支援

依照下方流程即可順利更新

$ wget https://www.openssl.org/source/openssl-1.0.2-latest.tar.gz
$ tar zxvf openssl-1.0.2-latest.tar.gz -C /usr/local/
$ cd /usr/local/openssl-1.0.2*
$ ./config
$ make depend
$ make
$ make test
$ make install
$ mv /usr/bin/openssl /usr/bin/openssl_1.0.1e
$ ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
$ openssl version
OpenSSL 1.0.2h  3 May 2016

用 Let’s Encrypt 為 Magento 安裝免費的 SSL 憑證 / CENTOS 7

==================== 更新至新版後,無法正常 renew,請改用 Dehydrated 來處理 ====================

 

Let’s Encrypt 是各大廠為了提升網路安全性而共同合作推出免費提供憑證的機構(CA), 以下是在 CentOS 7 將 Let’s encrypt 配置到 NGINX 的方法

先安裝 git、 EPEL repo 與 Let’s encrypt 所需套件

su
yum install -y git epel-release gcc libffi-devel python-devel openssl-devel

下載 Let’s encrypt:

cd /root
git clone https://github.com/letsencrypt/letsencrypt

系統會將 Let’s Encrypt 的最新版本下載到 /root/letsencrypt

先停用 NGINX 後用 letsencrypt-auto 取得 SSL 憑證檔

cd /root/letsencrypt
./letsencrypt-auto certonly -a standalone -d yourdomain.com

or 

cd /root/letsencrypt
./letsencrypt-auto --config /home/test/configs/[your-domain].conf certonly

mkdir /root/webroot
cd /root/letsencrypt
./letsencrypt-auto certonly -a webroot --webroot-path=/usr/share/nginx/html -d odoo.glamping.tw
./letsencrypt-auto certonly -a webroot --webroot-path=/root/webroot -d odoo.glamping.tw

Let’s encrypt 會將憑證檔案放到 /etc/letsencrypt/live/.

接下來生成 DH Parameter

mkdir /etc/nginx/cert
openssl dhparam 2048 -out /etc/nginx/cert/dhparam.pem
openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048

接著設定 NGINX 的 SSL 設定,加入以下參數

    ssl_certificate      /etc/letsencrypt/live/odoo.glamping.tw/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/odoo.glamping.tw/privkey.pem;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;

    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
    ssl_session_cache shared:SSL:20m;
    ssl_session_timeout 180m;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 8.8.8.8 8.8.4.4;
    add_header Strict-Transport-Security "max-age=31536000 always;

接下來重新啟動 NGINX

service nginx reload

去測試網站跑分,這樣子的設定應該可以直接拿到最高評分 A+ !

最後,由於 Lets Encrypt 憑證有效期限只有 90 天,建議每 60 天自動續約

先建立 renew script:auto-renew.sh

/root/letsencrypt/letsencrypt-auto certonly --webroot --renew-by-default --agree-tos -m cewolf@cewolf.com -w /root/webroot -d gapl.com.tw -d www.gapl.com.tw -d glamp.tw
nginx -s reload

接著設定 CRON 於每兩個月的 20號 凌晨 3 點續約

0 3 20 2,4,6,8,10,12 * root /root/auto-renew.sh

Reload crond

systemctl reload crond.service

大功告成!

目前 nginx reload 並不會換上新的憑證

再找到解決方案前先這樣子跑

systemctl stop crond.service
/root/letsencrypt/letsencrypt-auto renew
/bin/systemctl start nginx.service

 

測試網站:

Qualys SSL Labs SSL Server Test

DigiCert® SSL Installation Diagnostics Tool

SSL Checker

參考資料:

LinuxRHEL / CentOS 7 安裝 Let’s encrypt RHEL / CentOS 7 安裝 Let’s encrypt

Let’s Encrypt 的 SSL 憑證安裝

Configure Magento with SSL

Optimizing HTTPS on Nginx

Guide to Deploying Diffie-Hellman for TLS

用 nginx 建置一個 A+ 等級的 https 網頁伺服器

SSL延遲有多大?

How to Validate a Let’s Encrypt Certificate on a Site Already Active on CloudFlare