Concurrent users at multi location using Firebird - firebird

How can I use firebird to connect to my database (host) from the other computer at different location 50km away?
Is there an online method? How to do it?

I use SSH tunnels. On Ubuntu 14.04 with Upstart and autossh installed,
you#your-local-server:/etc/init$ cat autossh-other-server.conf
description "autossh other-server service"
version "1.0"
author "Your Name"
start on runlevel [2345]
stop on runlevel [016]
script
exec start-stop-daemon --start -c some-user-with-ssh-keys --exec /usr/bin/autossh -- -N -p 2022 other-server.your-domain.com -L 0.0.0.0:3052:localhost:3050
end script
Note that I already had a user setup with ssh keys for no-password ssh connections to the remote host. Your software on this side can connect to Firebird on port 3052.

Related

Create multiple Postgres instances on same machine

To test streaming replication, I would like to create a second Postgres instance on the same machine. The idea is that if it can be done on the test server, then it should be trivial to set it up on the two production servers.
The instances should use different configuration files and different data directories. I tried following the instructions here http://ubuntuforums.org/showthread.php?t=1431697 but I haven't figured out how to get Postgres to use a different configuration file. If I copy the init script, the scripts are just aliases to the same Postgres instance.
I'm using Postgres 9.3 and the Postgres help pages say to specify the configuration file on the postgres command line. I'm not really sure what this means. Am I supposed to install some client for this to work? Thanks.
I assume you can work your way out on using postgresql utilities.
Create the clusters
$ initdb -D /path/to/datadb1
$ initdb -D /path/to/datadb2
Run the instances
$ pg_ctl -D /path/to/datadb1 -o "-p 5433" -l /path/to/logdb1 start
$ pg_ctl -D /path/to/datadb2 -o "-p 5434" -l /path/to/logdb2 start
Test streaming
Now you have two instances running on ports 5433 and 5434. Configuration files for them are in data dirs specified by initdb. Tweak them for streaming replication.
Your default installation remains untouched in port 5432.
On Debian based distros you could use pg_createcluster instead of initdb:
$ pg_createcluster -u [user] -g [group] -d /path/to/data -l /path/to/log -p 5433
Also pg_ctlcluster is an alternative to pg_ctl.
Steps to create New Server Instance on PostgreSQL 9.5
On command prompt run:
initdb -D Instance_Directory_path -U username -W
(prompts for password)
Once the new Instance Directory is created. Run command prompt as Administrator
pg_ctl register -N service_name -D Instance_Directory_path -o "-p port_no"
After the service is registered, start server
pg_ctl start -D Instance_Directory_path -o "-p port_no"
To complete other answers, on CentOS 6 AND 7.
After running something like
$ initdb -D /path/to/newdb
You'll have to change at least port configuration option and, probably, listen_addresses in config file postgresql.conf.
Instead of starting inmediatly this new instance, which has been explained in previous answers, maybe you want new instance to run automatically on system start (in case of shutdown, e.g.). To do this, as CentOS doesn't have pg_ctl register option (only for Windows) you'll have to create a new service file and register it in order systemctl or service can start it up automatically.
Centos 6
Follow next commands to get service's init file:
[root#machine ~]# service postgresql-9.6 edit
Usage: /etc/init.d/postgresql-9.6 {start|stop|status|restart|upgrade|condrestart|try-restart|reload|force-reload|initdb|promote}
[root#machine ~]# cd /etc/init.d # Now we know where service file is
[root#machine init.d]# cp -p postgresql-9.6 postgresql-9.6_5433
[root#machine init.d]# vi postgresql-9.6_5433
Now you can change PGDATA directory with the one where new instance resides. If you're using Postgresql version previous to 9.4 (which you shouldn't by the time of this answer) you'll have to change PGPORT too with the value where new instance is listening to.
The name of the new service is up to you. I usually take original service name and add port number at the end.
Now you only have to register new service:
[root#machine init.d]# chkconfig postgresql-9.6_5433 on # service registered!
[root#machine init.d]# service postgresql-9.6_5433 start
Iniciando servicios postgresql-9.6_5433: [ OK ]
[root#machine init.d]# service postgresql-9.6_5433 status
Se está ejecutando postgresql-9.6_5433 (pid 120993)...
Centos 7
In CentOS 7 instead of service to control services running on the machine you have systemctl and commands and paths change a bit. But the process is the same: create new service file, edit with the new location/port, register and start:
[root#localhost ~]# locate postgresql.service
/etc/systemd/system/multi-user.target.wants/postgresql.service
/usr/lib/systemd/system/postgresql.service
[root#localhost ~]# cd /usr/lib/systemd/system
[root#localhost ~]# cp -p postgresql.service postgresql_5433.service
[root#localhost ~]# vi postgresql_5433.service
# Change PGDATA and maybe PGPORT if PG version <9.4
[root#localhost ~]# systemctl enable postgresql_5433.service
[root#localhost ~]# systemctl start postgresql_5433.service
[root#localhost ~]# systemctl list-unit-files | grep postgres
postgresql.service enabled
postgresql_5433.service enabled

postgresql: pg_ctl status shows no server running when the server is running as a windows service

I have PostgreSQL 9.4(not installed, rather self configured) which is also installed as a Windows service. Now I am trying to check the status of the server using pg_ctl.exe status -D data_dir_path, but it only shows the status when I start the console as admin.
My final goal is to be able to shutdown/ start the database server without admin rights. Is it possible to configure PostgreSQL so that I can start/stop the servers locally without admin rights?
As far I read in the PostgreSQL documentation, the services can be registered to a user using [-U username] [-P password] arguments but I am not sure whether this is the database user or the local windows user. I tried registering the service using the following code but it does not install it. And I do not see any logs too. The commnd follows:
pg_ctl.exe register -N service_name -U database_user -P database_user_password -D data_dir_path -S auto -o "-p port"
Thanks in advance

memcached doesn't start on vagrant up with CentOS 6.5

I'm trying to provision a development box with Vagrant and a CentOS 6.5 base box. I want memcached to automatically start at system boot/vagrant up.
I have tried adding memcached -d -l localhost -p11211 to /etc/rc.d/rc.local and this does not work.
I have also tried adding to /etc/init/vagrant-mounted.conf
start on vagrant-mounted
memcached -d -l localhost -p11211
[EDIT]
I've updated /etc/rc.d/rc.local to now use the following
chkconfig memcached on
service memcached start
I'm not seeing anything in the /var/log/boot.log. It looks like rc.local is not being run at all. It has ugo+x permissions; so the file is definitely executable, but it doesn't appear to run at all.
Does memcached -d -l localhost -p11211 exit immediately or spawn a process?
If it keeps running, try: nohup memcached -d -l localhost -p11211 &
Also, try putting it in /etc/rc.local as
memcached -d -l localhost -p11211 >/var/log/memcached.log 2>&1
That will give you a log file with possible errors.
Lastly, does your install of memcached not have an init.d file in /etc/init.d ?
if it does, simply do chkconfig servicename on && service servicename start

How to Install Postgresql v9.1 and JBoss AS v7.1.1 on Ubuntu 12.04 LTS

There are really good sources that describe how to install Postgresql and JBoss on Ubuntu 12.04 LTS but information is distributed accross other pages.
However, it would be good to have a walktrough guide to easily install and configure these.
Preparing for installation
sudo apt-get install postgresql postgresql-contrib postgresql-common pgadmin3 openssh-server openssh-client
This command will install latest Postgresql, PgAdmin3, Postgresql-contrib and SSH server packages. SSH server is not necessarily required but it is good to manage the server remotely. So I've added it to the install list. [1]
Oracle Java JDK and JBoss AS installations are not automatic. So we should download them from their web sites. We'll use jdk-7u10-linux-i586.tar.gz (or later version) and jboss-as-7.1.1.Final.tar.gz
See http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html for JDK and http://www.jboss.org/jbossas/downloads/ for JBoss.
or try the commandline links below [2]. (The links might get invalid in the future, sorry for that...)
wget --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F" "http://download.oracle.com/otn-pub/java/jdk/7u10-b18/jdk-7u10-linux-i586.tar.gz"
wget "http://download.jboss.org/jbossas/7.1/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final.tar.gz"
Note that one might like to install OpenJDK which is available on apt-get repository and preferred by Ubuntu. However that is a preference and I'd like to use Oracle's JDK.
Optional: Adding extra locale support for Postgresql:
In my experience I needed Turkish locale support on Postgresql but it was not installed on Ubuntu by default. Here are sample commands to add Turkish collation support to Ubuntu, hence to Postgresql. [3]
sudo locale-gen tr_TR
sudo locale-gen tr_TR.UTF-8
Configuring Postgresql
We've already installed postgresql via apt-get. Now it would be good to make some changes to the config. [4]
By default Postgresql does not allow TCP connections. Edit postgresql.conf (my favorite editor is pico)
sudo pico /etc/postgresql/9.1/main/postgresql.conf
add
listen_addresses = '*' #Listens on all interfaces!!
or uncomment
listen_addresses = 'localhost' #More secure way to configure the server. Prefer this one if you won't connect to the server remotely
line.
If you selected to bind to all interfaces instead of localhost, then you'll need an extra configuration to allow remote connections. [5] Open up pg_hba.conf
sudo pico /etc/postgresql/9.1/main/pg_hba.conf
Add the line:
host all all 0.0.0.0/0 md5
Restart Postgresql to apply new config.
sudo /etc/init.d/postgresql restart
Now we'll set the password for default postgres user [6]. First fire up postgresql commandline.
sudo -u postgres psql
execute the following command. [7]
postgres=# ALTER USER postgres WITH ENCRYPTED PASSWORD '<your new password>';
Now you may connect to your server via PgAdmin3 or your favorite SQL Client or via command line...
Installing and Configuring Java and JBoss AS 7.1.1
I've selected /opt directory as our install directory. You are free to choose your own as long as you configure scripts accordingly. First extract JDK.
sudo tar -zxvf <Full Path to jdk-7u10-linux-i586.tar.gz> -C /opt
This will extract JDK to **/opt/jdk1.7.0_10* directory. Now we'll extract and configure JBoss AS. [8] [9]
First create a user for JBoss (jboss-as), it is a good habit to run your servers impersonating a user instead of directly executing them as root. This will tighten security.
sudo useradd -s /bin/sh jboss-as
Extract jboss-as-7.1.1.Final.tar.gz to /opt/jboss-as-7.1.1.Final
sudo tar -zxvf <Full Path to jboss-as-7.1.1.Final.tar.gz> -C /opt
I assume you'll run JBoss in standalone mode. Open up standalone.conf add the lines below.
JAVA_HOME="/opt/jdk1.7.0_10" #show your JAVA_HOME directory to JBoss
JAVA_OPTS="$JAVA_OPTS -Djboss.bind.address=0.0.0.0" #Bind to 0.0.0.0 so that remote clients can connect to your server.
Impersonate jboss-as user by executing
sudo -su jboss-as
First test the server by executing
cd /opt/jboss-as-7.1.1.Final
./standalone.sh
It should fire-up without problems. Use CTRL+C to shut down the server. You might connect to the server on your browser at port 8080.
http://<your server address>:8080
Now we'll create a management user for JBoss. It is required to use administration console running at port 9990.
export JAVA_HOME=/opt/jdk1.7.0_10/
./add-user.sh
Management User -> Select (a)
Realm (Management Realm) -> Accept the default and press enter
Username : -> Enter <your admin user name>
Password : -> Enter <your password>
Is this correct yes/no? -> Type 'yes' and press Enter
Added user '<your admin user name>' to file '/opt/jboss-as-7.1.1.Final/standalone/configuration/mgmt-users.properties'
Added user '<your admin user name>' to file '/opt/jboss-as-7.1.1.Final/domain/configuration/mgmt-users.properties'
Exit from impersonated jboss-as user.
exit
Now you may configure your server via its web interface at
http://<your server address>:9990
This address only accept your if you are at localhost Whenever you need to configure your server remotely, fire up the server with the following command.
sudo -u jboss-as ./standalone.sh -Djboss.bind.address.management=0.0.0.0
Again for security reasons do not bind to 0.0.0.0 if you don't need it.
Install JBoss as System Service
We'll prepare a server management script for init daemon (aka. init.d) [10]
cd /etc/init.d/
sudo pico jboss
Copy and paste the content below. Do not forget to modify JAVA_HOME, JBOSS_HOME directories and --chuid jboss-as (impersonates as jboss-as user when running the server) parameter accordingly.
#!/bin/sh
### BEGIN INIT INFO
# Provides: jboss
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/Stop JBoss AS v7.1.1 Final
### END INIT INFO
#
#source some script files in order to set and export environmental variables
#as well as add the appropriate executables to $PATH
export JAVA_HOME=/opt/jdk1.7.0_10
export PATH=$JAVA_HOME/bin:$PATH
export JBOSS_HOME=/opt/jboss-as-7.1.1.Final
export PATH=$JBOSS_HOME/bin:$PATH
case "$1" in
start)
echo "Starting JBoss AS 7.1.1 Final"
start-stop-daemon --start --quiet --background --chuid jboss-as --exec ${JBOSS_HOME}/bin/standalone.sh
;;
stop)
echo "Stopping JBoss AS 7.1.1 Final"
start-stop-daemon --start --quiet --background --chuid jboss-as --exec ${JBOSS_HOME}/bin/jboss-cli.sh -- --connect command=:shutdown
;;
*)
echo "Usage: /etc/init.d/jboss {start|stop}"
exit 1
;;
esac
exit 0
Set the script as executable and update rc.d
sudo chmod +x jboss
sudo update-rc.d jboss defaults
Now JBoss will start with your server. You might use the commands below to start and stop the server
sudo service jboss start
sudo service jboss stop

I have installed PostgreSQL via MacPorts, but cannot access it

As I said in title, I've installed PostgreSQL usind MacPorts, but cannot access it.
The installation process was
$ sudo port install postgresql83-server
$ sudo mkdir -p /opt/local/var/db/postgresql83/webcraft
$ sudo chown postgres:postgres /opt/local/var/db/postgresql83/webcraft
$ sudo su postgres -c '/opt/local/lib/postgresql83/bin/initdb -D /opt/local/var/db/postgresql83/webcraft'
$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql83-server.plist
My PATH is
/opt/local/lib/postgresql83/bin:/opt/local/lib/mysql5/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
I try to connect the server using psql client
$ psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Here is some info
$ ps ax | grep postgres | grep -v grep
52 ?? Ss 0:00.00 /opt/local/bin/daemondo --label=postgresql83-server --start-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql83-server/postgresql83-server.wrapper start ; --stop-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql83-server/postgresql83-server.wrapper stop ; --restart-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql83-server/postgresql83-server.wrapper restart ; --pid=none
Did you try running:
which psql
I imagine psql is still referencing /usr/bin/psql, and the macports version of psql is suffixed with the version number, in your case psql83. You can alias psql to psql83 as a simple workaround. Better would be to change the default:
sudo port select --set postgresql postgresql83
That will do the proper routing.
There is a very easy solution to this, but it's not well documented in my opinion:
MacPorts encourages installing their *_select ports to manage potentially multiple versions of software (say you want Postgres93 and Postgres94 at the same time). It's a great feature, but it adds an extra step that is for some reason rarely mentioned in the docs:
$ sudo port install postgresql94-server
Many failed attempts at starting the server later..
$ sudo port install postgresql_select
$ sudo port select postgresql
Available versions for postgresql:
none (active)
postgresql94
Well that can't be good!
$ sudo port select postgresql postgresql94
$ sudo port load postgresql94-server
You're kidding me. Now it's running?
Simply installing Postgres doesn't fully setup symlinks to make it easily runnable. Installing postrgresql_select gives MacPorts the information it needs to do that via port select. Once you've selected the active version of your choice, starting the Posgres server via luanchctl is as easy as port load postgresqlXX-server.
I know this is a very late answer and doesn't answer your full question, but launchctl will show different results depending on if you are superuser or not.
Try doing:
sudo launchctl list | grep postgres
I had exactly the same problem on my MacBook Pro. I could resolve the problem after I rode this blog post here and all the comments:
http://benscheirman.com/2010/06/installing-postgresql-for-rails-on-mac-os-x
The Problem is that postgres is not really running. I recognized this after I did a port scan to my own machine and realized that nothing is running on Port 5432.
I created a small script "start_pg_server.sh":
#!/bin/sh
sudo su postgres -c 'pg_ctl start -D /opt/local/var/db/postgresql83/defaultdb/'
after executing this script the server was running and I could connect me with pgAdmin. I was also able to run my ruby stuff with rake db:create and rake db:migrate.
After I restored using Timemachine I had the same problem.
The reason was that the permissions were mangled and postgres could not write the pid file.
Running this solved it for me:
sudo chown -R postgres:postgres /opt/local/var/db/postgresql91/
sudo port unload postgresql91-server
sudo port load postgresql91-server
Did you by any chance create your postgres user with a shell of /usr/bin/false? If so, the startup script won't work because it uses su which passes commands you send it through the shell.
If you did set it to /usr/bin/false, try changing it to /bin/bash and that might fix things.