diff --git a/oblig2/oblig2.md b/oblig2/oblig2.md index 43ca402a68c878121e0d9d0b7dee0b59a9996ee6..1d571b87b886ad42bf173052227245e513b8fc09 100644 --- a/oblig2/oblig2.md +++ b/oblig2/oblig2.md @@ -52,11 +52,22 @@ By giving the tables indexes, we can optimize the database for faster lookups. W ```create index on pictures (pictureid);``` -By running the code explain SELECT picture FROM pictures WHERE pictureid = '7VAgCDqHlheLtNK5wjiApbjylVj63L.jpg'; - +By running the code ```explain SELECT picture FROM pictures WHERE pictureid = '7VAgCDqHlheLtNK5wjiApbjylVj63L.jpg';``` we now see that the database only searched for 1 row to find the picture with this id. This is because this picture-id is the first picture in the database. Without indexes in the database, running the code above would take longer time and give the output "FULL SCAN" instead of "1 row" in the "estimated row count" line. <img src="./bilder/task2_w5.png"> +We also run this commands for indexing the other tables in the database as well: +``` +create index on users (name); +create index on users (userid); +create index on users (lastpostdate); +create index on posts (userid); +create index on posts (postdate); +create index on comments (postid,postdate); +create index on comments (postid); +``` + + ### 3) Docker image for webserver We make our docker file with all configs integrated, mainly because we couln't figure out how shared volumes worked. This is our dockerfile as of 13.13.2023: @@ -387,11 +398,48 @@ Our procedure for closing and opening production can be found under /prosedyrer ## Week 7 - Memcache -*Docker Method* +### Alternative 2, Docker Method -To install memcache, we +To install memcache, we used the 2. alternative, by installing a memcache docker image on our webserver, www3. By running this command, we create and starts the officiall memcache image: +``` +docker run --name=memcache -p 11211:11211 -d 192.168.130.6:5000/memcached memcached -m 128 +``` +The ip-adress is the webservers ip-adress. We give the image 128 GB RAM to use. + +First we need to install this library: +```apt-get install -y php-memcache```. Without this library, we will get an error when we make changes to the config.php file in bookface. +The we add these lines to the config.php: +``` +$memcache_server = "192.168.130.6:11211"; +$memcache_enabled = 1; +$memcache_enabled_pictures = 1; +``` +The ip-adress in the code above is webserver. + +These lines is added to the config.php in all of the webserver images(we have three). The output of the docker ps command will now look like this: +``` +root@www3:/# docker ps +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +ed5e6c6f6a0c webserver:latest "/usr/sbin/apache2ct…" 2 weeks ago Up 18 hours 0.0.0.0:32770->80/tcp, :::32770->80/tcp dwww3 +414c47dad476 webserver:latest "/usr/sbin/apache2ct…" 2 weeks ago Up 18 hours 0.0.0.0:32769->80/tcp, :::32769->80/tcp dwww2 +367938a83d1b webserver:latest "/usr/sbin/apache2ct…" 2 weeks ago Up 18 hours 0.0.0.0:32768->80/tcp, :::32768->80/tcp dwww1 +6ddb0327815d fallbackwebserver:v4 "/usr/sbin/apache2ct…" 2 weeks ago Up 18 hours 0.0.0.0:80->80/tcp, :::80->80/tcp dwwwFallback2 +659d225688ac webserver:v18 "/usr/sbin/apache2ct…" 3 weeks ago Up 18 hours 0.0.0.0:32772->80/tcp, :::32772->80/tcp cwww +d8d7e161a78a 192.168.128.23:5000/memcached "docker-entrypoint.s…" 4 weeks ago Up 18 hours 0.0.0.0:11211->11211/tcp, :::11211->11211/tcp memcache +``` +We can, by looking at the picture, verify that the docker memcache instance is indeed running. + +### Check whether the memcache setup works: + +By running this command, we get the following output: +``` +ubuntu@manager:~$ curl -s http://10.212.169.121 | grep -i memcache +<! Memcache is enabled !><! using memcache for randomized users !> +<! using memcache for randomized posters !> +<! Using memcache to display counters !> +``` +This verify that memcache is indeed working as excpected. - ## Week 8 - backup ### 1) Backup VM