5

他のホストからのインデックス作成機能の実行をテストしたかったのは、この機能がプログラムへの Hadoop で完全に正しく実行されていないためです。しかし、以下で説明するように、他のホストからデータベースへの接続に問題がありました。何が問題なのかわかりません。

私はJavaプログラムに従って書いた

import java.io.*;
import java.util.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.*;

public class Sample {
    public static void main (String[] args) throws IOException  {
                    int CountComputers;
            FileInputStream fstream = new FileInputStream(
                    "/export/hadoop-1.0.1/bin/countcomputers.txt");
            BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
            String result=br.readLine();
            CountComputers=Integer.parseInt(result);
            input.close();
            fstream.close();
            Connection con = null;
            Statement st = null;
                ResultSet rs = null;    
               String url = "jdbc:postgresql://192.168.1.8:5432/NexentaSearch";
                String user = "postgres";
                String password = "valter89";
            //Class.forName("org.postgresql.Driver");
            ArrayList<String> paths = new ArrayList<String>();
            try
            {
                Class.forName("org.postgresql.Driver");
                con = DriverManager.getConnection(url, user, password);
                        st = con.createStatement();
                        rs = st.executeQuery("select path from tasks order by id");
                while (rs.next()) { paths.add(rs.getString(1)); };
                PrintWriter zzz = null;
                    try
                    {
                            zzz = new PrintWriter(new FileOutputStream("/export/hadoop-1.0.1/bin/readwaysfromdatabase.txt"));
                    }
                    catch(FileNotFoundException e)
                    {
                            System.out.println("Error");
                            System.exit(0);
                    }
                    for (int i=0; i<paths.size(); i++)
                {
                    zzz.println("paths[i]=" + paths.get(i) + "\n");
                    }
                    zzz.close();

            }
            catch (SQLException e) 
            {
                System.out.println("Connection Failed! Check output console");
                e.printStackTrace();
            }
            catch (ClassNotFoundException e)
            {
                e.printStackTrace();
            }
        }
}

コマンドでSample.jarを起動しました

./java -jar -Djava.library.path=/opt/jdk1.7.0_06/lib /Samplejavaprogram/Sample.jar

その結果、次のメッセージを受け取りました

Connection Failed! Check output console
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:136)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
    at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
    at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
    at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
    at org.postgresql.Driver.makeConnection(Driver.java:393)
    at org.postgresql.Driver.connect(Driver.java:267)
    at java.sql.DriverManager.getConnection(DriverManager.java:579)
    at java.sql.DriverManager.getConnection(DriverManager.java:221)
    at Sample.main(Sample.java:33)
Caused by: java.net.ConnectException: Connection timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at java.net.Socket.connect(Socket.java:528)
    at java.net.Socket.<init>(Socket.java:425)
    at java.net.Socket.<init>(Socket.java:208)
    at org.postgresql.core.PGStream.<init>(PGStream.java:62)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:76)
    ... 9 more

アドレス 192.168.1.10 のホストからファイルを起動しました。エラーを解消するのに役立ちます。エラーの原因は?何を作る必要がありますか?

netstat -a


UDP: IPv4
   Local Address        Remote Address      State
-------------------- -------------------- ----------
      *.bootpc                            Idle
      *.dhcpv6-client                      Idle
      *.*                                 Unbound
      *.*                                 Unbound
      *.sunrpc                            Idle
      *.*                                 Unbound
      *.38606                             Idle
      *.sunrpc                            Idle
      *.*                                 Unbound
      *.40712                             Idle
      *.*                                 Unbound
      *.*                                 Unbound
      *.*                                 Unbound
      *.54122                             Idle
      *.41742                             Idle
      *.*                                 Unbound
      *.lockd                             Idle
      *.lockd                             Idle
      *.59670                             Idle
      *.42840                             Idle
      *.43065                             Idle
      *.39546                             Idle
      *.34243                             Idle
      *.35383                             Idle
      *.40746                             Idle
      *.40832                             Idle
192.168.1.2.bootpc                        Idle
      *.mdns                              Idle
      *.mdns                              Idle
192.168.1.2.ntp                           Idle
      *.snmpd                             Idle
      *.ntp                               Idle
      *.ntp                               Idle
localhost.localdomain.ntp                      Idle
myhost2.ntp                               Idle

UDP: IPv6
   Local Address                     Remote Address                   State      If
--------------------------------- --------------------------------- ---------- -----
      *.dhcpv6-client                                               Idle       
      *.*                                                           Unbound    
localhost.44111                   localhost.44111                   Connected  
      *.sunrpc                                                      Idle       
      *.*                                                           Unbound    
      *.38606                                                       Idle       
      *.54122                                                       Idle       
      *.*                                                           Unbound    
      *.lockd                                                       Idle       
      *.42840                                                       Idle       
      *.39546                                                       Idle       
      *.35383                                                       Idle       
      *.40832                                                       Idle       
      *.ntp                                                         Idle       
localhost.ntp                                                       Idle       

TCP: IPv4
   Local Address        Remote Address    Swind Send-Q Rwind Recv-Q    State
-------------------- -------------------- ----- ------ ----- ------ -----------
localhost.localdomain.4999       *.*                0      0 128000      0 LISTEN
      *.2001               *.*                0      0 128000      0 LISTEN
      *.2002               *.*                0      0 128000      0 LISTEN
      *.2003               *.*                0      0 128000      0 LISTEN
      *.16049              *.*                0      0 128000      0 LISTEN
      *.5432               *.*                0      0 128000      0 LISTEN
      *.sunrpc             *.*                0      0 128000      0 LISTEN
      *.*                  *.*                0      0 128000      0 IDLE
      *.sunrpc             *.*                0      0 128000      0 LISTEN
      *.*                  *.*                0      0 128000      0 IDLE
      *.54002              *.*                0      0 128000      0 LISTEN
      *.49023              *.*                0      0 128000      0 LISTEN
      *.55493              *.*                0      0 1049200      0 LISTEN
      *.46659              *.*                0      0 1048952      0 LISTEN
      *.lockd              *.*                0      0 1049200      0 LISTEN
      *.lockd              *.*                0      0 1048952      0 LISTEN
      *.45361              *.*                0      0 128000      0 LISTEN
localhost.localdomain.36084 localhost.localdomain.2001 65440      0 139264      0 ESTABLISHED
      *.53943              *.*                0      0 128000      0 LISTEN
localhost.localdomain.2001 localhost.localdomain.36084 139060      0 130880      0 ESTABLISHED
localhost.localdomain.44644 localhost.localdomain.2012 34765      0 139264      0 ESTABLISHED
localhost.localdomain.2012 localhost.localdomain.44644 139060      0 139060      0 ESTABLISHED
      *.36068              *.*                0      0 128000      0 LISTEN
      *.57055              *.*                0      0 128000      0 LISTEN
      *.login              *.*                0      0 128000      0 LISTEN
      *.finger             *.*                0      0 128000      0 LISTEN
      *.telnet             *.*                0      0 128000      0 LISTEN
      *.shell              *.*                0      0 128000      0 LISTEN
      *.40524              *.*                0      0 128000      0 LISTEN
      *.60838              *.*                0      0 128000      0 LISTEN
      *.47648              *.*                0      0 128000      0 LISTEN
      *.56894              *.*                0      0 128000      0 LISTEN
      *.48461              *.*                0      0 128000      0 LISTEN
      *.53672              *.*                0      0 128000      0 LISTEN
      *.42108              *.*                0      0 128000      0 LISTEN
      *.63720              *.*                0      0 128000      0 LISTEN
      *.ssh                *.*                0      0 128000      0 LISTEN
localhost.localdomain.smtp       *.*                0      0 128000      0 LISTEN
localhost.localdomain.submission       *.*                0      0 128000      0 LISTEN
      *.80                 *.*                0      0 128000      0 LISTEN
      *.*                  *.*                0      0 128000      0 IDLE
      *.2000               *.*                0      0 128000      0 LISTEN
      *.*                  *.*                0      0 128000      0 IDLE
      *.443                *.*                0      0 128000      0 LISTEN
      *.*                  *.*                0      0 128000      0 IDLE
localhost.localdomain.38137 localhost.localdomain.2003 65440      0 139264      0 ESTABLISHED
localhost.localdomain.2003 localhost.localdomain.38137 139060      0 130880      0 ESTABLISHED
localhost.localdomain.63918 localhost.localdomain.2001 65440      0 139264      0 ESTABLISHED
localhost.localdomain.2001 localhost.localdomain.63918 139060      0 130880      0 ESTABLISHED
myhost2.ssh          192.168.1.4.7431     65548      0 128480      0 ESTABLISHED
localhost.localdomain.34057 localhost.localdomain.2001 65440      0 139264      0 ESTABLISHED
localhost.localdomain.2001 localhost.localdomain.34057 139060      0 130880      0 ESTABLISHED
localhost.localdomain.37015 localhost.localdomain.2001 65440      0 139264      0 ESTABLISHED
localhost.localdomain.2001 localhost.localdomain.37015 139060      0 130880      0 ESTABLISHED
      *.2011               *.*                0      0 131072      0 LISTEN
localhost.localdomain.36598 localhost.localdomain.2002 65440      0 139264      0 ESTABLISHED
localhost.localdomain.2002 localhost.localdomain.36598 139060      0 130880      0 ESTABLISHED
localhost.localdomain.4000       *.*                0      0 131072      0 LISTEN
localhost.localdomain.53161 localhost.localdomain.2011 34765      0 139264      0 ESTABLISHED
localhost.localdomain.2011 localhost.localdomain.53161 139060      0 139060      0 ESTABLISHED
localhost.localdomain.43878 localhost.localdomain.2001 65440      0 139264      0 ESTABLISHED
localhost.localdomain.2001 localhost.localdomain.43878 139060      0 130880      0 ESTABLISHED
localhost.localdomain.50976 localhost.localdomain.2001 65440      0 139264      0 ESTABLISHED
localhost.localdomain.2001 localhost.localdomain.50976 139060      0 130880      0 ESTABLISHED
localhost.localdomain.62633 localhost.localdomain.2012 34765      0 139264      0 ESTABLISHED
localhost.localdomain.2012 localhost.localdomain.62633 139060      0 139060      0 ESTABLISHED
      *.2012               *.*                0      0 131072      0 LISTEN
localhost.localdomain.34418 localhost.localdomain.2012 34765      0 139264      0 ESTABLISHED
localhost.localdomain.2012 localhost.localdomain.34418 139060      0 139060      0 ESTABLISHED
localhost.localdomain.34356 localhost.localdomain.2011 34765      0 139264      0 ESTABLISHED
localhost.localdomain.2011 localhost.localdomain.34356 139060      0 139060      0 ESTABLISHED
localhost.localdomain.62884 localhost.localdomain.2001 65440      0 139264      0 ESTABLISHED
localhost.localdomain.2001 localhost.localdomain.62884 139060      0 130880      0 ESTABLISHED
localhost.localdomain.52603 localhost.localdomain.2011 34765      0 139264      0 ESTABLISHED
localhost.localdomain.2011 localhost.localdomain.52603 139060      0 139060      0 ESTABLISHED
localhost.localdomain.35345 localhost.localdomain.2001 65440      0 139264      0 ESTABLISHED
localhost.localdomain.2001 localhost.localdomain.35345 139060      0 130880      0 ESTABLISHED
localhost.localdomain.49022 localhost.localdomain.2001 130880      0 139264      0 TIME_WAIT
localhost.localdomain.42797 localhost.localdomain.2001 130880      0 139264      0 TIME_WAIT
localhost.localdomain.46312 localhost.localdomain.2001 130880      0 139264      0 TIME_WAIT

TCP: IPv6
   Local Address                     Remote Address                 Swind Send-Q Rwind Recv-Q   State      If
--------------------------------- --------------------------------- ----- ------ ----- ------ ----------- -----
      *.5432                            *.*                             0      0 128000      0 LISTEN      
      *.sunrpc                          *.*                             0      0 128000      0 LISTEN      
      *.*                               *.*                             0      0 128000      0 IDLE        
      *.54002                           *.*                             0      0 128000      0 LISTEN      
      *.55493                           *.*                             0      0 1049200      0 LISTEN      
      *.lockd                           *.*                             0      0 1049200      0 LISTEN      
      *.53943                           *.*                             0      0 128000      0 LISTEN      
      *.57055                           *.*                             0      0 128000      0 LISTEN      
      *.login                           *.*                             0      0 128000      0 LISTEN      
      *.finger                          *.*                             0      0 128000      0 LISTEN      
      *.telnet                          *.*                             0      0 128000      0 LISTEN      
      *.shell                           *.*                             0      0 128000      0 LISTEN      
      *.60838                           *.*                             0      0 128000      0 LISTEN      
      *.56894                           *.*                             0      0 128000      0 LISTEN      
      *.53672                           *.*                             0      0 128000      0 LISTEN      
      *.63720                           *.*                             0      0 128000      0 LISTEN      
      *.ssh                             *.*                             0      0 128000      0 LISTEN      
localhost.smtp                          *.*                             0      0 128000      0 LISTEN      
      *.80                              *.*                             0      0 128000      0 LISTEN      
      *.2000                            *.*                             0      0 128000      0 LISTEN      
      *.443                             *.*                             0      0 128000      0 LISTEN      

Active UNIX domain sockets
Address  Type          Vnode     Conn  Local Addr      Remote Addr
ffffff0119f107b8 stream-ord 00000000     00000000                                  
ffffff0119f10b68 stream-ord 00000000     00000000                                  
ffffff0119214050 stream-ord 00000000     00000000                                  
ffffff0119214400 stream-ord 00000000     00000000                                  
ffffff0119214b60 stream-ord 00000000     00000000                                  
ffffff0114119048 stream-ord 00000000     00000000                                  
ffffff01141193f8 stream-ord ffffff011950e580 00000000    /tmp/dbus-3YiNfXlgwn                
ffffff01141197a8 stream-ord ffffff0119217e40 00000000    /tmp/dbus-7BNzAEnmYY                
ffffff0114119b58 stream-ord ffffff0114118e40 00000000    /var/run/mDNSResponder                
ffffff01138b2040 stream-ord 00000000     00000000    /var/run/dbus/system_bus_socket                
ffffff01138b23f0 stream-ord 00000000     ffffff0111d0e780                /var/run/dbus/system_bus_socket 
ffffff01138b27a0 stream-ord 00000000     00000000    /var/run/dbus/system_bus_socket                
ffffff01138b2b50 stream-ord 00000000     ffffff0111d0e780                /var/run/dbus/system_bus_socket 
ffffff0113059038 stream-ord ffffff0113835140 00000000    /var/run/.inetd.uds                
ffffff01130593e8 stream-ord 00000000     ffffff0112c5f880                /var/run/hald/dbus-9g2E5zdff9 
ffffff0113059798 stream-ord 00000000     00000000    /var/run/hald/dbus-9g2E5zdff9                
ffffff0113059b48 dgram      ffffff01130b2e00 00000000    /var/run/in.ndpd_mib                
ffffff011306d030 stream-ord ffffff0112bb5280 00000000    /var/run/in.ndpd_ipadm                
ffffff011306d3e0 stream-ord 00000000     00000000    /var/run/hald/dbus-9g2E5zdff9                
ffffff011306d790 stream-ord 00000000     00000000    /var/run/hald/dbus-9g2E5zdff9                
ffffff011306db40 stream-ord 00000000     ffffff0112c5f880                /var/run/hald/dbus-9g2E5zdff9 
ffffff0112fcb028 stream-ord 00000000     ffffff0112c5f880                /var/run/hald/dbus-9g2E5zdff9 
ffffff0112fcb3d8 stream-ord 00000000     00000000    /var/run/hald/dbus-9g2E5zdff9                
ffffff0112fcb788 stream-ord 00000000     ffffff0112c5f880                /var/run/hald/dbus-9g2E5zdff9 
ffffff0112fcbb38 stream-ord ffffff0112fd4080 00000000    /tmp/.s.PGSQL.5432                
ffffff01122c4020 stream-ord 00000000     00000000    /var/run/hald/dbus-F83hT9CGSX                
ffffff01122c43d0 stream-ord 00000000     ffffff0112c5f280                /var/run/hald/dbus-F83hT9CGSX 
ffffff01122c4780 stream-ord ffffff0112c5f280 00000000    /var/run/hald/dbus-F83hT9CGSX                
ffffff01122c4b30 stream-ord 00000000     00000000                                  
ffffff0112294018 stream-ord 00000000     00000000                                  
ffffff01122943c8 stream-ord ffffff0112c5f880 00000000    /var/run/hald/dbus-9g2E5zdff9                
ffffff0112294778 stream-ord 00000000     00000000                                  
ffffff0112294b28 stream-ord 00000000     00000000                                  
ffffff0112278010 stream-ord ffffff01122c7880 00000000    /tmp/dbus-PuCCfO9I4C                
ffffff01122783c0 stream-ord 00000000     00000000                                  
ffffff0112278770 stream-ord 00000000     00000000                                  
ffffff0112278b20 stream-ord ffffff01122a0b40 00000000    /tmp/dbus-tfcmjjMClq                
ffffff0111d08008 stream-ord 00000000     00000000                                  
ffffff0111d083b8 stream-ord 00000000     00000000                                  
ffffff0111d08768 stream-ord ffffff01121a2b40 00000000    /tmp/dbus-cEAGQX2WDo                
ffffff0111d08b18 stream-ord ffffff0111d0e780 00000000    /var/run/dbus/system_bus_socket                

Postgresql が起動されましたか?

4

2 に答える 2

7

エラー「ホスト名とポートが正しいこと、およびポストマスターが TCP/IP 接続を受け入れていることを確認してください。」提案:

  1. Postgres が開始されていません。この実行 netstat -aを確認し、Postgres が 5432 ポートで接続を待機しているかどうかを確認します。

  2. 間違ったユーザー名/パスワード - これらの資格情報を使用して、コンソールまたは PG 管理者を使用して Postgres に接続してみてください

  3. 特に Postgres が Linux ボックス上にある場合、つまりセキュリティ上の理由から TCP/IP 接続が許可されない場合に発生する可能性があります。それを有効にする必要があります。ネットで「リモート Postgres 接続を有効にする」または「Postgres tcp/ip 接続を有効にする」を検索すると、大量の情報があります。

于 2013-05-22T18:54:57.910 に答える