Solaris 10下PostgreSQL的安装

08:19下午 一月 21, 2008 in category Solaris by 快快播谷

  Solaris 10上已经安装有PostgreSQL,只是还没有初始化,现在让我们看看如何将其启动起来。PostgreSQL服务是使用SMF管理的,让我们看看PostgreSQL的当前状态:

bash-3.00# svcs -a | grep sql
disabled       16:38:04 svc:/application/database/postgresql:version_81
disabled       19:33:19 svc:/application/database/postgresql:version_82

  我们现在启动PostgreSQL8.2,输入如下命令:

bash-3.00#svcadm enable svc:/application/database/postgresql:version_82

  在查看一下当前的状态:

bash-3.00# svcs -a | grep sql
disabled       16:38:04 svc:/application/database/postgresql:version_81
maintenance       19:33:19 svc:/application/database/postgresql:version_82

  PostgreSQL8.2处于维护状态(maintenance),没有启动起来。让我们来看看没有启动的原因:

bash-3.00#svcs -x

svc:/application/print/server:default (LP print server)
 状态:disabled 自 2008年01月21日 星期一 16时37分59秒 开始
原因:管理员已将其禁用。
   参见:http://sun.com/msg/SMF-8000-05
   参见:lpsched(1M)
影响:2 相关服务未运行。  (使用 -v 列出)。

svc:/application/database/postgresql:version_82 (PostgreSQL RDBMS)
 状态:maintenance 自 2008年01月21日 星期一 16时38分32秒 开始
原因:启动方法 退出,代码为 $SMF_EXIT_ERR_CONFIG。
   参见:http://sun.com/msg/SMF-8000-KS
   参见:postgres_82(1)
   参见:/var/svc/log/application-database-postgresql:version_82.log
影响:此项服务未运行。

 

  提示我们查看 /var/svc/log/application-database-postgresql:version_82.log文件,看看这个文件中内容:

 bash-3.00#cat  /var/svc/log/application-database-postgresql:version_82.log

[ Nov 28 15:58:35 Disabled. ]
[ Nov 28 15:58:36 Rereading configuration. ]
[ 11月 28 16:39:03 Rereading configuration. ]
[  1月 21 16:26:30 Enabled. ]
[  1月 21 16:26:30 Executing start method ("/lib/svc/method/postgresql start") ]
postgresql/data directory /var/postgres/8.2/data is not a valid PostgreSQL data directory
postgresql/data directory /var/postgres/8.2/data may not have been initialized
To initialize the postgresql/data directory /var/postgres/8.2/data run 'initdb /var/postgres/8.2/data'

[  1月 21 16:26:30 Method "start" exited with status 96 ]
[  1月 21 16:38:31 Executing start method ("/lib/svc/method/postgresql start") ]
postgresql/data directory /var/postgres/8.2/data is not a valid PostgreSQL data directory
postgresql/data directory /var/postgres/8.2/data may not have been initialized
To initialize the postgresql/data directory /var/postgres/8.2/data run 'initdb /var/postgres/8.2/data'
[  1月 21 16:38:32 Method "start" exited with status 96 ]

  

 

  这回知道原因了,我们没有初始化数据库。PostgreSQL安装在/usr/postgres/8.2/下,我们进入这个目录,我们会看到initdb这个用来初始化数据库的可执行文件,这个命令必须使用postgres这个账号来运行,让我们切换到postgres账号,来执行这个命令:

bash-3.00#su postgres

$ initdb /var/postgres/8.2/data

  如果不出什么意外,安装完毕后我们就可以使用 svcadm enable svc:/application/database/postgresql:version_82 命令来启动PostgreSQL8.2。启动之后我们可以使用默认的数据库帐号postgres登录,默认的密码是空的。

  PostgreSQL对安全限制的很严,如果你要从其它计算机登录,必须修改配置文件。 配置文件在/var/postgres/8.2/data目录下,修改postgres.conf,添加listen_addresses = '*',表示允许从所有计算机登录,还要修改pg_hba.conf,添加一行host    all         all         192.168.1.0/24        trust ,注意这个ip要是你所在机器的网络范围,由于我对PostgreSQL不是很熟,具体有关PostgreSQL的配置自己研究吧,希望对你有所帮助!

  补充:下面我机器上的用于定义PostgreSQL的SMF服务的postgresql.xml文件,在/var/svc/manifest/application/database目录下。内容如下:

<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
 Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
 Use is subject to license terms.

 ident    "@(#)postgresql.xml    1.1    07/01/31 SMI"

        NOTE:  This service manifest is not editable; its contents will
        be overwritten by package or patch operations, including
        operating system upgrade.  Make customizations in a different
        file.
-->

<service_bundle type='manifest' name='postgresql'>

<service
        name='application/database/postgresql'
        type='service'
        version='1'>

    <!--
       Wait for network interfaces to be initialized.
    -->
        <dependency
                name='network'
                grouping='require_all'
                restart_on='none'
                type='service'>
                <service_fmri value='svc:/milestone/network:default' />
        </dependency>

    <!--
       Wait for all local filesystems to be mounted.
    -->
        <dependency
                name='filesystem-local'
                grouping='require_all'
                restart_on='none'
                type='service'>
                <service_fmri value='svc:/system/filesystem/local:default' />
        </dependency>

        <exec_method
                type='method'
                name='start'
                exec='/lib/svc/method/postgresql start'
                timeout_seconds='60' />

        <exec_method
                type='method'
                name='stop'
                exec='/lib/svc/method/postgresql stop'
                timeout_seconds='60' />

        <exec_method
                type='method'
                name='refresh'
                exec='/lib/svc/method/postgresql refresh'
                timeout_seconds='60' />

        <!--
          Both action_authorization and value_authorization are needed
          to allow the framework general/enabled property to be changed
          when performing action (enable, disable, etc) on the service.
        -->
        <property_group name='general' type='framework'>
        <propval name='value_authorization' type='astring'
            value='solaris.smf.value.postgres' />
        <propval name='action_authorization' type='astring'
            value='solaris.smf.manage.postgres' />
        </property_group>

        <!--
          We define two instances of PostgreSQL as examples (8.1 & 8.2).
        -->

        <instance name='version_81' enabled='false'>

            <method_context>
                    <method_credential user='postgres' group='postgres' />
            </method_context>

        <!--
           Make sure the data configurable property points to the
           appropriate database directory.
        -->
            <property_group name='postgresql' type='application'>
                    <propval name='bin' type='astring'
                           value='/usr/bin' />
                    <propval name='data' type='astring'
                           value='/var/lib/pgsql/data' />
                    <propval name='log' type='astring'
               value='server.log' />
            <propval name='value_authorization' type='astring'
               value='solaris.smf.value.postgres' />
            </property_group>

        </instance>

        <instance name='version_82' enabled='false'>

            <method_context>
                    <method_credential user='postgres' group='postgres' />
            </method_context>

        <!--
           Make sure the data configurable property points to the
           appropriate database directory and port number in
           postgresql.conf is different than the first instance.
        -->
            <property_group name='postgresql' type='application'>
                    <propval name='bin' type='astring'
                           value='/usr/postgres/8.2/bin' />
                    <propval name='data' type='astring'
                           value='/var/postgres/8.2/data' />
                    <propval name='log' type='astring'
               value='server.log' />
            <propval name='value_authorization' type='astring'
               value='solaris.smf.value.postgres' />
            </property_group>

        </instance>

        <stability value='Evolving' />

        <template>
                <common_name>
                        <loctext xml:lang='C'>
                                PostgreSQL RDBMS
                        </loctext>
                </common_name>
                <documentation>
                        <manpage title='postgres_82' section='1' />
                        <doc_link name='postgresql.org'
                                uri='http://postgresql.org' />
                </documentation>
        </template>

</service>

</service_bundle>


评论[0]

评论:

发表一条评论:
  • HTML语法: 启用