Saturday 15 February 2020

Manage CentOS firewalld with an ncurses tool (GUI Firewall)

Jack Wallen shows you how to make working with CentOS 7 iptables much easier with the help of an ncurses-based GUI.

If you manage a CentOS 7 GUI-less server, you probably know that managing the firewall can be a bit of a hassle. Wouldn't it be nice if there was a handy, ncurses-based tool to make this process a bit easier? Oh wait, there is. That tool is system-config-firewall-tui. With this tool, you can easily set a service/interface/port as trusted, to allow incoming traffic to that port. Only those trusted elements will be allowed in.
Out of the box, system-config-firewall-tui isn't installed. I'm going to walk you through the process of installing the tool, enabling it to run, and then using it to open a port or two. I'll be demonstrating on CentOS7, but this tool is also available for Fedora as well. This tool directly manages iptables rules, so having a simple to use frontend for that is pretty important for some users. Don't get me wrong, system-config-firewall-tui doesn't give you the massive power of iptables (for that you really need to dive into the deep waters of iptables), but it does make the basic task of opening ports (via iptables) quick and easy.
Let's install and use system-config-firewall-tui.

Installation

The installation of the tool is pretty straightforward. Open up a terminal window and issue the command:

sudo yum install system-config-firewall-tui

 That will install the tool. However, when you go to run the command sudo system-config-firewall-tui, you'll be warned that firewalld is running, thus preventing the tool from opening. To get around this, issue the commands:
 
sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service

Usage

At this point you can issue the command:
 
sudo system-config-firewall-tui

The ncurses interface will open (Figure A). You should immediately notice that the firewall isn't enabled. Tab to the [ ] Enabled section and tap the keyboard spacebar to enable the firewall.
Figure A
Figure A
You must enable the firewall to continue.
With the firewall enabled, you can now tab down to Customize. In the new window (Figure B), you can scroll through the list of services to allow through the firewall.
Figure B
Figure B
Our list of available services.
After you've enabled your services, tab down to Forward. This is not port forwarding, rather the "Next" button. In the next screen (Figure C), you can add, edit, or remove additional ports.
Figure C
Figure C
Adding additional ports to be considered trusted.
If you tab to Add and hit Enter on your keyboard, you can then add a single port or port range, as well as a protocol. Do note, the protocol (tcp/udp) is required. Once you've taken care of that, tab to OK.
After you've added a custom port/protocol, tab down to Forward. In the resulting window (Figure D), you can list an interface as trusted.
Figure D
Figure D
Setting a trusted interface.
Enable as many interfaces as you need to be trusted and tab down to Forward. In the next screen, you can enable ports for port forwarding. Tab to Add and hit Enter on your keyboard. In the resulting screen (Figure E), enter the necessary source and destination information.
Figure E
Figure E
Setting up port forwarding.
In the next screen, you can mark ICMP types that should be rejected (Figure F). Enable each, from the list, and then tab to Forward, and tap your keyboard Enter key.
Figure F
Rejecting ICMP types.
Rejecting ICMP types.
In the next window (Figure H), you can add custom rules if necessary.
Figure H
Figure G
Adding custom rules.
Tab to Forward and hit Enter. Once you've finished with the custom rules, tab to OK and hit Enter. In the resulting screen, tab to Close and hit Enter. You will find yourself on the first screen where you can enable the firewall. Tab to OK and you will be warned that the new rules will override the current set. Tab to Yes and tap Enter on your keyboard. You've just created a new rule to the iptable chain, all with the help of a user-friendly ncurses GUI. If you issue the command sudo iptables -L you should see your new rules listed.

An easier route

Although system-config-firewall-tui isn't quite as flexible as working directly with iptables, if you're not ready to take the plunge into those deeper waters, this GUI is a much easier route to working with the firewall system on CentOS 7. Give system-config-firewall-tui a go and see if it doesn't turn into your go-to for the platform.

Source : https://www.techrepublic.com/article/how-to-easily-manage-centos-firewalld-with-an-ncurses-tool/

Tuesday 11 February 2020

Tips Memindahkan MySQL dari Server Fisik ke Server Virtual

Pagi ini saya selesai memindahkan sistem dan database MySQL Server dari sistem lama berupa server fisik IBM X Series 3400 ke Server (sementara) HP Proliant ML. Server lama menggunakan sistem operasi openSUSE 11.0 sedangkan server baru menggunakan SUSE Linux Enterprise Server (SLES) 11 JeOS yang menjadi Xen Hypervisor Guest. Sistem fisik dari HP Proliant ML ini menggunakan SLES 11 yang dioptimasi untuk menjadi Xen Hypervisor host.
Mengingat database MySQL Server ini merupakan data yang paling urgent dan digunakan oleh semua department, saya agak paranoid memindahkannya. Proses ujicoba dilakukan selama 2 minggu dengan berbagai metode antara lain :
  1. Proses Dump SQL. Cara ini gagal karena salah satu program aplikasi yaitu program aplikasi penggajian menggunakan data yang dienkripsi. Data yang dienkripsi ini menggunakan karakter dan simbol khusus yang membuat proses dumping menjadi kacau. Daripada satu group perusahaan nggak gajian lebih baik saya batalkan opsi ini 🙂
  2. Proses Sinkronisasi Database. Proses ini pernah saya lakukan sewaktu memindahkan data SQL Server ke MySQL namun cara ini juga tidak saya ambil karena prosesnya lama dan sinkronisasi hanya berjalan pada tabel, sementara view, stored procedure dan trigger tidak ikut serta.
  3. Replikasi Database. Metodenya adalah menggunakan model master & slave. Setiap perubahan data pada database master akan langsung direplikasi ke database slave. Opsi ini tidak saya ambil karena saya harus mengubah konfigurasi sistem. Opsi ini tetap menjadi pilihan jika cara lain mengalami kegagalan
  4. Manual Copy. Cara ini saya ambil karena salah satu staff IT pernah berhasil melakukannya pada salah satu group perusahaan. Metodenya menggunakan perintah rsync.

Berikut adalah detail proses pemindahan menggunakan sistem manual copy yang saya lakukan :
  1. Siapkan server baru. Install sistem operasi dalam modus seminimal mungkin, itu sebabnya saya menggunakan SLES dengan basis JeOS (Just Enough Operating System), yang bahkan lebih minimalis daripada sekedar install Text Mode
  2. Install package MySQL Database Server di server baru. Saya melakukan instalasi dari DVD SLES 11 menggunakan perintah : zypper in mysql. Instalasi dapat juga dilakukan menggunakan yast
  3. Jalankan Service MySQL Database Server di server baru. Jalankan dengan perintah : service mysql start. Pada saat pertama kali dijalankan, MySQL akan membuat struktur data untuk pertama kali. Setelah selesai, matikan kembali service MySQL tersebut dengan perintah : service mysql stop
  4. Shut down Service MySQL Induk. Kebetulan pada hari Minggu malam tidak ada jadwal kegiatan yang menggunakan database, jadi saya bisa ssh ke kantor untuk melakukan perintah service mysql stop dan kemudian melakukan rsync data ke server baru.
  5. Salin Data. Saya menggunakan perintah rsync untuk menyalin seluruh isi folder /var/lib/mysql dan kemudian memindahkannya ke server baru. Sebagai tindakan berjaga-jaga, saya menempatkan data ini tidak langsung ke /var/lib/mysql di server baru melainkan di salah satu sub folder  /srv. Sebagai catatan, saya juga menyalin file konfigurasi MySQL server lama yang ada di /etc/my.cnf.
Saat pertama kali mencoba, saya menyalin keseluruhan isi folder namun ternyata service MySQL tidak dapat dijalankan. Saya mengulang proses pemindahan namun membiarkan sub folder mysql (yang berisi tabel mysql, user, hak akses dll) tidak tersentuh. Ternyata cara ini berhasil. Service MySQL bisa dijalankan dan program aplikasi bisa mengaksesnya, hanya saja saya perlu melakukan sinkronisasi data user dan hak akses karena saya tidak menimpa folder data MySQL.
Setelah service MySQL Server berjalan dengan baik, ternyata masih ada 1 masalah tersisa, yaitu user tidak bisa menghapus atau membuat view dengan pesan : Error code 13. Googling beberapa workaround tanpa hasil, saya melakukan investigasi permission folder masing-masing database dan ternyata ada database yang hak akses Read/Writenya dipegang oleh root. Saya mengubah permission aksesnya dan masalahnya dapat terselesaikan.
Saat ini MySQL database server sudah dipergunakan sebagaimana biasanya.

Source : https://www.vavai.com/tips-memindahkan-mysql-dari-server-fisik-ke-server-virtual/