GNU/Linux >> Belajar Linux >  >> Linux

RCRON – Atur Ketersediaan Tinggi dari Pekerjaan cron

rcron adalah alat yang ampuh yang membantu administrator sistem dalam mengatur redundansi pekerjaan cron dan failover atas kelompok mesin. RCRON memastikan bahwa pekerjaan yang diinstal pada beberapa mesin hanya akan berjalan pada yang aktif setiap saat.

Kerja RCRON

Ketersediaan Tinggi menggunakan RCRON (Satu Node akan dicap sebagai Aktif dan Node Kedua akan dicap sebagai Pasif), Konfigurasi cron yang sama akan ada di keduanya, satu-satunya perbedaan adalah status aktif/pasif dalam sebuah file.

Untuk Switching otomatis status aktif/pasif, kita akan menggunakan KEEPALIVED Daemon, yang memanfaatkan sinyal keepalive untuk komunikasi antara 2 node. Setelah sinyal terkirim, jika tidak ada balasan yang diterima, tautan dianggap mati.

Dalam skenario ini, satu node ditandai sebagai master KEEPALIVED dan yang kedua sebagai cadangan KEEPALIVED. Node master akan membuat status rcron tetap aktif, dan node cadangan akan membuat status rcron tetap pasif. Segera setelah Master Node turun, ia akan mengirimkan sinyal prioritas 0 ke Backup Node, yang akan beralih dan berperilaku sebagai MASTER NODE dan secara berurutan menandai rcron sebagai aktif segera setelah master node muncul kembali, Backup Node akan beralih ke mode cadangan.

Langkah-Langkah Instalasi dan Konfigurasi RCRON Pada CentOS/RHEL

Dalam skenario Saya, saya memiliki Dua Mesin Linux, satu adalah Primer dan yang kedua adalah Slave.

Langkah1 :Aktifkan Penerusan IP di kedua Node. Edit file /etc/sysctl.conf &buat perubahan di bawah ini

net.ipv4.ip_forward = 1
# sysctl -p      ; Save the Changes without rebooting the Machine

Langkah 2 :Tambahkan Repositori EPEL Di Kedua Node.

# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm

Langkah 3 :Instal paket yang diperlukan di Kedua Node.

# yum install subversion byacc flex gcc

Langkah 4 :Jika Anda mendapatkan internet dari server proxy, setel http_proxy untuk svn.

# mkdir /root/.subversion/
# vi ~/.subversion/servers
http-proxy-exceptions = *.example.com
http-proxy-host = www.example.com
http-proxy-port = 8080
http-compression = no

Langkah 5 :Jika kita mendapatkan koneksi Internet secara langsung, lewati pengaturan proxy. Unduh perangkat lunak rcron dari SVN.

# cd /root;
# svn co http://rcron.googlecode.com/svn/trunk rcron
# cd rcron/rcron
# ./configure
# make
# make install

Langkah 6 :Buat direktori di kedua node.

# mkdir /etc/rcron/
##############################################
For MASTER SERVER Setup RCRON.conf as follows
##############################################
# vi /etc/rcron/rcron.conf
# An arbitrary name
cluster_name        = cluster
# A file containing either the word "active" or the word "passive"
state_file          = /var/run/rcron/state
# The default state in case state_file can't be read
#default_state       = active
syslog_facility     = LOG_CRON
syslog_level        = LOG_INFO
# We can tune jobs niceness/priorities 
nice_level          = 19
+++++++++++++++++++++++++++++++++++++++++++++++
For BACKUP SERVER NODE , Setup RCRON.conf as follows
+++++++++++++++++++++++++++++++++++++++++++++++
vi /etc/rcron/rcron.conf;
# An arbitrary name
cluster_name = cluster
# A file containing either the word "active" or the word "passive"
state_file = /var/run/rcron/state
# The default state in case state_file can't be read
#default_state = passive
syslog_facility = LOG_CRON
syslog_level = LOG_INFO
# We can tune jobs niceness/priorities 
nice_level = 19

Di Node Master Jalankan Perintah Di Bawah :

# mkdir /var/run/rcron
# touch /var/run/rcron/state
# echo "active" > /var/run/rcron/state

Di Node Budak Jalankan Perintah Di Bawah Ini :

# mkdir /var/run/rcron
# touch /var/run/rcron/state
# echo "passive" > /var/run/rcron/state

Langkah 7 :Sekarang instal paket keepalive di kedua node.

a) Unduh tarball sumber terbaru:

# cd /root
# wget http://cgit.luffy.cx/keepalived/snapshot/keepalived-1.2.7.tar.gz

b) Instal paket RPM BUILD:

# yum -y install rpm-build

c) Buka tar bola tar &edit file keepalived.spec.in:

# tar -zxvf keepalived-1.2.7.tar.gz
# mkdir -p /root/rpmbuild/SOURCES/
# cp /root/keepalived-1.2.7.tar.gz /root/rpmbuild/SOURCES/

ganti dari Versi 1.2.2 ke Versi:1.2.7:

# vi /root/keepalived-1.2.7/keepalived.spec.in
# yum -y install popt*
# cd /root/keepalived-1.2.7
# rpmbuild -ba keepalived.spec.in

Perintah di atas akan membuat RPM terkompilasi dari Sumber di lokasi:

/root/rpmbuild/RPMS/x86_64/keepalived-1.2.7-5.x86_64.rpm

Sekarang Instal rpm dengan perintah rpm:

# rpm -ivh /root/rpmbuild/RPMS/x86_64/keepalived-1.2.7-5.x86_64.rpm

Langkah 8 :SETUP konfigurasi yang disimpan.

Untuk node master, atur yang berikut:

# vi /etc/keepalived/keepalived.conf
vrrp_instance VI_1 { 
state MASTER 
interface eth0 
lvs_sync_daemon_inteface eth0 
virtual_router_id 31 
priority 101 
advert_int 5
vrrp_unicast_bind 172.16.243.144 
vrrp_unicast_peer 172.16.243.145 
authentication { 
auth_type PASS 
auth_pass 1111
}
notify_backup "/bin/echo passive > /var/run/rcron/state" 
notify_master "/bin/echo active > /var/run/rcron/state" 
notify_fault "/bin/echo passive > /var/run/rcron/state"
}

Untuk simpul cadangan:

# vi /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state BACKUP 
interface eth0 
lvs_sync_daemon_inteface eth0
virtual_router_id 31
priority 100 
advert_int 5 
vrrp_unicast_bind 172.16.243.145 
vrrp_unicast_peer 172.16.243.144
authentication { 
auth_type PASS 
auth_pass 1111
}
notify_backup "/bin/echo passive > /var/run/rcron/state" 
notify_master "/bin/echo active > /var/run/rcron/state" 
notify_fault "/bin/echo passive > /var/run/rcron/state"
}

Di mana “172.16.243.145” dan “172.16.243.144” adalah alamat IP Mesin Linux.

Langkah 9 :Buat Contoh entri crontab pada master dan slave.

* * * * * /usr/local/bin/rcron --conf /etc/rcron/rcron.conf echo `date` >> /tmp/output

Mulai layanan Keepalive di kedua node:

# service keepalived start ; chkconfig keepalived on

Catatan :Jika daemon yang tetap hidup terbunuh, kita akan membuat skrip crontab.

* * * * * * /root/keep-alive-monitor

Isi skrip:

# cat /root/keep-alive-monitor
#!/bin/sh
echo "test" >> /tmp/monitor;
ps -ef|grep -v grep|grep -i keepalived;
if [ $? -eq 0 ] ; then 
exit 0
else 
echo "passive" > /var/run/rcron/state;
/etc/init.d/keepalived restart;
fi


Linux
  1. Pekerjaan Cron / Tugas Otomatis

  2. Menggunakan pekerjaan CRON untuk mengunjungi url?

  3. Bagaimana cara mendapatkan daftar semua tugas cron terjadwal di mesin saya?

  1. Memecahkan Masalah Pekerjaan Cron

  2. Cara menghapus tugas cron

  3. Tambahkan pekerjaan cron di CWP

  1. Menjadwalkan Pekerjaan Cron dengan Crontab

  2. Cara Mendaftar Pekerjaan Cron di Linux

  3. Cara Menjadwalkan Pekerjaan Cron dengan Crontab