Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

Thursday, February 11, 2010

Make Ubuntu faster

There are few very simple methods to make Ubuntu faster. Some of them work not only on Ubuntu, but on other linux systems as well.

Change dynamic linking to static one

When compiler generates binary file, elements which should connect with external libraries are only stubs. When running application for the first time (in a session), it is dynamically linked, which means stubs are replaced with real calls to libraries. This process takes some time. Open Office on my machine runs about 5 seconds for the first time, and 1-2 seconds every next time.

Fortunately there is a program called prelink, accessible from Ubuntu repositories.

sudo apt-get install prelink
sudo prelink -amR

After the second command prelink scans binaries specified in /etc/prelink.conf and modifies them replacing dynamic calls with static ones, but in binary files, so this change is permanent. Disadvantage of this solution is that after every update of processed program we need to run prelink again.

We can always go back to dynamic linking (undo prelink):

sudo prelink -au

You HAVE TO go back to dynamic linking if you want to remove prelink.

Get now what I'll need in a few miliseconds

Next useful program fastening Ubuntu is preloader. It uses magic (complicated algorithms) to predict what data is going to be necessary next and loads it before application asks.

You only need to install it:

sudo apt-get install preload

It should run automatically, but if for some reason it is not running:

sudo /etc/init.d/preload start

Koziołek says it consumes a lot of RAM, but I didn't notice :)

Run services in paralell

If you have more than one core, you can set your system to start services in paralell during startup. This is potentially dangerous, as there might be services which depend on each other.

Edit /etc/init.d/rc and find line CONCURRENCY=none. Change it to CONCURRENCY=startpar.

This post is here courtesy of Bartłomiej "Koziołek" Kuczyński, and is translation of his post in Polish.

Monday, August 10, 2009

Setting up backup by rsync

I want to backup my files on another server. So I go to another server, and create file /etc/rsyncd.conf:

secrets file = /etc/rsyncd.secrets
#Global properties
read only = yes
list = yes
#User on server
uid = backup
#User's group
gid = backup

#Protected share for backups.
[files]
comment = For your eyes only
path = /home/backup/
auth users = franek
read only = no
hosts allow = 192.168.1.64
hosts deny = *
list = yes
We are using user backup as rsync files owner. Don't forget to create him.

So now we need to create entry for franek in rsyncd.secrets:
franek:his_password
rsyncd.secrets cannot be readable for all. In such case rsync daemon will not allow access to protected shares. Set permissions to 600.

We need to do one more thing before starting the daemon. Go to /etc/default/rsync and set RSYNC_ENABLE=true

Ok, issue sudo /etc/init.d/rsync start and rsync deamon is running.

Now go to the client machine. The one we want to make backups from. I want to backup whole /home, so my command looks like this:
sudo rsync -aXAvz --delete --delete-excluded --exclude-from=$DIR/backup.excludes --password-file=$DIR/rsync-pass /home franek@moon::files
So there is sudo rsync, and then some options:
-a the same as -rlptgoD, which is:
-r recurse into directories
-l copy symlinks as symlinks
-p preserve permissions
-t preserve modification times
-g preserve group
-o preserve owner
-D preserve device files, preserve special files
-X preserve extended attributes
-A preserve ACLs
-v be verbose
-z use compression
Then there is --delete and --delete-excluded. It means if there is some file on copy, but there is no such file on source, delete file from copy. --delete-excluded means delete all excluded files from copy.

I keep exclusions patterns in separate file. Format is quite simple:
lost+found
*/.Trash/
*/.thumbnails/
cache/
Cache/
.Cache/
.cache/
My share is password protected. Only user franek can access it, and he needs to give his password. If you want to do it by system (e.g. cron), you don't have the possibility to type the password. However, you can put it into file and make file readable only for user (permissions 700). Then you can just point to that file with --password-file option.

Next there is just source and destination. Just like in cp or smb. Source is pretty simple in my example. Destination is a bit more complicated: <user>@<server>::<share-name>

Saturday, August 1, 2009

Setting samba on ubuntu server for sharing files

I am building home server, so now I want to configure it in a way so I could put photos there, and everyone could access them.

I assume samba is already initialized.

Guest access
We want everybody to be able to store files there, and everybody to be able to read them. So let's give guest access to it. But somebody has to be the owner of the files, right? (In terms of Unix file ownership, chown). So we neet to tell who guest user maps to. Lets call our Unix user henry:
sudo adduser henry
Set some password too.

Now, let's tell samba that guest should map to henry. In /etc/samba/smb.conf in [global] section:
guest account = henry
We are ready to create share for everybody now. Again, in /etc/samba/smb.conf:
[for-all]
path = /home/henry
browsable = yes
read only = no
guest ok = yes
create mask = 644
Now we created share called "for-all", it is stored at /home/henry, and everybody can read and write it. Files put to server into for-all share are going to be read-write for owner (henry), and read for everyone. However, it is not so important as everybody can access them like owner through samba.

Users access
We can also make it available only for users. Let's say we want samba user henry:
sudo smbpasswd -a henry
Set password. User created.

Now we need to disable guest access:
guest ok = no
Now we can connect from another machine by smbclient:
smbclient //192.168.1.1/for-all -U henry
Of course put your server's IP instead of 192.168.1.1

Mount as fs for users manually
You can mount samba share to some directory on your client machine. Just like some filesystem. Install smbfs package:
sudo apt-get install smbfs
If you have sudo access, you can mount samba share. First, create directory to mount it:
mkdir smb-share
Now, mount share:
sudo mount -t cifs //192.168.1.1/for-all smb-share -o username=henry,noexec,uid=local_user,gid=local_group
noexec means you'll be not able to run any executable files from that share. uid and gid will render all files in mounted share to belong to user local_user and group local_group on client.

If you want more users to be able to mount the share, you can create group for them:
sudo addgroup samba
Now let's give this group rights to mount remote samba shares. Run:
sudo visudo
And in the group section add following line:
%samba   ALL=(ALL) /bin/mount,/bin/umount,/sbin/mount.cifs,/sbin/umount.cifs
Add user frank to that group:
sudo adduser frank samba
From now on, frank can mount samba shares.

Friday, July 31, 2009

Configure postfix to send emails for root to your account

Goal: make our small ubuntu server forward email which has "to: root" to your private mail.

Install postfix.
sudo apt-get install postfix
Some console app for sending emails can be handy too:
sudo apt-get install mutt
Edit /etc/postfix/main.cf. In mydestination enter host, host.domain, localhost.domain, and also empty domain:
mydestination = serverek.przepompownia.com, localhost.przepompownia.com, , localhost
Restart postfix. I'm not sure if it is really needed, but won't hurt ;)
sudo /etc/init.d/postfix restart
Ok, now edit /etc/aliases. Add something like this:
root: franek
franek: mickey@my.mail.com
Dont forget to run:
sudo newaliases
This way everything sent to root is forwarded to franek, and everything sent to franek is forwarded to mickey@my.mail.com

Now you can try sending some mail to "root". You can use mutt for this.
UPDATE:
Recently my ISP (neostrada, TPSA) blocked outgoing connections to port 25 (standard port for connecting with SMTP servers). What to do to send emails to port 587 is well described here. Author only forgot to add that you also need this:
transport_maps = hash:/etc/postfix/transport
in your main.cf

Sunday, December 28, 2008

64 bitowy firefox, java i flash plugin pod linuxem

W końcu jest! 64-bitowy plugin do javy i flash player do firefoxa. Jak dotąd użytkownicy 64-bitowego linuxa mieli do wyboru firefoxa bez pluginów do flasha i javy lub wersję 32-bitową, co wymagało pewnych kombinacji. Ewentualnie firefoxa 64-bitowego z 32-bitowymi pluginamy, co wymagało jeszcze większych kombinacji. Teraz w końcu możemy mieć w pełni 64-bitową przeglądarkę, z 64-bitowymi pluginami. I kombinacji też przy tym mniej ;)

Jak to zrobić

"Przepis" dotyczy ubuntu, ale na innych dystrybucjach powinno być podobnie. Najpierw ściągamy javę 1.6.0_12 early access i flash playera.

Jeśli java ściągnięta jest w postaci pliku .bin, po prostu go uruchamiamy (wcześniej dając mu taką możliwość np. przez chmod +x). Spowoduje to wypakowanie javy do katalogu jre1.6.0_12. Katalog ten przenosimy np. do /usr/lib/jvm (jako root lub przez sudo).

Rozpakowujemy flash playera. Jest to jeden plik libflashplayer.so. Kopiujemy ten plik do katalogu /usr/lib64/mozilla/plugins/

W tym też katalogu tworzymy link do pluginu javy:
ln -s /usr/lib/jvm/jre1.6.0_12/lib/amd64/libnpjp2.so /usr/lib64/mozilla/plugins/libnpjp2.so

I to wszystko! Uruchamiamy teraz 64-bitowego firefoxa i już możemy się cieszyć przeglądarką z javą i flashem. W dodatku jest ona oryginalna, systemowa, czyli update'y do niej będą się pojawiały w repozytorium.