0

Say I have a glusterfs mount that is shared between multiple servers, which is accessed by an application, and logs are written to a directory that would normally be in the directory tree of that mount point. (say /foo is our mounted shared storage, and /foo/bar is the directory where logs are written to) In order to prevent all servers from trying to write to the same logfile, I want to make /foo/bar a symlink to another, local directory, /var/bar. Is it possible to make local symlinks on a shared storage mount? And would those symlinks be able to be mapped on other servers that access that storage? Or if not, is there another way around this, like loop devices? Assume changing the directory to which logs are written is not possible.

2

If the filesystem supports symbolic links, then symbolic links (according to the POSIX standard) are interpreted on the client, not the server. Therefore you should be able to symlink to other filesystems reliably on any Unix or Unix-like system such as Linux.

For example:

/foo        A gluster remote file system
/var        A local file system

If /foo/bar is a symlink to /var/log/myhost then every machine that writes to /foo/bar will write to the local /var/log/myhost on that machine.

However if /var/log doesn't exist, the write will fail with an error message that will surprise you. (give it a try) So, make sure /var/log exists. That's not a problem as /var/log is created at install time in most systems. However, what if the link was to /var/log/dirname/filename.txt there is a good chance that /var/log/dirname doesn't exist yet. I've run into this problem before.

(I think there are examples of this in Chapter 28 of The Practice of System and Network Administration where there are recommendations to link to /etc/ from networked file systems.)

So, yes, you can do this with symlinks. However you it may confuse coworkers. Is it possible to tell the software to just write to /var/log/foo? It will be less confusing and more sustainable. You coworkers will thank you.

| improve this answer | |
0

It depends on shared filesystem. But in general, if remote FS supports symlinks, it will works. I can do symlink on gluster volume and it is ok (tested).

| improve this answer | |
0

Maybe you want to setup symlinks like this?

/foo      - Gluster mountpoint
/var/log  - local filesystem mountpoint

A service on the local server is configured to log to /foo/log/app.log. And that /foo/log directory should be per-server, but also located on the Gluster volume so that others can inspect the log when needed.

For that, I would suggest to create two sym-links. On each server:

# mkdir /foo/logs/$(hostname)
# ln -s /foo/logs/$(hostname) /var/log/app

And on the Gluster volume (only needed once):

# ln -s /var/log/app /foo/log

When an application writes to /foo/log/app.log, the symlink /foo/log resolves to /var/log/app. Now, /var/log/app is a symlink on the local filesystem of each server, and each server points to a different directory on the Gluster volume. So, /var/log/app points to /foo/logs/server1.example.com on one server, and to /foo/logs/server2.example.com on an other.

/foo/log/app.log -> /var/log/app/app.log -> /foo/logs/server1.example.com/app.log
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.