Recents

Tuesday, July 7, 2015

ownCloud 8.0.4 (NGiNX+MariaDB+SSL) di CentOS 7

Assalamu'alaikum.wr.wb.

Halo all, ketemu lagi dengan blog saya yang insya allah postingan saya bermanfaat semua untuk kalian semua yang membaca hahaha. Yuk masuk ke materi disini saya akan posting materi Cloud Storage menggunakan ownCloud 8.0.4. OwnCloud sama seperti google drive, dropbox, dan lain-lain namun dia bersifat open-source. Penasaran? Langsung saja ke materi.



A. Penjelasan Singkat

Saat ini layanan Cloud Storage sudah banyak bertebaran di internet, dari yang gratisan hingga berbayar. Contoh yang populer saat ini adalah Dropbox yang menyediakan space sebesar 2GB secara cuma-cuma yang bisa diupgrade hingga maksimal 18GB, kemudian ada lagi Google Drive, SugarSync, SpiderOak dan Microsoft SkyDrive. Semuanya memiliki kelebihan dan kekurangannya masing-masing.

Nah di tutorial kali ini saya akan mencoba membuat layanan Cloud Storage sendiri yang dapat digunakan untuk pribadi, komunitas, maupun lembaga atau perusahaan. Disini saya akan menggunakan sebuah CMS (Content Management System) yang memang khusus dibuat untuk layanan Cloud Storage mirip Dropbox atau Google Drive, CMS tersebut adalah ownCloud yang dapat diunduh secara cuma-cuma dan merupakan salah satu perangkat lunak sumber terbuka (Open Source).

OwnCloud termasuk dalam kategori Infrastructure as a Service (IaaS) Layanan awan. Dengan ownCloud kita dapat menyimpan file, folder, kontak, audio, galeri foto, kalender dan dokumen lainnya. Kita juga dapat mengakses file dan melakukan sinkronisasi file yang terdapat pada server ownCloud dengan perangkat mobile, desktop, atau peramba web.


B. Bahan-bahan:

- PC/Notebook
- Server yang sudah terinstall CentOS 7
- Koneksi Internet
- Smartphone Android (Kalau gapunya juga gpp hehe)


C. Langkah Kerja

1. Atur network pada server yang digunakan, disini saya menggunakan subnet /24. Kemudian restart konfigurasi interface network.
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost ~]# service network restart
Restarting network (via systemctl):                        [  OK  ]
[root@localhost ~]# chkconfig network on



2. Matikan SELinux menjadi disable agar tidak di proteksi policy, biar bisa masuk ke sistem.
[root@localhost ~]# vi /etc/sysconfig/selinux



3. Hentikan sekaligus martikan beberapa layanan yang sedang aktif seperti, firewall, iptables.
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl stop firewalld 
[root@localhost ~]# systemctl stop iptables
[root@localhost ~]# systemctl stop ip6tables
[root@localhost ~]# systemctl disable firewalld 
[root@localhost ~]# systemctl disable ip6tables
[root@localhost ~]# systemctl disable iptables


4. Kemudian update sistem agar lebih baru.
[root@localhost ~]# yum update -y


5. Untuk menginstall LEMP (Linux, NGiNX, MariaDB, PHP-FPM) Install EPEL Repository dahulu.
[root@localhost ~]# yum install epel-release -y


6. Install package berikut ini.
[root@localhost ~]# yum -y install nginx mariadb mariadb-server php-fpm php-cli php-gd php-mcrypt php-mysql php-pear php-xml bzip2 vim


7. Matikan dan disable httpd.
[root@localhost ~]# systemctl stop httpd 
[root@localhost ~]# systemctl disable httpd 


8. Karena disini saya menggunakan MariaDB, jalankan kemudian aktifkan MariaDB.
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl enable mariadb


9. Konfigurasi MariaDB untuk membuat password root.
[root@localhost ~]# mysql_secure_installation 
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): #Tekan Enter
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password: #Masukkan Password Root
Re-enter new password: #Masukkan Password Root Kembali
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@localhost ~]#


10. Edit file PHP-FPM. Ubah user dan group menjadi nginx.
[root@localhost ~]# vi /etc/php-fpm.d/www.conf

; Start a new pool named 'www'.
[www]

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx -- Ubah jadi nginx yang sebelumnya apache
; RPM: Keep a group allowed to write in log dir.
group = nginx -- Ubah jadi nginx yang sebelumnya apache


11. Edit file nginx.conf. Hapus listen  pada line 3.
[root@localhost ~]# vi /etc/nginx/nginx.conf

    server {
        listen       80 default_server;
        listen       [::]:80 default_server; -- (Hapus bagian ini)
        server_name  _;
        root         /usr/share/nginx/html;



12. Buat direktori untuk session-path dan ubah permission.
[root@localhost ~]# mkdir -p /var/lib/php/session
[root@localhost ~]# chown nginx:nginx -R /var/lib/php/session/


13. Jalankan kemudian aktifkan NGiNX dan PHP-FPM.
[root@localhost ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost ~]# systemctl start php-fpm
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable php-fpm
[root@localhost ~]# systemctl enable nginx


14. Testing NGiNX di browser menggunakan IP Address Server.



15. Buat database untuk ownCloud di MariaDB.
[root@localhost ~]# mysql -u root -p
Enter password: -- (Masukkan Password Root)
Welcome to the MariaDB monitor.  Commands end with ; or \g.
]Your MariaDB connection id is 10
Server version: 5.5.41-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database owncloud_db;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> create user ownclouduser@localhost identified by 'ownclouduser';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all privileges on owncloud_db.* to ownclouduser@localhost identified by 'ownclouduser';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit
Bye
[root@localhost ~]#


16. Buat dahulu direktori untuk SSL, masuk ke direktori yang sudah dibuat. Buat SSL Cerficate dengan mengisi datanya.
[root@localhost ~] mkdir -p /etc/nginx/ssl
[root@localhost ~] cd /etc/nginx/ssl/
[root@localhost ssl]# openssl req -new -x509 -days 365 -nodes -out /etc/nginx/ssl/owncloud.crt -keyout /etc/nginx/ssl/owncloud.key
Generating a 2048 bit RSA private key
.............................................................+++
.......................................+++
writing new private key to '/etc/nginx/ssl/owncloud.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:ID
State or Province Name (full name) []:Jawa Barat
Locality Name (eg, city) [Default City]:Bekasi
Organization Name (eg, company) [Default Company Ltd]:TKJ
Organizational Unit Name (eg, section) []:Excellent
Common Name (eg, your name or your server's hostname) []:iman
Email Address []:root@iman
[root@localhost ssl]#


17. Ubah permission owner agar bisa menjadi read dan write.
[root@localhost ssl]# chmod 600 owncloud.crt 
[root@localhost ssl]# chmod 600 owncloud.key


18. Install wget dahulu agar bisa mendownload file ownCloud. Pindah ke direktori /opt. Download file ownCloud di direktori tersebut.
[root@localhost ~]# yum install wget -y
[root@localhost ~]# cd /opt/
[root@localhost opt]# wget -c https://download.owncloud.org/community/owncloud-8.0.4.tar.bz2


19. Ekstrak kemudian pindahkan ke direktori /usr/share/nginx/html/.
[root@localhost opt]# tar xfv owncloud-8.0.4.tar.bz2
[root@localhost opt]# mv owncloud/ /usr/share/nginx/html/


20. Pindah ke direktori html, ubah permission owner di direktori ownCloud ke nginx.
[root@localhost opt]# cd /usr/share/nginx/html/
[root@localhost html]# chown nginx:nginx -R owncloud/


21. Buat direktori data untuk direktori ownCloud dan ubah permission nginx.
[root@localhost html]# mkdir -p owncloud/data/
[root@localhost html]# chown nginx:nginx -R owncloud/data/


22. Konfigurasi virtualhost untuk ownCloud. Pindah ke direktori /etc/nginx/conf.d/.
[root@localhost html]# cd /etc/nginx/conf.d/
[root@localhost conf.d]# vi owncloud.conf


23. Copy paste konfigurasi di bawah ini.
upstream php-handler {
    server 127.0.0.1:9000;
    #server unix:/var/run/php5-fpm.sock;
}

server {
        listen 80;
        server_name 192.168.100.161; # YourIP or domain
        return 301 https://192.168.100.161;  # redirect all to use ssl

}


server {
        listen 443 ssl;
        server_name 192.168.100.161; # YourIP or domain

        #SSL Certificate you created
        ssl on;
        ssl_certificate /etc/nginx/ssl/owncloud.crt;
        ssl_certificate_key /etc/nginx/ssl/owncloud.key;

        # owncloud path
        root /usr/share/nginx/html/owncloud/;

        client_max_body_size 10G; # set max upload size
        fastcgi_buffers 64 4K;

        rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
        rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
        rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;

        index index.php;
        error_page 403 /core/templates/403.php;
        error_page 404 /core/templates/404.php;

        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }

        location ~ ^/(data|config|\.ht|db_structure\.xml|README) {

                deny all;
        }

        location / {
                # The following 2 rules are only needed with webfinger
                rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
                rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;

                rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;
                rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;

                rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;

                try_files $uri $uri/ index.php;
        }

        location ~ ^(.+?\.php)(/.*)?$ {
                try_files $1 = 404;

                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$1;
                fastcgi_param PATH_INFO $2;
                fastcgi_param HTTPS on;
                fastcgi_pass php-handler;
        }

        # Optional: set long EXPIRES header on static assets
        location ~* ^.+\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
                expires 30d;
                # Optional: Don't log access to assets
                access_log off;
        }

}


24. Restart NGiNX, PHP-FPM, MariaDB dan aktifkan apabila mesin dinyalan sudah otomatis up.
[root@localhost conf.d]# systemctl restart nginx mariadb php-fpm
[root@localhost conf.d]# systemctl enable nginx mariadb php-fpm


25. Masuk ke browser, ketik di URL http://192.168.100.161 (Your-IP-Address) maka otomatis ngedirect ke https. Apabila muncul seperti seperti gambara di bawah ini di https, jangan khawatir, pilih I Understand the Risks kemudian pilih Add Exception.




26. Pilih Get Certificate dan Confirm Security Exception.



27. Makan muncul tampilan halaman ownCloud. Terlihat website ownCloud tersecure karena sudah di konfigurasi SSL Certificate.



28. Penjelasan detail seperti gambar di bawah ini.



29. Login dengan admin dengan memasukkan password root. Untuk database, pilih MySQL/MariaDB, masukkan data database sesuai yang sudah dibuat sebelumnya dan Data Folder pindahkan ke direktori data.



30.  Tampilan ownCloud setelah login.



- Membuat User

1. Untuk membuat user, klik sebelah kanan pilih admin, maka pilih bagian user. Masukkan nama beserta password.



2. Terlihat user telah terbuat dengan nama imanagus.



3. Kemudian log out, login dengan user yang telah dibuat.



- Testing Upload File

1. Secara default upload file di limitasi hanya bisa mengupload sebesar 513MB. Disini saya menggunakan admin untuk mengupload file.



2. Nah solusinya saya temukan, karena saya menggunakan PHP-FPM, ubah limitasi file menjadi 513MB menjadi 4GB.
[root@localhost ~]# vi /usr/share/nginx/html/owncloud/.user.ini 



3. Restart kembali NGiNX, PHP-FPM, MariaDB.
[root@localhost conf.d]# systemctl restart nginx mariadb php-fpm


4. Refresh di browser, terlihat max upload menjadi 4GB.



5. Disini saya akan coba upload file .ISO.



6. Tunggu proses hingga selesai, setelah selesai maka akan ada di tampilan folder.



- Testing Menggunakan Smartphone Android


1. Install ownCloud dahulu dari Google Play Store, kemudian masukkan IP Address Server pada URL, dan user yang sudah dibuat kemudian Connect.



2. Tampilan ownCloud di Android setelah login.



3. Buat file .txt buat testing, disini saya mulai dari browser.



4. Terlihat file gan.txt telah terbuat.



5. Cek apakah di android ada, terlihat ada file yang sudah dibuat melalui browser.



6. Nah disini saya balik, saya akan buat direktori dari Android. Pilih Create directory.



7. Masukkan nama, misal gan2.



8. Terlihat direktori sudah terbuat.



9. Cek di browser, terlihat direktori yang sudah dibuat di Android ada di browser.



Semoga Bermanfaat

Terima kasih


Wassalamu'alaikum.wr.wb.

0 komentar:

Post a Comment