Jual alat otomatis

Rabu, 30 Juli 2014

RASPBERRY WEBMIN SAMBA SHARE | FILE SERVER

Raspberry Pi Webmin Install & Updates Via apt-get

This post is an update to a method used previously to install webmin on to the Raspberry Pi. The old post can still be found here if you run in to issues and is a fail safe method. However times move on and we can now change a few settings on the Pi to be able to install webmin and all of its dependencies using apt-get install webmin.
So enough about the blurb intro lets get on to what needs to be done.
Firstly get yourself SSH’d in to your Pi or open a command session from the desktop. We will then move on to editing our source list for APT. Carry out the following command
pi@raspberrypi ~ $ sudo nano /etc/apt/sources.list
You will be presented with your source.list file. You need to add in two new lines below the current list of sources. Copy and paste in the following.
deb http://download.webmin.com/download/repository sarge contrib
deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib
This will use the official webmin repository and its mirror to ensure we can keep webmin updated to the latest version.
We will also now be adding in key file to ensure we can access the repo. First ensure you are in your root directory.
pi@raspberrypi ~ $ cd ~
As you can see I was already in there but you may not be so always worth running to be sure. We will now download the key file.
pi@raspberrypi ~ $ wget http://www.webmin.com/jcameron-key.asc
--2013-12-24 11:27:24--  http://www.webmin.com/jcameron-key.asc
Resolving www.webmin.com (www.webmin.com)... 216.34.181.97
Connecting to www.webmin.com (www.webmin.com)|216.34.181.97|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1320 (1.3K) [text/plain]
Saving to: `jcameron-key.asc'

100%[======================================>] 1,320       --.-K/s   in 0s

2013-12-24 11:27:25 (11.2 MB/s) - `jcameron-key.asc' saved [1320/1320]
Now we just need to add this to our apt key list.
pi@raspberrypi ~ $ sudo apt-key add jcameron-key.asc
OK
To ensure APT is up to date with all of the changes we have made you can now run the update command.
pi@raspberrypi ~ $ sudo apt-get update
Get:1 http://mirrordirector.raspbian.org wheezy Release.gpg [490 B]
Get:2 http://archive.raspberrypi.org wheezy Release.gpg [490 B]
Get:3 http://webmin.mirror.somersettechsolutions.co.uk sarge Release.gpg [189 B]
Get:4 http://webmin.mirror.somersettechsolutions.co.uk sarge Release [9,542 B]
Get:5 http://archive.raspberrypi.org wheezy Release [7,224 B]
Get:6 http://mirrordirector.raspbian.org wheezy Release [14.4 kB]
Get:7 http://archive.raspberrypi.org wheezy/main armhf Packages [15.9 kB]
Get:8 http://mirrordirector.raspbian.org wheezy/main armhf Packages [7,414 kB]
Get:9 http://webmin.mirror.somersettechsolutions.co.uk sarge/contrib armhf Packa  ges [1,218 B]
Ign http://archive.raspberrypi.org wheezy/main Translation-en_GB
Ign http://archive.raspberrypi.org wheezy/main Translation-en
Ign http://webmin.mirror.somersettechsolutions.co.uk sarge/contrib Translation-e  n_GB
Ign http://webmin.mirror.somersettechsolutions.co.uk sarge/contrib Translation-e  n
Hit http://raspberrypi.collabora.com wheezy Release.gpg
Hit http://raspberrypi.collabora.com wheezy Release
Hit http://raspberrypi.collabora.com wheezy/rpi armhf Packages
Ign http://raspberrypi.collabora.com wheezy/rpi Translation-en_GB
Ign http://raspberrypi.collabora.com wheezy/rpi Translation-en
Get:10 http://download.webmin.com sarge Release.gpg [189 B]
Hit http://mirrordirector.raspbian.org wheezy/contrib armhf Packages
Hit http://mirrordirector.raspbian.org wheezy/non-free armhf Packages
Hit http://mirrordirector.raspbian.org wheezy/rpi armhf Packages
Ign http://mirrordirector.raspbian.org wheezy/contrib Translation-en_GB
Ign http://mirrordirector.raspbian.org wheezy/contrib Translation-en
Ign http://mirrordirector.raspbian.org wheezy/main Translation-en_GB
Ign http://mirrordirector.raspbian.org wheezy/main Translation-en
Ign http://mirrordirector.raspbian.org wheezy/non-free Translation-en_GB
Ign http://mirrordirector.raspbian.org wheezy/non-free Translation-en
Ign http://mirrordirector.raspbian.org wheezy/rpi Translation-en_GB
Ign http://mirrordirector.raspbian.org wheezy/rpi Translation-en
Get:11 http://download.webmin.com sarge Release [9,542 B]
Get:12 http://download.webmin.com sarge/contrib armhf Packages [1,218 B]
Ign http://download.webmin.com sarge/contrib Translation-en_GB
Ign http://download.webmin.com sarge/contrib Translation-en
Fetched 7,475 kB in 47s (157 kB/s)
Reading package lists... Done
Quite a list isn’t it.
Now we can do the awesome and run our webmin install via apt-get .. finally haha!
pi@raspberrypi ~ $ sudo apt-get install webmin
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  apt-show-versions libapt-pkg-perl libauthen-pam-perl libio-pty-perl
  libnet-ssleay-perl
The following NEW packages will be installed:
  apt-show-versions libapt-pkg-perl libauthen-pam-perl libio-pty-perl
  libnet-ssleay-perl webmin
0 upgraded, 6 newly installed, 0 to remove and 27 not upgraded.
Need to get 22.1 MB of archives.
After this operation, 139 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://download.webmin.com/download/repository/ sarge/contrib webmin all 1  .660 [21.6 MB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libnet-ssleay-per  l armhf 1.48-1 [317 kB]
Get:3 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libauthen-pam-per  l armhf 0.16-2 [31.2 kB]
Get:4 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libio-pty-perl ar  mhf 1:1.08-1 [39.3 kB]
Get:5 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libapt-pkg-perl a  rmhf 0.1.26+b1 [80.9 kB]
Get:6 http://mirrordirector.raspbian.org/raspbian/ wheezy/main apt-show-versions   all 0.20 [34.9 kB]
Fetched 22.1 MB in 21s (1,041 kB/s)
Selecting previously unselected package libnet-ssleay-perl.
(Reading database ... 72353 files and directories currently installed.)
Unpacking libnet-ssleay-perl (from .../libnet-ssleay-perl_1.48-1_armhf.deb) ...
Selecting previously unselected package libauthen-pam-perl.
Unpacking libauthen-pam-perl (from .../libauthen-pam-perl_0.16-2_armhf.deb) ...
Selecting previously unselected package libio-pty-perl.
Unpacking libio-pty-perl (from .../libio-pty-perl_1%3a1.08-1_armhf.deb) ...
Selecting previously unselected package libapt-pkg-perl.
Unpacking libapt-pkg-perl (from .../libapt-pkg-perl_0.1.26+b1_armhf.deb) ...
Selecting previously unselected package apt-show-versions.
Unpacking apt-show-versions (from .../apt-show-versions_0.20_all.deb) ...
Selecting previously unselected package webmin.
Unpacking webmin (from .../archives/webmin_1.660_all.deb) ...
Processing triggers for man-db ...
Setting up libnet-ssleay-perl (1.48-1) ...
Setting up libauthen-pam-perl (0.16-2) ...
Setting up libio-pty-perl (1:1.08-1) ...
Setting up libapt-pkg-perl (0.1.26+b1) ...
Setting up apt-show-versions (0.20) ...
** initializing cache. This may take a while **
Setting up webmin (1.660) ...
Webmin install complete. You can now login to https://raspberrypi:10000/
as root with your root password, or as any user who can use sudo
to run commands as root.
As you can see from the above the apt-get install does EVERYTHING. Previously when using a tar file we would have had to made some changes and settings along the way.
to get webmin root password 
 sudo grep your_username /etc/shadow |cut -f2 -d:
copy the encrypted password
sudo nano /etc/webmin/miniserv.users
paste the password ,example like this root:$1$e/9mjoasd$asdasljjwynSD42

Login the webmin with https://raspi:10000 with user root, password is raspberry(or your username pi password)

for mapping the external hardisk 
$ sudo blkid
$ get the hardisk id

$ sudo nano /etc/fstab
(paste this)
UUID=8A2CF4F62CF4DE5F   /media/wd       ntfs-3g rw,suid,dev,exec,auto,nouser,async,umask=000 0 0


$ sudo nano /etc/samba/smb.conf
(add or edit)

=====smb.conf======
socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=131072 SO_SNDBUF=131072

force user = root
security = user
create mode= 0660
directory mode = 0771

[KIDUNG]
        path = /media/wd/IT
        writeable = yes
        valid users = @it
        create mode = 0660
        directory mode = 0771

[FILEBERSAMA]
        path = /media/wd/share
        writeable = yes
        valid users = @users
        create mode = 0660
        directory mode = 0771

[LAGU]
        path = /media/wd/mp3
        writeable = yes
        valid users = @users
        create mode = 0660
        directory mode = 0771

==end of smb.conf ==


add group samba = IT, users


this is directory permission of my external hardisk
ls -al /media/wd/
total 84
drwxrwxrwx 1 cubie cubie 49152 Jul 31 16:53 .
drwxr-xr-x 3 root  root   4096 Jul 31 20:06 ..
drwxrwxrwx 1 cubie cubie  4096 Jul 31 17:23 mp3
drwxrwxrwx 1 cubie cubie     0 Jul 31 17:42 share
drwxrwxrwx 1 cubie cubie 24576 Jul 31 19:21 video



Senin, 28 Juli 2014

BACKUP RASPBERRY TO GOOGLE DRIVE -CLOUD

Back up your Pi to your Google drive

Being able to back up data to the cloud is very useful. It means that even if your Raspberry Pi dies or your SD card gets corrupted, your data is still safe. It also means that you can access your data from any where in the world.
If you have a Google drive account, you can use the grive program to sync a folder on your Pi with your Google drive.

Install grive

Start by making sure that your Pi's software is up to date, install some additional packages, and get the code using git:
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install git cmake build-essential libgcrypt11-dev libjson0-dev libcurl4-openssl-dev libexpat1-dev libboost-filesystem-dev libboost-program-options-dev binutils-dev libboost-test-dev libqt4-dev libyajl-dev

$ git clone git://github.com/Grive/grive.git
Modify /home/pi/grive/libgrive/src/drive/State.cc to resolve some compiler problems. Lines that use the Add() method need to contain a cast to the correct size of integer. The expression "(boost::uint64_t)" must be added to lines 251, 252 and 256. The updated code should look like this:
void State::Write( const fs::path& filename ) const { Json last_sync ; last_sync.Add( "sec", Json((boost::uint64_t)m_last_sync.Sec() ) ); last_sync.Add( "nsec", Json((boost::uint64_t)m_last_sync.NanoSec() ) ); Json result ; result.Add( "last_sync", last_sync ) ; result.Add( "change_stamp", Json((boost::uint64_t)m_cstamp) ) ; std::ofstream fs( filename.string().c_str() ) ; fs << result ; }
Now you need to configure the make files by running cmake (note the '.' after the cmake command) and compile the source code by running make:
$ cd ./grive $ cmake . $ make
You need to create a directory where you can store files that you want to be syncronized with your Google drive, and copy the grive executable to that directory.
$ mkdir ~/google_drive $ cp ./grive/grive ~/google_drive
make sure all directory and files owned by user pi $ sudo chown pi:pi -R google_drive
The first time you execute grive, you need to use the -a option in order to authenticate with Google. You must be logged into your Google account from your Pi for this to work. If you're logged into your Google account on a PC or laptop, log out, and then log in again using a browser on your Pi. Once you've done this, change to your Google drive directory and run grive.
$ cd ../google_drive/ $ ./grive -a
A link will be printed in the terminal window. Copy the link and paste it in a browser. A page on google.com will appear with a long code that you need to enter in the terminal window. Pasting the code didn't work for me, so you may have to type it in. The authentication process will then take place, and your Pi will sync for the first time. Before you do this, check to see how much space you've used up on your Google drive, and check to see if there's enough space on your Pi's SD card.

Running a backup to the cloud

If you've got this far, you should now be able to sync files and folders in /home/pi/google_drive with your Google drive. The next step is to backup the data on your Pi and upload it to your Google drive.
The following bash script creates a tar archive containing my home directory. I've made sure not to include the Google drive directory in this archive, otherwise previous archives would be included in the backup. The second line compresses the archive into a .tar.gz file. The file is moved to the google drive directory before running grive to upload the new archive to your Google drive on the internet. I've used the date command to embed the current date in the file name.
#!/bin/bash tar -cvzf backup_$(date +%y.%m.%d).tar /home/pi --exclude="/home/pi/google_drive" gzip backup_$(date +%y.%m.%d).tar mv backup_$(date +%y.%m.%d).tar.gz ./google_drive cd ./google_drive ./grive cd ..
Save this code as grive_backup.sh, and make it executable using the chmod +x command.
When you run the script, it may appear to hang while gzip is running. This may take a few minutes depending on how much data there is in your home directory.

Running a backup script as cron job

This script can eaily be automated by creating an entry in the crontab file. Linux uses the crontab file to schedule tasks. Entries are made in the format
minute hour day_of_month month day_of_week username command
Use this command to open crontab:
$ sudo nano /etc/crontab
...and then add this line:
00 03 * * * pi /home/pi/grive_backup.sh
This specifies that you want to run grive_backup.sh at 3.00am every day, and it should be run as user pi. Linux should automatically detect that your crontab file has been modified, so there's no need to reboot.
Your SD card will fill up after a few days or weeks, so it's best to remove old backups. You can do this by adding the following line to the script above:
rm backup_$(date --date="7 days ago" +%y.%m.%d).tar.gz
This time the date command is being used to create a date from 7 days ago, so a back up file from 7 days ago will be deleted.

Kamis, 24 Juli 2014

Set Up Apache Virtual Hosts cubieboard/raspberry

Set Up Apache Virtual Hosts cubieboard/raspberry

What the Red Means

The lines that the user needs to enter or customize will be in red in this tutorial! The rest should mostly be copy-and-pastable.

About Virtual Hosts

Virtual Hosts are used to run more than one domain off of a single IP address. This is especially useful to people who need to run several sites off of one virtual private server. The sites display different information to the visitors, depending on with which the users accessed the site.There is no limit to the number of virtual hosts that can be added to a VPS.

Set Up

The steps in this tutorial require the user to have root privileges. You can see how to set that up in the here Initial Server Setup. You can implement whatever username suits you.
Additionally, you need to have apache already installed and running on your virtual server If this is not the case, you can download it with this command:
sudo apt-get install apache2

Step One— Create a New Directory

The first step in creating a virtual host is to a create a directory where we will keep the new website’s information.
This location will be your Document Root in the Apache virtual configuration file later on. By adding a -p to the line of code, the command automatically generates all the parents for the new directory.
sudo mkdir -p /var/www/example.com/public_html
You will need to designate an actual DNS approved domain, or an IP address, to test that a virtual host is working. In this tutorial we will use example.com as a placeholder for a correct domain name.
However, should you want to use an unapproved domain name to test the process you will find information on how to make it work on your local computer in Step Seven.

Step Two—Grant Permissions

We need to grant ownership of the directory to the user, instead of just keeping it on the root system.
 sudo chown -R $USER:$USER /var/www/example.com/public_html 
Additionally, it is important to make sure that everyone will be able to read our new files.
 sudo chmod -R 755 /var/www
Now you are all done with permissions.

Step Three— Create the Page

Within our configurations directory, we need to create a new file called index.html
sudo nano /var/www/example.com/public_html/index.html
We can add some text to the file so we will have something to look at when the IP redirects to the virtual host.
<html>
  <head>
    <title>www.example.com</title>
  </head>
  <body>
    <h1>Success: You Have Set Up a Virtual Host</h1>
  </body>
</html>
Save and Exit

Step Four—Create the New Virtual Host File

The next step is to set up the apache configuration. We’re going to work off a duplicate—go ahead and make a copy of the file (naming it after your domain name) in the same directory:
 sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/example.com

Step Five—Turn on Virtual Hosts

Open up the new config file:
 sudo nano /etc/apache2/sites-available/example.com
We are going to set up a virtual host in this file.
The first step is to insert a line for the ServerName under the ServerAdmin line.
  ServerName example.com 
The ServerName specifies the domain name that the virtual host uses.
If you want to make your site accessible from more than one name (for example, with www in the URL), you can include the alternate names in your virtual host file by adding a ServerAlias Line. The beginning of your virtual host file would then look like this:
<VirtualHost *:80>
        ServerAdmin webmaster@example.com
        ServerName example.com
        ServerAlias www.example.com
  [...]
The next step is to fill in the correct Document Root. For this section, write in the extension of the new directory created in Step One. If the document root is incorrect or absent you will not be able to set up the virtual host.
The section should look like this:
 DocumentRoot /var/www/example.com/public_html 
You do not need to make any other changes to this file. Save and Exit.
The last step is to activate the host, with the built in apache shortcut:
 sudo a2ensite example.com

Step Six—Restart Apache

We’ve made a lot of the changes to the configuration, and the virtual host is set up. However none of the changes that we made will take effect until Apache is restarted.
Use this command to restart apache:
 sudo service apache2 restart
You may see an error along the lines of
Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName 
The message is just a warning, and you will be able to access your virtual host without any further issues.

Optional Step Seven—Setting Up the Local Hosts

If you have pointed your domain name to your virtual private server’s IP address you can skip this step—you do not need to set up local hosts. Your virtual hosts should work. However, if want to try out your new virtual hosts without having to connect to an actual domain name, you can set up local hosts on your computer alone. For this step, make sure you are on the computer itself, not your droplet.
To proceed with this step you need to know your computer’s administrative password, otherwise you will be required to use an actual domain name to test the virtual hosts.
If you are on a Mac or Linux, access the root user (su) on the computer and open up your hosts file:
nano /etc/hosts 
If you are on a Windows Computer, you can find the directions to alter the host file on theMicrosoft site
You can add the local hosts details to this file, as seen in the example below. As long as that line is there, directing your browser toward, say, example.com will give you all the virtual host details for the corresponding IP address.
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost

#Virtual Hosts 
12.34.56.789    example.com
However, it may be a good idea to delete these made up addresses out of the local hosts folder when you are done to avoid any future confusion.

Step Eight—RESULTS: See Your Virtual Host in Action

Once you have finished setting up your virtual host, you can see how it looks online. Type your ip address into the browser (ie. http://12.34.56.789)
It should look somewhat similar to my handy screenshot
Good Job!

Creating More Virtual Hosts

To add more virtual hosts, you can just repeat the process above, being careful to set up a new document root with the appropriate domain name, and then creating and activating the new virtual host file.