Search

Kermorvant's Portfolio

Haaga-Helia Business IT student.

My own module – H5?

12.5.2017, 14:45

WORKING MODULE IS THE MOST BELOW SCRIPT!

I started to continue my own module, which i started earlier during my last lecture. Everyone in the class had to reserve a puppet module that could do something useful, for example I chose to create a module that could help our school’s programming students, by installing Java, IntelliJ/Eclipse, localhost (apache2) and to do the right configuration.

Source: http://terokarvinen.com/

my github: https://github.com/a1600567/mymodule

Once again I started my Linux by a livestick, and the first thing I did was the command: setxkbmap fi.

Last time I got to write this much to my module:

class mymodule {

exec {'apt-get update':
command => '/usr/bin/apt-get update',
refreshonly => true,
}

package {apache2:
require => Exec['apt-get update'],
ensure => 'installed',
allowcdrom => 'true',
}

package {openjdk-8-jre:
require => Exec['apt-get update'],
ensure => 'installed',
allowcdrom => 'true',
}

file {'/var/www/html/index.html':
content => "moi"
}

file {'/var/www/java':
ensure => 'directory'
}

file {'/var/www/java/index.java':
content => "public class HelloWorld {

 public static void main(string[] args) {
 System.out.println('hello, World');
 }
}
"

}


}

Everything so far installs fine, and localhost is running. BUT, when i first try to change the index.html file away from the apache2 default page, and after that changing the directory into /java, and change the index.html into index.java, It still cannot add java into there.

Screenshot_2017-05-12_12-37-39

Not right…. To be continued. Next time I’ll install eclipse/IntelliJ text editor atleast.

Report ending time: 15:38

 

15.5.2017, 12:12

Time to continue my module, after a super stressful work week.

I decided to delete the file scripts for now, because first i want to get an IDE to work. I’m planning to install IntelliJ, or Eclipse, because those are the main  programming environments for our programming students.

It seems that if i want to install one of those, it has to be downloaded and extracted as a .tar file…

Time flew and I started to work with a bash file, then I curiously tried to do a command: sudo-apt get install eclipse and it started to install everything!? I thought this can’t be true but it did.. and it works!

Screenshot_2017-05-15_09-55-42.png

This is how it looks when you open eclipse.

Now it was time to put the eclipse installment script to my module, and my module now looks like this:

class mymodule {

exec {'apt-get update':
command => '/usr/bin/apt-get update',
refreshonly => true,
}

package {apache2:
require => Exec['apt-get update'],
ensure => 'installed',
allowcdrom => 'true',
}

package {openjdk-8-jre:
require => Exec['apt-get update'],
ensure => 'installed',
allowcdrom => 'true',
}

package {eclipse:
require => Exec['apt-get update']
ensure => 'installed',
allowcdrom => 'true'

file {'/var/www/html/index.html':
content => "moi"
}

}

Report ending time: 13:16

 

Report starting time: 23:06

After a long day, and interviewing some programming students, I realized that they don’t even use localhost to do programming. They use eclipse or IntelliJ, and they run their java code in that platform. I still decided to keep localhost and apache if they want to implement some HTML code, and later add some java to it? (No idea if it’s possible though.).

Again I started xubuntu with livestick, and wrote setxkbmap fi and sudo apt-get update to get started! I also installed puppet, because I usually just create the manifests and init.pp and copy-paste my old puppet code from this report.

Now it was time to think about how to open eclipse after the installation of java and all the other required for this module. I tried to search the internet until I asked my classmate who is doing a module about music programs, and the module opens them all after the installations. So I asked him and he linked me to his github, and I found out that it has to be done as exec.

Source: https://github.com/PEELO1994/PEELO

So i put the exec script to my module, cleaned the scripts a little bit, fixed some typos and this is how my code looks and it believe me or not, actually works! It installs all the required things, and after that it opens the eclipse, where the student can setup it with couple of clicks. I was too afraid to try to configure the path locations for eclipse, because it’s mainly done by the students, and they might feel more comfortable by being able to choose the locations themselves, when starting a new java project. Eclipse is a graphical (not terminal looking) IDE program, so thats why.

class mymodule {

        exec {'apt-get update':
        command => '/usr/bin/apt-get update',
        refreshonly => true,
                }

        package {apache2:
                require => Exec['apt-get update'],
                ensure => 'installed',
                allowcdrom => 'true',
                }

        package {openjdk-8-jre:
                require => Exec['apt-get update'],
                ensure => 'installed',
                allowcdrom => 'true',
                }

        package {eclipse:
                require => Exec['apt-get update'],
                ensure => 'installed',
                allowcdrom => 'true',
                }

        file {'/var/www/html/index.html':
                content => "Working localhost to write HTML code besides java",
                }

        exec { 'OpenEclipse':
                command => '/usr/bin/eclipse',
                require => Package['eclipse'],
                }
}

I also cleaned the outlook of the code a little bit, so it’s easier to recognize the main things.

Now it’s getting quite late, and tomorrow is the last day to do some final scripts. I was thinking about doing some shell scripts to bash open this module, and copy it from git.

Report ending time: 23:54

 

16.5, 13:19

Today I came to school to finish my module, I was accompanied with my classmate Leo Jääskeläinen. I can focus much better in school. So now I’m pretty much done with my module, except that I want to create a shell script combined with git, and it would also run my module.

I started with the commands: setxkbmap fi to get the nordic alphabets, and after that I continued by installing puppet, git and by doing sudo apt-get update.

I created a new git repository, and cloned it straightaway. That’s the repository where I’m going to put my module to.

Screenshot_2017-05-16_10-25-53.png

Now before I’m going to push something there, I’ll handle the shell script first.

Now i created a shell script that will run sudo apt-get update, install puppet, copy my module to the right puppet directory and run my module.

#!/bin/bash

sudo apt-get update
sudo apt-get install -y puppet
sudo cp ./javamodule /etc/puppet/modules/asennusmoduuli
sudo puppet apply -e 'class {asennusmoduuli:}'

Oh, and I also changed the names to be more unique.

Screenshot_2017-05-16_11-13-59.png

I also pushed everything to git. Now it’s time for a small lunch.

After a lunch I started my linux again to run my scripts from the scratch. I wrote setxkbmap fi, sudo apt-get update and installed git with the command sudo apt-get install git.

After that I cloned my git repository from terminal and ran my script.

It takes quite a long time to run the script, and it never finishes it after eclipse pops. The script is over after I close eclipse. Then I realized that I had to put a & mark to one of the lanes in the openeclipse exec script, in my init.pp. Now the part looks like this:

exec { 'OpenEclipse':
 command => '/usr/bin/eclipse &',
 require => Package['eclipse'],
}

I also decided to modify my shell script to open the localhost after it starts the puppet module. So I added firefox ‘localhost’.  My final shell script looks like this now:

#!/bin/bash

sudo apt-get update
sudo apt-get install -y puppet
sudo cp -r ./javamodule /etc/puppet/modules/asennusmoduuli
sudo puppet apply -e 'class {asennusmoduuli:}'
firefox 'localhost'

And I also customized my init.pp, the content for my file to be more instructive for the users when the firefox, localhost pops. My final init.pp looks like this:

class asennusmoduuli {

 exec {'apt-get update':
 command => '/usr/bin/apt-get update',
 refreshonly => true,
 }

 package {apache2:
 require => Exec['apt-get update'],
 ensure => 'installed',
 allowcdrom => 'true',
 }

 package {openjdk-8-jre:
 require => Exec['apt-get update'],
 ensure => 'installed',
 allowcdrom => 'true',
 }

 package {eclipse:
 require => Exec['apt-get update'],
 ensure => 'installed',
 allowcdrom => 'true',
 }

 file {'/var/www/html/index.html':
 content => "Working localhost to write HTML code besides java. You can find the index.html from the path /var/www/html/index.html",
 }

 exec { 'OpenEclipse':
 command => '/usr/bin/eclipse &',
 require => Package['eclipse'],
 }
}

So.. The ritual to run my module is to clone my github, go to mymodule directory and start the shell script with the command bash start.sh

Screenshot_2017-05-16_14-32-38.png

This is how it looks!

My report this time is quite clumsy because I was focusing very hard to do the module, instead of writing this report. But I tried to write as “Live” as I could.

Thanks also for Tero Karvinen our teacher for these courses, and Leo Jääskeläinen and Ilari Huura for helping me with some commands for my module, and working together in the same classroom.

This is probably my last Linux report and I really really really suggest EVERY IT-student to join these courses if you are a student in Haaga-Helia University of Applied Sciences.

I joined these courses with pretty much zero knowledge of Linux, and I’ve learned so much!

Link to my github again: https://github.com/a1600567/mymodule

Report ending time: 17:40

 

 

Advertisements

H4 – Linux server management. vol 4

Report starting time: 12:42

This report is done with 4 classmates, in the lab class 5005.

I started by booting Xubuntu by a livestick, and the first thing i did, was to open terminal and to write the usual command: setxkbmap fi to get the nordic alphabets, (ä, å ö).

Now it was time for the homework:

h4. a) Master-slave. Start from an empty computer. Use the other computer as a slave, and the other computer as a master. Try that the slave gets a module from the master. Insert logs too!

Firstly, i opened our group’s github, where we wrote some material based on earlier class’s master-slave assignments. We’ve already tried master-slave during earlier class, but now it was time to do it independently(ish), with other classmates.

Our github page and notes: https://github.com/1600571/touhutiimi/tree/master/h4

SLAVE:

I decided to be a slave first, so i started by updating my packets, and to install puppet (no need to install puppetmaster as a slave..):

 $ sudo apt-get update
 $ sudo apt-get install -y puppet

Now that we have puppet installed, we don’t even necessarily need to create manifests folders etc, because the master will have them for us. (t-thank you master.)

First its good to change the hostname, so it’s easier for the master to recognize the accessing people. I changed the hostname with the command:

 $ sudo hostnamectl set-hostname kermorvant

Now my hostname is changed, and it’s time for the next changes.

The master’s hostname is apina, so now i have to change information from my puppet.conf file.

 $ sudoedit /etc/puppet/puppet.conf

Now inside the puppet.conf, I have to crate an [agent] bracket, and add the master’s hostname .local, like this:

Screenshot_2017-05-02_10-09-04

Now it was time for the real connection. First i tried to ping apina.local, but it didnt let me, because we realized that my master’s laptop was not connected to the lab connection.. After connecting to the lab computer, the ping works!

Now to connect to the apina.local, I use the command:

 $ sudo puppet agent -tdv

This had to be done 2 times. First you try to connect to master, but can’t access because the master has to sign it, after that I had to write the same command again, and we’re in!

Screenshot_2017-05-02_10-18-49

And now it was time to try the master’s own module:

 $ cd /tmp
 $ cat apinat.txt

The module was based in the /tmp/ location.

Screenshot_2017-05-02_10-20-49.png

MASTER:

Now it was time to be a master.

First i purged my puppet, and installed puppetmaster:

 $ sudo apt-get purge puppet
 $ sudo apt-get install puppetmaster

First it didn’t let me do any further installing/uninstalling commands because I had forgotten to change my hostname from the hosts file to kermorvant, it was still marked as xubuntu. To change the hostname, i fixed it like this:

 $ sudoedit /etc/hosts

Now it was time to officially start as a master.

Now it was time to change some information again in the puppet.conf file.

 $ sudoedit /etc/puppet/puppet.conf

I took the [agent] bracket away, and created a [master] bracket and inserted some new info (written below).

Screenshot_2017-05-02_10-35-04.png

I created a dns_alt_names with my hostname and .local to the end, so my upcoming slaves can connect to me.

Now before I start my puppetmaster, it’s time to do a module to a /tmp/ file, which the slaves can run with a cat command. I did the module (as usual) to the manifests folder. The order goes like this:

 $ cd /etc/puppet/modules
 $ sudo mkdir helloyk
 $ cd helloyk
 $ sudo mkdir manifests
 $ cd manifests
 $ sudoedit init.pp

class helloyk {
	file {'/tmp/helloyk.txt':
		content => "hello sla.. agents!\n",
	}	
}

After writing the module, there’s one new thing to do also. We have to go back to the original manifests folder, which is located in the /etc/puppet location, and then have to write some new script there, which is simple:

 $ cd /etc/puppet
 $ cd manifests
 $ sudo nano site.pp
class {"helloyk":}

Now it was time to start puppetmaster, with the command:

 $ sudo service puppetmaster start

Now it was time for the slave to make a connection.

Now that the slave did his agent tdv command, i had to accept the connection with the commands:

 $ sudo puppet cert list -all
 $ sudo puppet cert sign "name"

After signing the cert, the slave had to do the tdv command again for the real connection.

Screenshot_2017-05-02_11-49-37.png

As you can see, the cert is signed!

Now the slave wandered around my /tmp/, and ran the helloyk module that i did.

18261302_1179704918819574_1280467925_o.png

it works!

During my master phase, we stopped for quite a long time to wonder, why the slave couldnt connect to me. We had deleted the logs with the command

 $ sudo rm -rf /var/lib/puppet/ssl/

without realizing that it should be done when puppetmaster is stopped, not on.. So figuring that out everything started to work. We tried to restart the slave’s computer etc before that, that’s why his hostname changed too.

auth logs:

May  2 11:47:40 xubuntu sudo: pam_unix(sudo:session): session opened for user root by xubuntu(uid=0)
May  2 11:47:41 xubuntu sudo: pam_unix(sudo:session): session closed for user root
May  2 11:47:58 xubuntu sudo:  xubuntu : TTY=pts/6 ; PWD=/home/xubuntu ; USER=root ; COMMAND=/usr/bin/puppet cert sign make.tielab.haaga-helia.fi
May  2 11:47:58 xubuntu sudo: pam_unix(sudo:session): session opened for user root by xubuntu(uid=0)
May  2 11:47:59 xubuntu sudo: pam_unix(sudo:session): session closed for user root
May  2 11:48:11 xubuntu sudo:  xubuntu : TTY=pts/6 ; PWD=/home/xubuntu ; USER=root ; COMMAND=/usr/bin/puppet cert list -all
May  2 11:48:11 xubuntu sudo: pam_unix(sudo:session): session opened for user root by xubuntu(uid=0)
May  2 11:48:11 xubuntu sudo: pam_unix(sudo:session): session closed for user root
May  2 12:17:01 xubuntu CRON[9407]: pam_unix(cron:session): session opened for user root by (uid=0)
May  2 12:17:01 xubuntu CRON[9407]: pam_unix(cron:session): session closed for user root

Syslogs:

xubuntu@xubuntu:~$ tail /var/log/syslog
May 2 11:48:18 xubuntu puppet-master[9151]: Compiled catalog for make.tielab.haaga-helia.fi in environment production in 0.02 seconds
May 2 12:11:30 xubuntu dbus[3892]: [system] Activating via systemd: service name=’org.freedesktop.hostname1′ unit=’dbus-org.freedesktop.hostname1.service’
May 2 12:11:30 xubuntu systemd[1]: Starting Hostname Service…
May 2 12:11:30 xubuntu dbus[3892]: [system] Successfully activated service ‘org.freedesktop.hostname1′
May 2 12:11:30 xubuntu systemd[1]: Started Hostname Service.
May 2 12:13:07 xubuntu dbus[3892]: [system] Activating via systemd: service name=’org.freedesktop.hostname1′ unit=’dbus-org.freedesktop.hostname1.service’
May 2 12:13:07 xubuntu systemd[1]: Starting Hostname Service…
May 2 12:13:07 xubuntu dbus[3892]: [system] Successfully activated service ‘org.freedesktop.hostname1’
May 2 12:13:07 xubuntu systemd[1]: Started Hostname Service.
May 2 12:17:01 xubuntu CRON[9408]: (root) CMD ( cd / && run-parts –report /etc/cron.hourly)

Report ending time: 15:27

H3 – Linux server management. vol 3

Report starting time: 17:21

Howdy again.

It was time for the 3rd homework report.

I booted my Xubuntu from my USB memory stick (Livestick), which once again means that it’s started fresh and i need to do my rituals.

First thing i did when i booted Linux, was to open terminal and type setxkbmap fi to get the nordic alphabets (ä, ö, å).

This time i was afraid to do anything else, for example sudo apt-get update, or to install anything because it might affect the homeworks, which are:

h3. a) Package-File-Server. Install and configure some demon in package-file-server style. Do something else than the sshd’s port switch that was shown in earlier class. 

Most of the readers might know (classmates) that were at the earlier class, that we did a script using puppet, that installs SSH, switches port and shows changes done to the sshd- file. Now it was time to do something new… but what?

Inspired by at least two of my classmates, i decided to do a script that installs apache2, customizes the default index.html test page, and does the command sudo apt-get update before installing.

First it was time to install puppet to create my own module, and manifests inside that.

$ sudo apt-get update

$ sudo apt-get install puppet

$ y  (I forgot to put -y before).

$ cd /etc/puppet/modules/

$ sudo mkdir helloyael

$ cd helloyael

$ sudo mkdir manifests

$  cd manifests

$ sudo nano init.pp

Now that i started to write init.pp, i had forgotten how the template for file-package-service looks like, so i opened my shared github repository where we wrote the sshd example that we did during earlier class. The github is made by me, and two other students in the same server management course.

https://github.com/1600571/touhutiimi/blob/master/ssh_ohjeet.odt

(WARNING: EMBARASSING).

Now i know how the template looks, so i have to customize it to install apache2, run sudo-apt get update and customize the default test page.

Writing the script, I had a problem with the sudo-apt get update part, for example with the command => (path), so i found a stackoverflow link for it:

http://stackoverflow.com/questions/10845864/puppet-trick-run-apt-get-update-before-installing-other-packages

So now that the script was done, picture below:

Screenshot_2017-04-17_15-13-17

Now it was time to test it. To run the script, we use the command:

$ sudo puppet apply -e ‘class {helloyael:}’

The outcome looked like this:

Screenshot_2017-04-17_15-14-08.png

 

Now it was time to see if the page worked. To open firefox and the wanted url, which is localhost, i wrote:

firefox “localhost”

and it opened a firefox and my localhost page, and it looked absolutely right!

Screenshot_2017-04-17_15-20-38.png

b) Modules from Git. Do a script, which clones your module from git and ran for example through livestick. You can check an example from terokarvinen/nukke GitHub-varastosta.

First i started this part by installing git, with the command:

$ sudo apt-get install -y git

I had this kind of script already done in our “Touhutiimi” github folder, so it was time to use it.

Screenshot_2017-04-17_15-42-06

It looks like this. It differs a lot from the previous puppet script because this is a shell script.

This script works as an excellent starting script, which writes you these commands to your terminal automatically. It unlocks the nordic alphabets, installs puppet and git, and finally clones your github repository and goes there automatically.

Now it was time to run this script by writing:

$ bash start.sh

Yep, it works.

Screenshot_2017-04-17_15-46-02.png

Even though i already had git and puppet installed, it managed to clone my github repository, which i simply checked by writing the command ls and it was there.

Report ending time: 18:47

Sources:

http://terokarvinen.com/2017/aikataulu-%e2%80%93-palvelinten-hallinta-ict4tn022-2-%e2%80%93-5-op-uusi-ops-loppukevat-2017-p2

http://stackoverflow.com/questions/10845864/puppet-trick-run-apt-get-update-before-installing-other-packages

https://github.com/a1600567/helloyael

https://github.com/1600571/touhutiimi

Inspirations for the apache script(” 😀 “):

https://ilarihuura.wordpress.com/2017/04/17/palvelinten-hallinta-h3/

https://leojaaskelainen.wordpress.com/2017/04/14/palvelinten-hallinta-h3/

 

H2 – Linux server management. vol 2

Hello reader(s)!

This time i did my second report to my GitHub, using sudo nano. I wrote my report into a .md file.

Link: https://github.com/a1600567/helloyael/blob/master/H2.md

Check it out! Report was made 11.4.2017

All the sources used in this report can be found in the H2.md file too :).

H1 – Linux server management

Hello!

It’s time to continue further with linux, but this time more specifically with Linux server management! I decided to start writing reports to this course in English, because i want to improve myself, and possibly get some international benefits (workplace abroad etc..).

Report starting time: 18:51

Once again i started my Xubuntu Linux OS as a livestick (Try Xubuntu for free) through my USB-stick.

To get the nordic alphabets (ä, ö), i need to do a command setxkbmap fi in terminal. So i did that.

Now was the time to open my homework for this report:

h1.

a) Two resources. Make and try a module that uses at least two resources (for example. file and package).

I re-opened my terminal, and it was time to do one of my old routines, which is the command Sudo apt-get update, it’s important to update the packages before we install anything.

Now it was time to install puppet! We already used puppet in our previous class, so i installed it with the command sudo apt-get install puppet.  After installing puppet, and to make a module it was time to browse through puppet directories to the modules folder. cd /etc/puppet/modules inside the modules folder i have to make a new folder, and inside that folder i need to make a folder called manifests.

So first inside the modules folder i did sudo mkdir mymodule, after that to get inside the folder mymodule, i did the command cd mymodule and inside that folder i had to do the folder called manifests with the same command sudo mkdir manifests.

Inside the manifests folder, i did an init.pp file with the command sudoedit init.pp, but at this point i forgot what to exactly write inside.. AND i had to use two different resources.. I did some research in Google and i found a site called Puppet Cookbook, which told me how to install multiple packages with puppet. I was still lost because i had to find instructions for the file resource too.

Got it! With the file i could write for example helloworld, and with the package i can install a package. I found instructions for the file from a website called upguard.

Now i remembered about the /tmp/ path and content => “text” and i was ready to write.

Screenshot_2017-04-03_16-28-33

The code looks like this now. 2 different commands(?) in 1 script. separated with a } mark.

Now it was time to try the script with the command sudo puppet apply -e ‘class {mymodule:}’. And it didn’t work… The problem looked like this:

Screenshot_2017-04-03_16-36-39

It said it didn’t install. Use “allowcdrom” to override this failure. 2 times.

I googled allowcdrom in puppet, and i found a guide from stackoverflow. It was time to edit the script.

Screenshot_2017-04-03_16-40-24

Like this!

Now we did the same sudo puppet apply -e ‘class {mymodule:}’ command and it went through! Now it was time to try if the cmatrix i tried to install worked, by just writing cmatrix to terminal. (cmatrix was my first “funny” installation to terminal, which i installed during the earlier Linux course as an assignment).

Tadaa! Cmatrix works!

Screenshot_2017-04-03_16-42-19

And last, but not least it was time to try the file resource. I did the command cat /tmp/mymodule and the content text works!!

Screenshot_2017-04-03_16-48-24

b) Watch a video about puppet, and other similar program. This was my homework, because i didn’t attend an IT exhibition..).

So.. it was time to compare Puppet with an other similar program, and i bumped into quite many similar programs called Chef, Salt and Ansible. Now was the time to watch the video and compare all 3 of them with puppet.

Quite amazing, all of them. I discovered a funny fact, that Puppet was developed in Ruby!

Puppet is an open source configuration management tool. Works great as a master client program. Puppet is the oldest of these!

Salt was written in Python, and it’s motivated to enable high speed communication with large amount of systems. (At least according to them). Salt is highly scalable and it has a syndicate feature where one master manages multiple masters.

Ansible was written in Python and uses SSH to communicate. It is also highly scalable.

Chef is in a ruby dsl too. Chef uses a logical chef workstation to manage chef servers.

Report ending time: 20:19

Sources:

http://terokarvinen.com/2017/aikataulu-%e2%80%93-palvelinten-hallinta-ict4tn022-2-%e2%80%93-5-op-uusi-ops-loppukevat-2017-p2

https://www.puppetcookbook.com/posts/creating-a-symlink.html

https://www.puppetcookbook.com/posts/install-multiple-packages.html

https://www.upguard.com/getting-started-with-puppet-labs

http://www.tecmint.com/20-funny-commands-of-linux-or-linux-is-fun-in-terminal/

http://serverfault.com/questions/667804/installing-packages-with-dependencies-using-puppet

Muistiinpanoja Labraharjoitukseen

Perus toimenpiteet taas:

setxkbmap fi

sudo apt-get update

sudo apt-get install apache2

sudo apt-get install ssh

SSH:

sudo ssh -l

passwd (HYVÄ SALASANA)

sudo ssh xubuntu@localhost

sudo adduser username (HYVÄ SALASANA)

sudo mkdir public_html

sudo nano index.html

sudo a2enmod userdir

Tulimuuri:

sudo ufw allow 22/tcp

sudo ufw allow 80/tcp

sudo ufw enable

Sudo oikeudet:

Sudo adduser username adm

usermod -aG sudo username

H5 – Linux pt. 5

Raportin aloitusaika: 21:38

Aloitin tekemään Linux kotitehtäviä käynnistämällä Xubuntun livetikulta. Xubuntun käynnistyttyä avasin ensimmäiseksi terminaalin ja kirjoitin komennon: setxkbmap fi jotta sain ääkköset päälle. Tämän jälkeen avasin opettajani Tero Karvisen laatimat läksyt osoitteesta terokarvinen.com

a) Ota käyttöön oma virtuaalipalvelin (VPS).

Ensimmäinen tehtävä oli ottaa käyttöön oma virtuaalipalvelin.

Olimme tunnilla tutustuneet github student developer packiin josta saamme kunnolliset eväät IT:n opiskeluun, esimerkiksi oman virtuaalipalvelimen käyttöönottoon. Paketti tarjoaa sivua nimeltä DigitalOcean, johon saamme paketin kautta 50€ koodin, jotta emme tarvitsisi tehtävää varten käyttää omaa rahaa.

DigitalOceaniin rekisteröityessä joudutaan kuitenkin laittamaan korttitietomme.

Nyt oli aika tehdä oma “Droplet” eli oma virtuaalipalvelin. Valitsin Ubuntun 10€/kk maksavan palvelimen, ja maaksi Saksa (Frankfurt) joka sijaitsee lähimpänä. Sitten painettiin “Create”. Tämän jälkeen sähköpostiini ilmestyi palvelimen tiedot ja salasana.

Screenshot_2017-03-06_19-48-39.png

Tietoturvallisista syistä en halunnut kuvaan IP-osoitettani vaikka tämän poistankin myöhemmin, joten otin screenshotin “Select a region” vaihtoehdolla, jolla voimme cropata kuvan tiettyyn kohtaan.

Ennen kuin päätin ottaa yhteyttä palvelimeen kävin komennoilla sudo apt-get update, sudo apt-get install ssh ja sudo apt-get install apache2. Laittamassa kaikki tarvittavat valmiiksi.

Nyt oli aika ottaa ssh yhteys omaan virtuaalipalvelimeen! Terminaaliin otin yhteyden kirjoittamalla komennon ssh root@ip-osoite jonka jälkeen pyydettiin vaihtamaan salasana. Salasanan vaihdettua olin vihdoin rootissa!

Screenshot_2017-03-06_20-03-41

(Foliohattuni päätti taas jättää IP:n pois.)

Sitten kävin laittamaan palomuurin asetukset kuntoon komennoilla sudo ufw allow 22/tcp jonka jälkeen komento sudo ufw enable.

Nyt oli aika tehdä palvelimeeni uusi käyttäjä! Tein käyttäjän komennolla sudo adduser yael. Tämän jälkeen käyttäjälle piti luoda salasana. Salasanan laitettuani laitoin käyttäjäni adm ja admin ryhmiin komennoilla sudo adduser yael adm ja sudo adduser yael admin.

Nyt lähdin ssh yhteydestä pois komennolla exit ja oli aika kokeilla ottaa ssh yhteys käyttäjällä. Tehtiin komento yael@IP-osoite ja salasana ja pääsin sisään!

Nyt oli aika ottaa root login pois päältä! mentiin komennolla sudoedit /etc/ssh/sshd_config “valikkoon” josta pystyimme laittamaan root loginin pois päältä laittamalla root loginin kohdalle “no” mikä oli oletuksena “yes”. Nyt painettiin exit, ja kokeiltiin mennä roottina sisään. Jostain syystä pääsin edelleen sisään ja yritin pohtia tilannetta varmaan 15 minuuttia tekemällä uudestaan komennon sudo apt-get update. Ei vieläkään auttanut!!. Kävin jopa uudestaan tarkastamassa että olinko typonnut “no” väärin.. En ollut. Sitten tehtiin komento sudo srvice ssh restart ja exit. Kokeiltiin mennä roottina sisään niin vihdoin tuli denied! Kokeiltiin vielä viimeisen kerran mennä sisään userilla ja onnistui normaalisti.

Screenshot_2017-03-06_20-44-50.png

b) Laita domain-nimi osoittamaan virtuaalipalvelimeesi

c) Asenna weppipalvelin virtuaalipalvelimeesi

Nyt päästään lyömään samanaikaisesti kaksi kärpästä yhdellä iskulla! Eli b ja c tehtävä!

Nyt oli aika asentaa webbipalvelin virtuaalipalvelimeeni. Olin jo omalla userillani sisällä ssh:n kautta, joten tehtiin komento sudo apt-get install apache2.

Avattiin vähän palomuuri portteja lisää komennolla sudo ufw allow 80/tcp.

Sitten mentiin pois palvelimelta exit komennolla ja omasta terminaalista komento sudoedit /etc/hosts ja vaihdettiin oletus IP-osoitteiden alle oman virtuaalipalvelimen IP-osoite ja perään haluttu domain nimi. Laitoin yaelinjokuoma.com. Sitten painettiin CTRL + X, y ja enter. Nyt hosts tiedosto oli muokattu.

Nyt oli aika kokeilla URL:ia. Se toimii!!

Screenshot_2017-03-06_21-09-00.png

Tähän osioon minulla meni tyhmän virheen takia enemmän aikaa koska menin muuttamaan hosts kansion sisältöä omalta palvelimeltani, enkä ollut laittanut sitä ennen exitiä.

Raportin lopetusaika: 23:10

 

 

 

 

 

H4 – Linux pt. 4

Raportin aloitusaika: 22:12

Käynnistin livetikun n. klo 22:10, jonka jälkeen ensimmäinen rutiinini oli avata terminaali ja kirjoittaa komento setxkbmap fi jotta saadaan ääkköset päälle. Tämän jälkeen avasin blogini, tämän raportin kirjoittamista varten. Oli aika ottaa läksyt esille!

a) Asenna alusta lähtien LAMP.

Noniin! Oli aika tehdä samat rutiinit kuin viime Linux tunnilla, eli asentaa Apache2, MySQL ja php!

Aloitettiin tekemällä komento sudo apt-get update, jotta paketit päivittyvät. Tämän jälkeen tehtiin komento sudo apt-get install apache2, jotta saadaan apache2 asennettua. Testasin vielä varmuuden varalta komennolla firefox “http://localhost” että se varmasti toimii, ja se toimii.

apache2toimii_yael.png

Olin tässä vaiheessa myös unohtanut avata tulimuuri portit 22 ja 80, joten tein ensiksi komennon sudo ufw allow 22/tcp, jonka jälkeen komento sudo ufw allow 80/tcp ja viimeiseksi hyväksyttiin ne päälle komennolla sudo ufw enable.

tulimuuritpaalle_yael.png

Sitten jatkettiin järjestyksessä mySQL:ään, mutta unohdin tässä vaiheessa mySQL asennus komennon, sillä se oli paljon monimutkaisempi kuin vain sudo apt-get install mySQL. Niinpä päätin avata opettajamme Tero Karvisen LAMP asennus ohjeet hänen kotisivuiltaan:

http://terokarvinen.com/2016/mysql-install-and-one-table-database-sql-crud-tutorial-for-ubuntu

Noniin löytyipäs. Komento on siis sudo apt-get -y install mysql-server mysql-client.
Asennuksen jälkeen ohjelma pyytää asettamaan mySQL rootille salasanan, ja toistetaan.

Sitten kirjaudutaan sisään komennolla: mysql -u root -p, jonka jälkeen kysytään salasanaa, ja tadaa! Sisällä ollaan.

mysqlasennettu_yael.png

Noniiiin, nyt on siis mySQL asennettu myös. Tarvittaessa oltaisiin voitu nopeasti luoda tietokanta esim. komennolla: CREATE DATABASE opiskelija CHARACTER SET utf8; mutta niin ei ohjeissa kysytty.

Sitten oli viimeisen, eli php:n vuoro!

Aloitin asentamalla PhP:n komennolla: sudo apt-get install apache2 libapache2-mod-php php-mysql, mutta jostain syystä ei tapahtunut mitään..? Sitten tajusin että olinkin vahingossa vieläkin mySQL:n sisällä, joten kirjoitin komennon exit jonka jälkeen normaalissa tilassa kirjoitettiin sama, ja asennus onnistui.

Nyt kun asennus oli tehty, oli aika tehdä php:n aktivoimis rutiinit. Etsittiin php:n aktivoimis ohjeet Tero Karvisen nettisivuilta:

http://terokarvinen.com/2016/read-mysql-database-with-php-php-pdo

Aloitettiin komennolla: sudo a2enmod userdir, jonka jälkeen komento sudoedit /etc/apache2/mods-available/php7.0.conf, ja laitettiin # merkki viimeisten rivien alkuun, jotta php aktivoituu. Sitten restartattiin apache2 komennolla: sudo service apache2 restart jotta saatiin asetukset voimaan.

Tässä vaiheessa alkoi tilanne minulle monimutkaistua. Tehtiin ensiksi komento echo ‘<?php print(2+2+”\n\n”); ?>’> index.php. Tämä komento ilmeisesti teki minulle index.php tiedoston, johon kyseisen php koodikin oli liitetty mukaan. Kävin kuitenkin avaamassa index.php tiedoston kirjoittamalla komennon sudo nano index.php, ja lisäsin html pohjan mukaan, vaihdoin tittelin phptest, laitoin <h1> MOI? <h1> ja siirsin php koodinpätkän <p></p> sisään niin kuin tunnillakin oli esimerkeissä. Tämän jälkeen piti kyseinen sivu avata, joten etsin IP osoitteeni komennolla: hostname -i. Kirjoitin nettiosoite kenttään IP osoitteeni/~xubuntu koska se on automaattinen livetikun käyttäjän nimi. Tadaa! Toimii.

huhhuhmikatyomaa_yael.png

d) Laita liitteeksi tai linkiksi raporttiisi tällä komenolla kerätty log.txt:

tail /var/log/syslog /var/log/auth.log /etc/lsb-release /var/log/apache2/*.log /proc/uptime >log.txt

Yritin terminaalin kautta avata kyseistä texti tiedostoa, mutta en meinannut millään onnistua johtuen luultavasti väsymyksestä, joten menin graafisesti home kansiosta avaamaan kyseisen textitiedoston.

logtxt_yael.png

Raportin lopetusaika: 23:50

H3 – Linux pt. 3

Raportin aloitusaika: 19:55

Käynnistin linuxin livetikulta asentamatta kello 19:55, ja ensimmäinen asia jonka tein oli avata terminaali ja laittaa ääkköset päälle komennolla setxkbmap fi. Tämän jälkeen otin esille h3. läksyt.

h3. Asenna apache2 weppipalvelin. Lataa jokin sivu omalta palvelimeltasi, vaikka testisivu.Etsi sivulatauksesta syntynyt lokirivi.

Aluksi en ollut varma että onko kyse vain simppelistä sudo apt-get install apache2 komennosta, mutta löysin selkeät ohjeet opettajani Tero Karvisen nettisivuilta. Päätin etsiä tämän koska olen ennenkin löytänyt sivulta hyviä ohjeita.

Apache2 ohjeen sivu: http://terokarvinen.com/2008/install-apache-web-server-on-ubuntu-4

Aluksi tehtiin tuttu komento, eli sudo apt-get update, jonka jälkeen ohjeiden mukaisesti sudo apt-get install apache2. Kun asennus oli valmis, käynnistin sen, mikä oli mielestäni testisivu, eli oletussivu kun avataan localhost. Käynnistys tehtiin komennolla: firefox “http://localhost&#8221;, jonka jälkeen eteen ilmestyi tämännäköinen sivu:

testisivuu.png

 

Nyt piti etsiä logit avatusta testisivusta.

Kokeilin aluksi etsiä normaalisti tekemällä komennot cd /var/log -> ls -> cat auth.log mutta sieltä löytyi vain tiedot apache2:n asennuksesta.

Tämän jälkeen kokeilin sitten mennä syvemmälle apache2:een komennolla cd /var/log/apache2 ja uudelleen ls -> cat auth.log. Jostain syystä tämä ei toiminut. Sitten googletin ohjee että miten avataan apache2 logit, josta löysin komennon sudo grep GET /var/log/apache2/access.log.

Tieto löytyi sivulta: https://www.a2hosting.com/kb/developer-corner/apache-web-server/viewing-apache-log-files googlettamalla “how to see apache2 logs”.

Komennon tehtyä, sain mielestäni logit näkyviin testisivusta!

apache2logs.png

Raportin lopetusaika: 20:21

Create a free website or blog at WordPress.com.

Up ↑