我正在尝试在Openshift上部署Grails应用程序。 我正在使用本地构建的war文件部署应用程序。 现在,我使用DataSource.groovy文件中的rhc-app-show命令给出的url作为我的数据库配置。 每当我尝试使用Openshift的环境变量(例如$ OPENSHIFT_MYSQL_DB_HOST)时,它都会崩溃。关于如何在配置文件中使用它们的任何想法或指示?
感谢。
答案 0 :(得分:5)
我没有使用过OpenShift,但Google引导我访问显示这些环境变量的FAQ:
OPENSHIFT_MYSQL_DB_HOST
OPENSHIFT_MYSQL_DB_PASSWORD
OPENSHIFT_MYSQL_DB_USERNAME
OPENSHIFT_MYSQL_DB_URL
OPENSHIFT_MYSQL_DB_PORT
所以看起来这样可行:
production {
dataSource {
driverClassName = 'com.mysql.jdbc.Driver'
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
String host = System.getenv('OPENSHIFT_MYSQL_DB_HOST')
String port = System.getenv('OPENSHIFT_MYSQL_DB_PORT')
String dbName = System.getenv('OPENSHIFT_APP_NAME')
url = "jdbc:mysql://$host:$port/$dbName"
username = System.getenv('OPENSHIFT_MYSQL_DB_USERNAME')
password = System.getenv('OPENSHIFT_MYSQL_DB_PASSWORD')
properties {
...
}
}
}
缺少的位是数据库名称 - 是否有可用的东西?我不确定OPENSHIFT_MYSQL_DB_URL
的格式,但看起来您可能只能使用url = "jdbc:${System.getenv('OPENSHIFT_MYSQL_DB_URL')}"
答案 1 :(得分:0)
production {
dataSource {
dbCreate = "update"
driverClassName = "org.postgresql.Driver"
dialect = org.hibernate.dialect.PostgreSQLDialect
uri = new URI(System.getenv('OPENSHIFT_POSTGRESQL_DB_URL'))
url = "jdbc:postgresql://"+uri.host+uri.path+"/"+System.getenv('OPENSHIFT_APP_NAME')
username = System.getenv('OPENSHIFT_POSTGRESQL_DB_USERNAME')
password = System.getenv('OPENSHIFT_POSTGRESQL_DB_PASSWORD')
}
production {
dataSource {
dbCreate = "update"
driverClassName = "org.postgresql.Driver"
dialect = org.hibernate.dialect.PostgreSQLDialect
uri = new URI(System.getenv('OPENSHIFT_POSTGRESQL_DB_URL').toString())
appname = System.getenv('OPENSHIFT_APP_NAME').toString()
url = "jdbc:postgresql://"+uri.host.toString()+uri.path.toString()+"/"+appname
username = System.getenv('OPENSHIFT_POSTGRESQL_DB_USERNAME').toString()
password = System.getenv('OPENSHIFT_POSTGRESQL_DB_PASSWORD').toString()
}
答案 2 :(得分:0)
在Grails 3.0.11中,文件application.yml
System.getenv不起作用,所以我不得不在mysql中手动配置数据库的url连接....使用文档https://developers.openshift.com/en/managing-port-forwarding.html的命令
dataSource:
dbCreate: update
url : jdbc:mysql://thisIsTheUrlGetWithPort-ForwardCommandAndThePort:48381/server?verifyServerCertificate=false&autoReconnect=true&useSSL=false&requireSSL=false
driverClassName: com.mysql.jdbc.Driver
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
username : admin9CzsS #this is a username example
password : RR7y9uKw3t #this is a password example
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: ConnectionState
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED