Debain11下安装Ofbiz18.12

1 篇文章 0 订阅

1.安装jdk

sudo apt install openjdk-11-jdk

sudo update-alternatives --config java

1.下载Ofbiz

地址: The Apache OFBiz® Project - Downloadsicon-default.png?t=N7T8https://ofbiz.apache.org/download.html#

2.创建ofbiz用户

sudo adduser ofbiz 

切换用户到ofbiz

su - ofbiz

cp /*****/apache-ofbiz-18.12.05.zip ./

3.解压ofbiz

unzip apache-ofbiz-18.12.05.zip

4.重命名目录

mv apache-ofbiz-18.12.05 ofbiz-18.12.05

cd ofbiz-18.12.05

5. 初始化gradle环境

gradle/init-gradle-wrapper.sh

6.使用postgresql数据库

配置外部数据库之前

在配置外部数据库之前,必须确保以下几个步骤:

  1. 在更改 OFBiz 实体引擎配置以使用远程数据源之前,您必须首先创建远程数据库。远程数据库必须存在,在postgres中创建3个数据库(即ofbiz、ofbizolap、ofbiztenant)。
  2. 为远程数据库添加用户/所有者。OFBiz 将以该用户身份访问数据库。确保用户拥有创建和删除数据库表所需的所有权限。
    postgresql14 注意密码加密方式有变化。
    ALTER ROLE ofbiz PASSWORD 'ofbiz';
  3. 将用户/所有者密码(如果需要或必要)添加到远程数据库。
  4. 确保数据库正在侦听远程连接的 IP 端口已打开并且没有任何防火墙障碍(例如,默认情况下,PostgreSQL 侦听端口 5432 上的连接)。
  5. 编辑这个文件:framework/entity/config/entityengine.xml。

    步骤 i) Ofbiz 使用 Derby 作为默认数据库。更改默认数据源名称 postgress。
    Ex-     
        <delegator name="default" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" Distributed-cache-clear-enabled="false"> 
        <group -map group-name="org.apache.ofbiz" datasource-name="localpostgres"/> 
        <group-map group-name="org.apache.ofbiz.olap" datasource-name="localpostgresolap"/> 
        <group -map group-name="org.apache.ofbiz.tenant" datasource-name="localpostgrestenant"/> 
        </delegator>      
        

    步骤 ii) Ofbiz 已经为 postgress 定义了 3 个连接器:localpostgres、localpostolap 和 localposttenant。在 entityengine.xml 中搜索这 3 个连接器名称。
    步骤 iii) 为您的数据库设置编辑它们。
    Ex- 
    jdbc-uri="jdbc:postgresql://127.0.0.1:5432/ofbiz" <--这是数据库名称--> 
        jdbc-username="ofbiz" <--这是用户名--> 
        jdbc-password ="ofbiz" <--这是密码-->

6.创建ofbiz插件

./gradlew createPlugin -PpluginId=PostgressDemo

或修改添加 在./build.gradle文件中

runtime 'org.apache.derby:derby:10.14.2.0'
runtime 'org.postgresql:postgresql:42.4.0'

7. 并在PostgresDemo插件中添加postgres的gradle依赖。目录在./plugins/PostgressDemo的./plugins/PostgressDemo/build.gradle 文件

    dependencies {    
          pluginLibsRuntime 'org.postgresql:postgresql:42.4.0' 
    }
8. 之后启动加载默认数据的命令。

    ./gradlew loadAll

查看是由于gradle plugin版本较高,需将build.gradle配置文件中 compile 替换为 implementation 后重载项目即可解决

The authentication type 10 is not supported. Check that you have configured the sys_hba.conf file 

postgresql驱动版本过低,

删除

framework/entity/lib下的驱动


You can get more information about available Gradle possibilities using "gradlew tasks" (Windows) or "./gradlew tasks" (Linux/Unix/OSX)

$ ./gradlew cleanAll loadAll
If the build succeed, you can now start OFBiz instance:

$ ./gradlew ofbiz
You can also run OFBiz as background service:

$ ./gradlew ofbizBackground
Finally, to stop OFBiz after using it:

$ ./gradlew "ofbiz --shutdown"
 

到这里项目的信息数据都配置好了 gradlew ofbiz 运行可以正常启动了       

Open a browser and go to
https://localhost:8443/ecommerce or https://localhost:8443/ecomseo for the ecommerce application or
https://localhost:8443/webtools for the WebTools application or
https://localhost:8443/catalog for the Catalog Manager application.


The default administrative account is username: "admin", password: "ofbiz".

Changing the OFBiz service port

Since in a demo scenario OFBiz might be installed on a host where Teamcenter is also installed, the demo assumes a port for OFBiz that is different from the default. To change the OFBiz port to e.g. 8081:

Change port.http from 8080 to 8081 in framework\webapp\config\url.properties.

Change all ports from 8080 to 8081 in framework\service\config\serviceengine.xml and in framework\catalina\ofbiz-component.xml

-----------------------------------------------------------------------------------------------

systemd service

Most Linux systems/distributions are now run under systemd init system. It would be nice if OFBiz can be run automatically when system boots and stopped when system shuts down, without needing to login to ofbiz user and executing gradlew manually. This is where systemd service comes in.

Create /etc/systemd/system/ofbiz.service with following:

# OFBiz service

[Unit]
Description=OFBiz Service

[Service]
Type=simple

# environment variables
Environment="JAVA_HOME=/path/to/jdk8"
Environment="PATH=/path/to/jdk8/bin:/bin:/sbin:/usr/bin:/usr/sbin"

User=ofbiz
WorkingDirectory=/opt/ofbiz

# start and stop executables
# note that systemd requires specifying full/absolute path to executables
ExecStart=/opt/ofbiz/gradlew ofbiz
ExecStop=/opt/ofbiz/gradlew "ofbiz --shutdown"

[Install]
WantedBy=multi-user.target

Reload systemd daemon, then enable and start the service:

# systemctl daemon-reload
# systemctl enable ofbiz.service --now

The log, which is displayed to stdout when running gradlew manually, is now on systemd journal, which can be viewed by:

# journalctl -u ofbiz.service

Serving OFBiz with NGINX as Reverse Proxy

Continuing from previous tutorial, Installing OFBiz, we will configuring NGINX to serve OFBiz instance by means of reverse proxy (that is, OFBiz will be put behind NGINX, and any requests to OFBiz instance will be passed from NGINX).

Prerequisites

  • You need to have OFBiz installed on your system. See Installing OFBiz for details.
  • A working NGINX setup. We assumed that you installed NGINX from the upstream's repository. You can consult online tutorials that discuss about NGINX configurations, but here we will only explain the ones that relevant for this tutorial.

Configuring OFBiz

From previous tutorial in this gist, OFBiz is installed to /opt/ofbiz. Change directory to it first (replace if you installed to different one):

$ cd /opt/ofbiz

By default, OFBiz use internal Tomcat server which is listening on any addresses (0.0.0.0). Because NGINX will sit in front of OFBiz, set listen address for Tomcat to only localhost.

Edit framework/base/ofbiz-component.xml. Set host property for JNDI naming server to 127.0.0.1, thus this name server only acts on localhost:

...
    <!-- load the naming (JNDI) server -->
    ...
        <property name="host" value="127.0.0.1"/>
    ...
...

When clients visit links on OFBiz, the permalinks generated points to the internal port (https://localhost:8443). In order to be served by NGINX, such permalinks must be rewritten without port (https://localhost).

Set serving port and domain names on framework/webapp/config/url.properties. Replace domain.tld with domain to be used to serve OFBiz:

...
port.https=443
force.https.host=domain.tld
...
port.http=80
force.http.host=domain.tld
...

Basic (All-Pass) NGINX Configuration

Now OFBiz have been configured for reverse-proxy support, we can move to NGINX setup. In this setup, all requests to OFBiz are proxy-passed from NGINX.

Create /etc/nginx/conf.d/ofbiz.conf with following:

# NGINX Reverse Proxy Configuration for OFBiz

# http
server {
    listen 80;
    listen [::]:80;

    server_name domain.tld;

    return 301 https://domain.tld$request_uri;
}

# https
server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name domain.tld;

    ssl_certificate     /path/to/your/site/certificate;
    ssl_certificate_key /path/to/your/site/certificate-private-key;

    location / {
        proxy_pass https://127.0.0.1:8443;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded_For $proxy_add_x_forwarded_for;
    }
}

Serving Static Assets

In above setup, any requests (even static assets) are passed to OFBiz, which use embedded Tomcat HTTP server. However, this setup is somewhat heavy-weight as Tomcat does all actual request servings that proxied from NGINX. In this section, NGINX will be configured to directly serve static assets instead, and only pass to OFBiz if requested assets aren't found.

Again, edit /etc/nginx/conf.d/ofbiz.conf as following.

First, change location block from previous setup (location /) into named location block (location @ofbiz). This block will be referred when using try_files later as fallback location:

...
    location @ofbiz {
        proxy_pass https://127.0.0.1:8443;
        ...
    }
...

Add location block for static assets:

...
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        root /opt/ofbiz/framework/images/webapp/images;
        try_files $uri $uri/ @ofbiz;
        expires 3d;
    }
...

Explanation: try_files are used to serve static assets, with @ofbiz as fallback location. In order for this to work, either set root directory globally (on server block context), or on location block (which we use here) first. Since static assets on OFBiz are on images webapp, the directory would be /opt/ofbiz/framework/images/webapp/images. Arguments to try_files specify that NGINX will look for requested assets on root directory first, before falling back to @ofbiz if not found. Expiry date for 3 days expires 3d; is also set, so that browsers can use their cached assets before re-requesting them for 3 days.

Finally, add location block that match root directory and files other than static assets:

...
    location / {
        root /opt/ofbiz/framework/images/webapp/images;
        try_files $uri $uri/ @ofbiz;
    }
...

Explanation: root directory and try_files arguments are same as for static assets above, without expires directive. You can put this block below static assets location block, so that location blocks for most specific URL are come first (in this case, location block for static assets is above location block for root).

Reload Server

After configuring NGINX as above, test for syntax errors:

# nginx -t

If no errors are found on your configuration, reload NGINX:

# nginx -s reload

Conclusion

Now you have NGINX serve your OFBiz Instance, and statics assets are served by NGINX, thus taking advantage of fast static content serving that NGINX offers.

This tutorial only cover basic working configurations that can be applied on almost any setups. Furthermore, when experimenting your configurations, always test for any performance bottlenecks and security holes. Whenever possible, prefer simplicity instead of fragile and untested configurations.

Full NGINX Configuration

# NGINX Reverse Proxy Configuration for OFBiz

# http
server {
    listen 80;
    listen [::]:80;

    server_name domain.tld;

    return 301 https://domain.tld$request_uri;
}

# https
server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name domain.tld;

    ssl_certificate     /path/to/your/site/certificate;
    ssl_certificate_key /path/to/your/site/certificate-private-key;

    location @ofbiz {
        proxy_pass https://127.0.0.1:8443;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded_For $proxy_add_x_forwarded_for;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        root /opt/ofbiz/framework/images/webapp/images;
        try_files $uri $uri/ @ofbiz;
        expires 3d;
    }

    location / {
        root /opt/ofbiz/framework/images/webapp/images;
        try_files $uri $uri/ @ofbiz;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值