Setting Up A Standalone Storage Server With GlusterFS And Samba On Debian Squeeze - Page 3
6 Configuring Samba
In this case, we assume that we have 3 departments.
apt-get install samba
Next, we need to configure /etc/samba/smb.conf on both nodes:
cp /etc/samba/smb.conf /etc/samba/smb.conf_orig
[global] netbios name = CLUSTER [public] comment = Public directory path = /home/public force user = nobody force group = nogroup read only = No create mask = 0664 directory mask = 0775 guest ok = Yes [homes] comment = Home directory %S valid users = %S read only = No create mask = 0700 directory mask = 0700 browseable = No [Dep_1] comment = Department 1 path = /home/Dep_1 guest ok = no browseable = yes writeable = yes create mask = 0660 directory mask = 0770 write list = @Dep_1 [Dep_2] comment = Department 2 path = /home/Dep_2 guest ok = no browseable = yes writeable = yes create mask = 0660 directory mask = 0770 write list = @Dep_2 [Dep_3] comment = Department 3 path = /home/Dep_3 guest ok = no browseable = yes writeable = yes create mask = 0660 directory mask = 0770 write list = @Dep_3
Create users groups on both nodes:
Create the directories and set privileges (only on node1):
Make sure, that all is fine...
ls -l /home/
... as result, you should se:
drwxrwx--- 2 root Dep_1 4096 12-25 13:50 Dep_1
7 Custom scripts and settings to make life easier ;)
How many times did You hear "where is my very important file?" Sometimes users remove wrong files of their shares. With samba, we can avoid this. At least we can recover that file, if we were using the "recycle" module.
Append following lines into the /etc/samba/smb.conf in global section
[global] ... #RECYCLE BIN recycle:repository = /home/TRASH/%u_%I_%S recycle:keeptree = TRUE recycle:versions = TRUE recycle:touch = TRUE ...
And next append following line in section [homes]:
[homes] ... vfs objects = recycle ...
Create TRASH directory:
Of course after that we need to restart SAMBA, thats mean We have to login on every one node and run command like:
It would be easier if We don't need to login twice. We may do that in few simple steps:
ssh-keygen -t rsa
Command ssh-keygen -t rsa generate two files, one of them contains private key and another contain public key.
cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
and on node2 run following command:
That's it, now we may run on node1 following command, and we dont have to enter any passwords:
ssh node2 /etc/init.d/samba restart
8 The very last part
To make sure that both nodes could be accessed via SMB, and there are the same users accounts, we need to add Linux and Samba users accounts on both nodes. Of course we don't want to let users login to any node shell. We can do it in that way (run following command):
Remember, be nice and say hello to every new user.
Next we create a useful script.
#!/bin/bash backup_time=`date +%Y.%m.%d_%H:%M` USER=$1 DEPARTMENT=$2 PASSWORD=$3 #Add Linux user account /usr/sbin/useradd -d /home/$DEPARTMENT/$USER -g $DEPARTMENT -G users,$DEPARTMENT -m -k /root/skel -s /bin/false $USER #Setup directory permission chmod 700 /home/$DEPARTMENT/$USER #Setup SAMBA user - password echo -ne "$PASSWORD\n$PASSWORD\n" | smbpasswd -s -a $USER #Make a copy, and move on node2 cp /etc/passwd /root/passwd.copy.$backup_time cp /etc/group /root/group.copy.$backup_time tar czvf /root/tdb_$backup_time.tgz /var/lib/samba ssh node2 /etc/init.d/samba stop scp /etc/passwd node2:/etc/passwd scp /etc/group node2:/etc/group scp -r /var/lib/samba/* node2:/var/lib/samba/ ssh node2 /etc/init.d/samba start
From now, if you want to add next user, just run ...
Lets make some tests:
On MS Windows client:
Press START -> Run -> and try to get access to \\192.168.20.106
If everything ok, do it on node2: \\192.168.20.107
On both servers you should have access to Johns directory and public directory.
... you should see that result ...
... next run ...
... you should see all removed files and directories.
Of course You may want to use CTDB Cluster to manage the Samba, and You probably should.