You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Michael Joyner <mi...@newsrx.com> on 2014/09/18 18:08:17 UTC
Re: Access solr cloud via ssh tunnel? (Workaround/Jsch)
On 09/16/2014 04:03 PM, Doug Balog wrote:
> Not sure if this will work, but try to use ssh to setup a SOCKS proxy via
> the -D 9999 command option.
> Then use the socksProxyHost and socksProxyPort via the java command line
> (ie java -DsocksProxyHost="localhost") or
> System.setProperty("socksProxyHost","localhost") from your code. Make sure
> to specify both the host and the port.
> See
> http://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html
Unfortunately Jsch does not seem to provide the "-D" "socks5" over
"ssh" option.
- In case this may help others -
Because the production system will have direct access to the cluster and
this is being setup for accessing the production cloud from our office
we instead did the following:
SolrTunnels t = new SolrTunnels();
t.connect();
LBHttpSolrServer server = new LBHttpSolrServer();
server.setParser(new BinaryResponseParser());
server.setAliveCheckInterval(500);
for (SolrHost solr: t.getEndpoints()) {
server.addSolrServer("http://127.0.0.1:"+solr.forward+"/solr/test");
}
WHERE:
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.newsrx.util.NrxLog;
public class SolrTunnels {
static final private String sshUser = "autossh";
static final private String sshPass = "LETMEIN";
static private String sshHost = "public.solr.gateway.host.com;
static final private int sshPort = 22;
static volatile private JSch jsch = new JSch();
static private Session solrSSH = null;
public static class SolrHost {
public String host;
public int port;
public int forward;
public SolrHost() {}
public SolrHost(String host, int port) {
super();
this.host = host;
this.port = port;
this.forward = -1;
}
}
final static private List<SolrHost> nodes;
static {
nodes=new ArrayList<>();
nodes.add(new SolrHost("solr1.private", 8983));
nodes.add(new SolrHost("solr2.private", 8983));
}
public SolrTunnels() {
}
public void connect() {
if (solrSSH != null) {
if (solrSSH.isConnected()) {
return;
}
}
JSch.setConfig("StrictHostKeyChecking", "no");
JSch.setConfig("Compression", "none");//compressionsometimes
causes ssh transport breakage
int maxTries = 100;
do {
try {
if (solrSSH !=null) {
solrSSH.disconnect();
}
solrSSH = jsch.getSession(sshUser, sshHost, sshPort);
solrSSH.setPassword(sshPass);
solrSSH.connect(1000);
Iterator<SolrHost> isolr = nodes.iterator();
while (isolr.hasNext()) {
SolrHost solr = isolr.next();
solr.forward=solrSSH.setPortForwardingL(0, solr.host,solr.port);
Console.log("http://127.0.0.1:"+solr.forward+"/solr");
}
} catch (JSchException e) {
e.printStackTrace();
try {
Console.log("Sleeping 100 ms");
Thread.sleep(100);
} catch (InterruptedException e1) {
}
}
} while (maxTries-- > 0&&!solrSSH.isConnected());
}
public Collection<SolrHost> getEndpoints() {
List<SolrHost> list = new ArrayList<>();
Iterator<SolrHost> isolr = nodes.iterator();
while (isolr.hasNext()) {
SolrHost solr = isolr.next();
if (solr.forward>0) {
list.add(solr);
}
}
return list;
}
public void disconnect() {
if (solrSSH !=null) {
Iterator<SolrHost> isolr = nodes.iterator();
while (isolr.hasNext()) {
SolrHost solr = isolr.next();
try {
solrSSH.delPortForwardingL(solr.forward);
} catch (JSchException e) {
}
}
solrSSH.disconnect();
}
}
}
Re: Access solr cloud via ssh tunnel? (Workaround/Jsch)
Posted by Shalin Shekhar Mangar <sh...@gmail.com>.
This would make for a nice blog post!
On Thu, Sep 18, 2014 at 9:38 PM, Michael Joyner <mi...@newsrx.com> wrote:
> On 09/16/2014 04:03 PM, Doug Balog wrote:
>
>> Not sure if this will work, but try to use ssh to setup a SOCKS proxy via
>> the -D 9999 command option.
>> Then use the socksProxyHost and socksProxyPort via the java command line
>> (ie java -DsocksProxyHost="localhost") or
>> System.setProperty("socksProxyHost","localhost") from your code. Make
>> sure
>> to specify both the host and the port.
>> See
>> http://docs.oracle.com/javase/7/docs/api/java/net/doc-files/
>> net-properties.html
>>
>
> Unfortunately Jsch does not seem to provide the "-D" "socks5" over "ssh"
> option.
>
> - In case this may help others -
>
> Because the production system will have direct access to the cluster and
> this is being setup for accessing the production cloud from our office we
> instead did the following:
>
> SolrTunnels t = new SolrTunnels();
> t.connect();
> LBHttpSolrServer server = new LBHttpSolrServer();
> server.setParser(new BinaryResponseParser());
> server.setAliveCheckInterval(500);
> for (SolrHost solr: t.getEndpoints()) {
> server.addSolrServer("http://127.0.0.1:"+solr.forward+"/solr/test");
> }
>
> WHERE:
>
> import java.util.ArrayList;
> import java.util.Collection;
> import java.util.Iterator;
> import java.util.List;
>
> import com.jcraft.jsch.JSch;
> import com.jcraft.jsch.JSchException;
> import com.jcraft.jsch.Session;
> import com.newsrx.util.NrxLog;
>
> public class SolrTunnels {
>
> static final private String sshUser = "autossh";
> static final private String sshPass = "LETMEIN";
> static private String sshHost = "public.solr.gateway.host.com;
> static final private int sshPort = 22;
>
> static volatile private JSch jsch = new JSch();
> static private Session solrSSH = null;
>
> public static class SolrHost {
> public String host;
> public int port;
> public int forward;
> public SolrHost() {}
> public SolrHost(String host, int port) {
> super();
> this.host = host;
> this.port = port;
> this.forward = -1;
> }
> }
> final static private List<SolrHost> nodes;
> static {
> nodes=new ArrayList<>();
> nodes.add(new SolrHost("solr1.private", 8983));
> nodes.add(new SolrHost("solr2.private", 8983));
> }
> public SolrTunnels() {
>
> }
>
> public void connect() {
> if (solrSSH != null) {
> if (solrSSH.isConnected()) {
> return;
> }
> }
>
> JSch.setConfig("StrictHostKeyChecking", "no");
> JSch.setConfig("Compression", "none");//compressionsometimes
> causes ssh transport breakage
>
> int maxTries = 100;
> do {
> try {
> if (solrSSH !=null) {
> solrSSH.disconnect();
> }
> solrSSH = jsch.getSession(sshUser, sshHost, sshPort);
> solrSSH.setPassword(sshPass);
> solrSSH.connect(1000);
> Iterator<SolrHost> isolr = nodes.iterator();
> while (isolr.hasNext()) {
> SolrHost solr = isolr.next();
> solr.forward=solrSSH.setPortForwardingL(0, solr.host,solr.port);
> Console.log("http://127.0.0.1:"+solr.forward+"/solr");
> }
> } catch (JSchException e) {
> e.printStackTrace();
> try {
> Console.log("Sleeping 100 ms");
> Thread.sleep(100);
> } catch (InterruptedException e1) {
> }
> }
> } while (maxTries-- > 0&&!solrSSH.isConnected());
> }
>
> public Collection<SolrHost> getEndpoints() {
> List<SolrHost> list = new ArrayList<>();
> Iterator<SolrHost> isolr = nodes.iterator();
> while (isolr.hasNext()) {
> SolrHost solr = isolr.next();
> if (solr.forward>0) {
> list.add(solr);
> }
> }
> return list;
> }
>
> public void disconnect() {
> if (solrSSH !=null) {
> Iterator<SolrHost> isolr = nodes.iterator();
> while (isolr.hasNext()) {
> SolrHost solr = isolr.next();
> try {
> solrSSH.delPortForwardingL(solr.forward);
> } catch (JSchException e) {
> }
> }
> solrSSH.disconnect();
> }
> }
> }
>
>
--
Regards,
Shalin Shekhar Mangar.