I have installed mongo and bson_ext
now I have created a .rb file with the following contents ::
require 'rubygems'
require 'mongo'
db = Mongo::Connection.new.db("mydb")
db = Mongo::Connection.new("localhost").db("mydb")
db = Mongo::Connection.new("localhost", 27017).db("mydb")
However I am getting following error on running the code
yuzaki#ubuntu:~$ ruby firstruby.rb
/home/ryuzaki/.rvm/gems/ruby-1.9.2-p136/gems/mongo-1.2.0/lib/mongo/connection.rb:451:in `connect': Failed to connect to a master node at localhost:27017 (Mongo::ConnectionFailure)
from /home/ryuzaki/.rvm/gems/ruby-1.9.2-p136/gems/mongo-1.2.0/lib/mongo/connection.rb:554:in `setup'
from /home/ryuzaki/.rvm/gems/ruby-1.9.2-p136/gems/mongo-1.2.0/lib/mongo/connection.rb:98:in `initialize'
from firstruby.rb:4:in `new'
from firstruby.rb:4:in `<main>'
Please help!
had this happen several times now, and here is the solution that works for me:
sudo rm /var/lib/mongodb/mongod.lock
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
sudo start mongodb
sudo status mongodb
This is definitely due to your mongo server not running. Since you're on Ubuntu, try doing a sudo /etc/init.d/mongodb start and then see if your code works.
I just encountered this due to my /etc/hosts file not containing an entry for "localhost" - consequently Ruby couldn't resolve "localhost". I suppose you can hardcode 127.0.0.1 into your code rather than "localhost" - or fix /etc/hosts to contain:
127.0.0.1 localhost
If you're on a Mac and used Brew, restarting the service solved it for me:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
You can find this info by running brew info mongodb.
On a mac, using brew I found that brew info mongodb and then using then
ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents or mongod --config /usr/local/etc/mongod.conf worked!
Sometimes there is simply not enough space.
exception in initAndListen: 15926 Insufficient free space for
journals, terminating
Related
I am installing the searchkick gem to enable search capacilities on my application, but when running brew services start opensearch to start opensearch I get the following error: Error: Permission denied # rb_sysopen - /Users//Library/LaunchAgents/homebrew.mxcl.opensearch.plist.
I have tried this line of code: sudo chown -R "$*<My-Username>*":admin /Library/LaunchAgents/ (source), but it did not work.
Could someone help me with this?
I am using a mac with an intel processor (i5)
sudo chmod a+rw /Users/USERNAME/Library/LaunchAgents fixed the issue for me!
Source of code
I am using the osx and trying to install redis through brew
brew install redis
==> Downloading http://download.redis.io/releases/redis-2.8.17.tar.gz
Already downloaded: /Library/Caches/Homebrew/redis-2.8.17.tar.gz
==> make -C /private/tmp/redis-WEL8AT/redis-2.8.17/src CC=clang
==> Caveats
To have launchd start redis at login:
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
Then to load redis now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
Or, if you don't want/need launchctl, you can just run:
redis-server /usr/local/etc/redis.conf
==> Summary
At last I have installed redis, but when I run it in the way of
redis-server /usr/local/etc/redis.conf
there is error message,
*** FATAL CONFIG FILE ERROR ***
Reading the configuration file, at line 54
>>> 'tcp-backlog 511'
Bad directive or wrong number of arguments
I learned from Redis tcp-backlog to uncomment the redis.conf in that line.
but still more errors on other lines come again.
How do I solve it ?
Check if you have installed redis twice. I my case I had another redis installation from anaconda with version 2.6.9:
$ which redis-server
/Users/<username>/anaconda/bin/redis-server
$ redis-server -v
Redis server v=2.6.9 sha=00000000:0 malloc=libc bits=64
Homebrew instead will install the redis-server to a different place:
$ /usr/local/bin/redis-server -v
Redis server v=3.0.1 sha=00000000:0 malloc=libc bits=64 build=bf58331b4c8133f5
So to start the homebrew version with the homebrew config file do
$ /usr/local/bin/redis-server /usr/local/etc/redis.conf
I had similar problem due to a config file left over from previous redis versions. Uninstalling all redis versions and reinstalling the latest worked (also, don't forget to update brew before installing redis):
brew uninstall redis --force
brew update
brew install redis
You should now be able to start it.
I am having this issue third or forth time where after restarting my Mac (Yosemite and same thing with previous OSX version) postgres server doesn't start. I had installed my postgres following this link. Any idea why this consistently occurs after every restart?
typing psql it gives
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"?
I just fixed this on my mac. I used homebrew to install postgres. These are the steps I took to get up and running again.
First check the status of the postgresql service:
pg_ctl -D /usr/local/var/postgres status
if you see this pg_ctl: no server running, unload the launch agent:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
then move your existing postgres data (move rather than delete - cheap insurance):
mv /usr/local/var/postgres /usr/local/var/postgres-deletemewhenitsallgood
then initialize your postgres database:
initdb /usr/local/var/postgres -E utf8
then load your launch agent:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
OR start it:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Now check the status again:
pg_ctl -D /usr/local/var/postgres status
if you see something like this, you are good to go.
pg_ctl: server is running (PID: 61295)
/usr/local/Cellar/postgresql/bin/postgres "-D" "/usr/local/var/postgres"
Then you can go into your postgres database:
psql -d postgres
Also after that you need to add postgress Role.
To Resolve missing postgres Role error
To start postgres server on mac:
install postgres with brew
brew install postgres
ensure you have permissions for /usr/local/postgres
sudo chown -R `whoami` /usr/local
then init the db:
initdb /usr/local/var/postgres
To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
To load postgresql:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
To check your version:
psql --version
And to access postgres
psql -d postgres
I have installed Redis via gems, but am having a problem getting it started.
Following James Edward Gary II steps http://blog.grayproductions.net/articles/setting_up_the_redis_server/
I have:
$ sudo gem install ezmobius-redis
Password:
Successfully installed ezmobius-redis-0.1
1 gem installed
Installing ri documentation for ezmobius-redis-0.1...
Installing RDoc documentation for ezmobius-redis-0.1...
$ redis-server path/to/redis.conf
-bash: redis-server: command not found
Any thoughts as to what I am missing?
If you have done just what you have described in your question, then you are missing redis. ezmobius-redis is just a Ruby library that allows connecting to redis. redis itself is a separate piece of software running independently.
If you followed the article you linked and if you especially did this:
curl -O http://redis.googlecode.com/files/redis-1.0.tar.gz
tar xzvf redis-1.0.tar.gz
cd redis-1.0
make
sudo cp redis-server redis-cli redis-benchmark /usr/local/bin
then you have actually installed a very old version of redis into the /usr/local directory.
If you did this starting the server did not work, then you probably have /usr/local not in your PATH. You can start the server using:
$ /usr/local/bin/redis-server path/to/redis.conf
However, I would suggest to install the newest version of redis. To do that on OSX you should use homebrew:
- Read this (https://github.com/mxcl/homebrew/wiki/Installation) as a guide on how to install homebrew and then do a
brew install redis
to install the newest version of redis.
You might need to open a new terminal to get the latest path settings. Try typing "bash" or "xterm &" and typing the redis-server command again.
I know there are a lot of lion-postgresql related questions on stack overflow already, but none seem to solve my problem.
I installed the homebrew of postgresql and everything was fine after that. Then I messed around a bit with the the libpq.dylib link in /usr/lib so that an application would link to the brew installed version rather than the OS-installed version. Somehow I managed to break my install while doing this in such a way that any call to psql gives the following error:
>psql
psql: invalid connection option "client_encoding"
reinstalling postgresql with 'brew remove postgresql' and another 'brew install postgresql' doesn't seem to help (same error). I've also relinked /usr/lib/libpq.dylib to be /usr/lib/libpq.5.dylib, which is what I believe it was before.
Also, a potentially related problem is that my postgres server doesn't seem to want to shut down:
>pg_ctl -D /usr/local/var/postgres stop -s -m fast
pg_ctl: server does not shut down
Anyone have any clues as to what is wrong? Alternatively, how would I completely uninstall and reinstall the postgres server and client?
Try /usr/local/bin/psql. If that doesn't work, take a look at which psql.
Lion comes with a installation of postgresql running, and you might be using the stock psql instead of the brew psql.
Or that one might be running, and using the brew psql to connect to the Lion postgres instance.
Verify that /usr/local/bin is before /usr/bin in $PATH. Check echo $PATH.
Fix that worked for me:
if you use pgAdmin:
show server_encoding;
-bash-4.1$ export PGCLIENTENCODING='UTF8'
-bash-4.1$ psql
psql (9.3.3)
Type "help" for help.
postgres=# \l
...
put var in .profile or .bashrc
If you installed postgresql via homebrew:
brew update
brew doctor
Unexpected dylibs:
/usr/local/lib/libpq.5.dylib
Unexpected .la files:
/usr/local/lib/psqlodbcw.la
brew upgrade postgresql
Error: The brew link step did not complete successfully
brew link --overwrite postgresql
Then you should be fine to run the psql command.
if you've brew doctor'd and already have the latest version of postgres, run
brew unlink postgresql && brew link postgresql
then
brew link --overwrite postgresql