OpenShift Origin 4.0 on CentOS 6.5
by MrChoke
การ Setup Node Host
สำหรับ Node Host ก็ใช้ Guest OS ที่ Clone ไว้ตอนแรก Boot ขึ้นมาแล้วก็ ssh เข้าไปตาม IP ที่ได้รับจาก vboxnet
ADD DNS Reccord
* BROKER Host
ขั้นแรกเลยเมื่อเรามีเครื่อง Node และ ได้รับ IP เรียบร้อยเราต้องทำการลงทะเบียนชื่อ Node กับ DNS Server โดยสั่งทางฝั่ง Broker นะครับ ทำทุกครั้งเมื่อมีการ setup Node ขึ้นมาใหม่
oo-register-dns -h node -d example.com -n 192.168.5.2 -k /var/named/example.com.key
ให้ระบุ IP (-n) และ ชื่อ Host (-d) ของเครื่อง Node ให้ถูกต้อง เมื่อสั่งเรียบร้อยแล้วให้ลอง ping ดูครับ ถ้าไม่มีอะไรผิดปกติก็สามารถระบุ IP กลับมาถูกต้อง
ping node.example.com หรือจะลอง dig node.example.com จะได้ข้อมูลออกมาประมาณนี้
;; QUESTION SECTION: ;node.example.com. IN A ;; ANSWER SECTION: node.example.com. 180 IN A 192.168.5.2 ;; AUTHORITY SECTION: example.com. 1 IN NS ns1.example.com. ;; ADDITIONAL SECTION: ns1.example.com. 1 IN A 127.0.0.1 ns1.example.com. 1 IN A 192.168.5.1
เพิ่มบรรทัดนี้ลงใน /etc/hosts
cat<<EOF>>/etc/hosts 192.168.5.2 node.example.com 127.0.0.1 node.example.com EOF
ตั้งค่า SSH Key Authentication
* BROKER Host
ขั้นตอนนี้เป็นการตั้งให้เครื่อง Broker และ Node ติดต่อกันผ่าน SSH โดยใช้ Key Auth แทนการใช้ password โดยสั่งคำสั่งต่อไปนี้บนเครื่อง Broker
ssh-copy-id -i ~/.ssh/rsync_id_rsa.pub root@192.168.5.2
โดยระบุ IP ของเครื่อง Node ให้ถูกต้อง และถ้ามีการสร้าง Node ใหม่ขึ้นมาก็ให้ทำแบบนี้เช่นกัน แต่ถ้าใช้วิธีการ Clone ก็ไม่ต้องครับ การส่ง key ไปยัง Node ถ้าเรายังไม่เคยเข้า Node จาก Broker มาก่อนจะมีการถามเรื่องการบันทึก known hosts ก็ให้ตอบ yes และใส่ password ให้ถูกต้อง
คราวนี้ก็ลอง ssh เข้าไปยัง Node จาก Broker อีกครั้งด้วยคำสั่งด้านล่าง ถ้าไม่มีอะไรผิดพลาดก็จะเข้าได้โดยไม่ต้องใช้ password วิธีนี้สามารถนำไปใช้งานในชีวิตประจำวันจริงๆ ได้ครับ
ssh -i /root/.ssh/rsync_id_rsa root@node.example.com
แค่นี้ระบบ OpenShift Origin ก็จะสื่อสารกันระหว่าง Broker กับ Node ได้ด้วย key แต่ถ้าเราอยากใช้แบบด้านล่างโดยไม่ต้องใช้ password ด้วยต้องทำเพิ่มเติมนิดหนึ่งครับ
ssh root@node.example.com ให้ใช้คำสั่ง ln -s ~/.ssh/rsync_id_rsa ~/.ssh/id_rsa
กำหนดชื่อเครื่อง Node
* NODE Host ให้มาทางฝั่งเครื่อง Node กำหนด DNS Server ให้ระบบดังนี้ ให้แก้ไข file /etc/resolv.conf
cat <<EOF >/etc/resolv.conf domain example.com search example.com nameserver 192.168.5.1 EOF
ระบุ IP ของเครื่อง Broker ให้ถูกต้อง ทดสอบโดยการสั่ง ping ping broker.example.com ถ้าไม่มีอะไรผิดพลาดจะสามารถส่งคืน IP กลับมาถูกและตอบ ping กลับมาถูก
PING broker.example.com (192.168.5.1) 56(84) bytes of data. 64 bytes from 192.168.5.1: icmp_seq=1 ttl=64 time=0.249 ms 64 bytes from 192.168.5.1: icmp_seq=2 ttl=64 time=1.12 ms 64 bytes from 192.168.5.1: icmp_seq=3 ttl=64 time=0.364 ms
ถ้าจะใช้ dig ต้องลงเพิ่มนิดหนึ่งครับ yum -y install bind-utils ให้เพิ่มค่าใน
/etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth1
โดยสั่งคำสั่งดังนี้
myip="192.168.5.1" cat <<EOF>>/etc/sysconfig/network-scripts/ifcfg-eth0 PEERDNS=no DNS1=${myip} EOF cat <<EOF>>/etc/sysconfig/network-scripts/ifcfg-eth1 PEERDNS=no DNS1=${myip} EOF
แก้ไข /etc/sysconfig/network nano -w /etc/sysconfig/network แก้ไขค่า HOSTNAME
HOSTNAME=node.example.com
สั่งปรับชื่อเครื่อง
hostname node.example.com logout แล้ว login เข้ามาใหม่ก็จะเห็น prompt ใหม่ตามชื่อเครื่องละ
ติดตั้ง MCollective บน Node Host
* NODE Host ติดตั้ง MCollective เพื่อติดต่อสื่อสารผ่าน ActiveMQ Messenger Server โดยติดตั้ง package ดังนี้
ติดตั้ง
yum -y install openshift-origin-msg-node-mcollective
ตั้งค่า MCollective
โดยใช้คำสั่งต่อไปนี้
cat <<EOF >/opt/rh/ruby193/root/etc/mcollective/server.cfg topicprefix = /topic/ main_collective = mcollective collectives = mcollective libdir = /opt/rh/ruby193/root/usr/libexec/mcollective logfile = /var/log/mcollective.log loglevel = debug daemonize = 1 direct_addressing = 1 registerinterval = 30 # Plugins securityprovider = psk plugin.psk = unset connector = stomp plugin.stomp.host = broker.example.com plugin.stomp.port = 61613 plugin.stomp.user = mcollective plugin.stomp.password = secret # Facts factsource = yaml plugin.yaml = /opt/rh/ruby193/root/etc/mcollective/facts.yaml EOF
ให้ตั้ง User และ Password ให้ตรงกับทาง Broker
เปิดใช้ Service
chkconfig ruby193-mcollective on service ruby193-mcollective start
ถึงตอนนี้ให้ไปทาง Broker host แล้วพิมพ์คำสั่งตรวจสอบว่าเห็นกันหรือยังดังนี้
mco find or oo-mco find
และลอง ping ดู
mco ping or oo-mco ping
และ ดูรายละเอียดของ node
mco inventory node.example.com or oo-mco inventory node.example.com
คำสั่งควรจะ work นะครับถ้าไม่ work ต้องไล่ดูว่าทำอะไรผิดหรือเปล่า แต่ปัญหาที่ผมพบบ่อยสุดคือเวลาไม่ตรงกันครับระหว่าง broker กับ node ต้อง restart ntpd ดูถ้ายังไม่ได้ก็ไล่ config ครับ
ติดตั้ง Node Packages
เป็นการติดตั้งแกนระบบของ OpenShift Origin Node Host * NODE Host
ติดตั้ง
ติดตั้ง Package ต่อไปนี้สำหรับติดตั้งแกนระบบของเครื่อง Node
yum -y install rubygem-openshift-origin-node \ rubygem-passenger-native \ openshift-origin-port-proxy \ openshift-origin-node-util \ rubygem-openshift-origin-container-selinux \ rubygem-openshift-origin-frontend-apachedb \ rubygem-openshift-origin-frontend-apache-mod-rewrite \ rubygem-openshift-origin-frontend-nodejs-websocket
echo "ServerName node.example.com" > /etc/httpd/conf.d/000001_openshift_origin_node_servername.conf
ตั้ง Firewall สำหรับ Proxy
iptables -N rhc-app-comm iptables -I INPUT 4 -m tcp -p tcp --dport 35531:65535 -m state --state NEW -j ACCEPT iptables -I INPUT 5 -j rhc-app-comm iptables -I OUTPUT 1 -j rhc-app-comm service iptables save
ติดตั้ง Cartridges
Cartridges คือชิ้นส่วนที่ผู้ใช้ PaaS นำมาประกอบใช้งานเป็น Application Gear เช่น ภาษาต่างๆ PHP RUBY JAVA Database ต่างๆ เช่น MySQL MongoDB MariaDB ถ้าวางแผนที่จะมีหลาย Node ต้องติดตั้ง Cartridges ให้เหมือนกันทุก Node นะครับส่วนจะมี Cartridges อะไรให้ใช้บ้างนั้นลองสั่ง
yum search origin-cartridge ตัวอย่างผมลงมี Cartridges ดังนี้
yum -y install openshift-origin-cartridge-cron \ openshift-origin-cartridge-haproxy \ openshift-origin-cartridge-php \ openshift-origin-cartridge-mysql\ openshift-origin-cartridge-mongodb\ openshift-origin-cartridge-nodejs \ openshift-origin-cartridge-phpmyadmin
ตามตัวอย่างก็ใช้เวลานานหน่อยถ้าใครเน็ทไม่แรงก็เลือกสักตัวสองตัวเพื่อทดสอบก็พอครับ แต่ cron ต้องลงก่อนเลยนะครับอย่าลืม
เมื่อติดตั้งเสร็จเรียบร้อยให้สั่ง install cartridges ด้วยคำสั่งด้านล่าง ถ้าสำเร็จจะคืนค่าว่า succeeded กลับมา
/usr/sbin/oo-admin-cartridge –recursive -a install -s /usr/libexec/openshift/cartridges/
จัดการ firewall และ services ที่จำเป็น
lokkit --service=ssh lokkit --service=https lokkit --service=http lokkit --port=8000:tcp lokkit --port=8443:tcp chkconfig httpd on chkconfig network on chkconfig sshd on chkconfig oddjobd on chkconfig openshift-node-web-proxy on
ตั้งค่า Multi-Tenancy บน Node Host
* NODE Host
Install augeas tools
augeas เป็นเครื่องมือสำหรับใช้แก้ไขค่า config file แบบง่ายๆ (ถ้าเข้าใจมันนะ) ซึ่งไม่ได้รู้จัก config ทั้งหมดหรอก ถ้าอยากรู้ว่ามีอะไรบ้างลองเข้าไปอ่านในเว็บของ augeas ดูครับ http://augeas.net
yum -y install augeas
Configure PAM Modules
แก้ไขค่าเกี่ยวกับ PAM ถ้าอยากรู้ว่าแก้อะไรบ้างก็ลองไล่อ่านดูครับ
cat <<EOF | augtool set /files/etc/pam.d/sshd/#comment[.='pam_selinux.so close should be the first session rule'] 'pam_openshift.so close should be the first session rule' ins 01 before /files/etc/pam.d/sshd/*[argument='close'] set /files/etc/pam.d/sshd/01/type session set /files/etc/pam.d/sshd/01/control required set /files/etc/pam.d/sshd/01/module pam_openshift.so set /files/etc/pam.d/sshd/01/argument close set /files/etc/pam.d/sshd/01/#comment 'Managed by openshift_origin' set /files/etc/pam.d/sshd/#comment[.='pam_selinux.so open should only be followed by sessions to be executed in the user context'] 'pam_openshift.so open should only be followed by sessions to be executed in the user context' ins 02 before /files/etc/pam.d/sshd/*[argument='open'] set /files/etc/pam.d/sshd/02/type session set /files/etc/pam.d/sshd/02/control required set /files/etc/pam.d/sshd/02/module pam_openshift.so set /files/etc/pam.d/sshd/02/argument[1] open set /files/etc/pam.d/sshd/02/argument[2] env_params set /files/etc/pam.d/sshd/02/#comment 'Managed by openshift_origin' rm /files/etc/pam.d/sshd/*[module='pam_selinux.so'] set /files/etc/pam.d/sshd/03/type session set /files/etc/pam.d/sshd/03/control required set /files/etc/pam.d/sshd/03/module pam_namespace.so set /files/etc/pam.d/sshd/03/argument[1] no_unmount_on_close set /files/etc/pam.d/sshd/03/#comment 'Managed by openshift_origin' set /files/etc/pam.d/sshd/04/type session set /files/etc/pam.d/sshd/04/control optional set /files/etc/pam.d/sshd/04/module pam_cgroup.so set /files/etc/pam.d/sshd/04/#comment 'Managed by openshift_origin' set /files/etc/pam.d/runuser/01/type session set /files/etc/pam.d/runuser/01/control required set /files/etc/pam.d/runuser/01/module pam_namespace.so set /files/etc/pam.d/runuser/01/argument[1] no_unmount_on_close set /files/etc/pam.d/runuser/01/#comment 'Managed by openshift_origin' set /files/etc/pam.d/runuser-l/01/type session set /files/etc/pam.d/runuser-l/01/control required set /files/etc/pam.d/runuser-l/01/module pam_namespace.so set /files/etc/pam.d/runuser-l/01/argument[1] no_unmount_on_close set /files/etc/pam.d/runuser-l/01/#comment 'Managed by openshift_origin' set /files/etc/pam.d/su/01/type session set /files/etc/pam.d/su/01/control required set /files/etc/pam.d/su/01/module pam_namespace.so set /files/etc/pam.d/su/01/argument[1] no_unmount_on_close set /files/etc/pam.d/su/01/#comment 'Managed by openshift_origin' set /files/etc/pam.d/system-auth-ac/01/type session set /files/etc/pam.d/system-auth-ac/01/control required set /files/etc/pam.d/system-auth-ac/01/module pam_namespace.so set /files/etc/pam.d/system-auth-ac/01/argument[1] no_unmount_on_close set /files/etc/pam.d/system-auth-ac/01/#comment 'Managed by openshift_origin' save EOF
cat <<EOF > /etc/security/namespace.d/sandbox.conf # /sandbox \$HOME/.sandbox/ user:iscript=/usr/sbin/oo-namespace-init root,adm,apache EOF cat <<EOF > /etc/security/namespace.d/tmp.conf /tmp \$HOME/.tmp/ user:iscript=/usr/sbin/oo-namespace-init root,adm,apache EOF cat <<EOF > /etc/security/namespace.d/vartmp.conf /var/tmp \$HOME/.tmp/ user:iscript=/usr/sbin/oo-namespace-init root,adm,apache EOF
Enable Control Groups (cgroups)
* NODE Host เปิดใช้งาน cgroups เพื่อจำกัดการเข้าถึงทรัพยากรของเครื่อง ง่ายต่อการควบคุมแต่ละผู้ใช้งาน
chkconfig cgconfig on chkconfig cgred on service cgconfig restart service cgred restart
Configure Disk Quotas
* NODE Host
เปิดการใช้งาน disk quota เพื่อจำกัดการใช้งานพื้นที่ disk บนเครื่องสำหรับแต่ละ user โดยการแก้ไข /etc/fstab แล้วใส่ option usrquota ในบรรทัดของ / (ถ้าท่านออกแบบระบบเองก็ให้ระบุไปที่ partition ที่มี /var/lib/openshift อยู่นะครับ )
nano -w /etc/fstab
/dev/mapper/VolGroup-lv_root / ext4 defaults,usrquota 1 1
หลังจากนั้นให้ทำการ remount / ใหม่ เพื่อเปิดใข้งาน option ที่ตั้งไว้ mount -o remount / update database โดยสั่ง quotacheck -cmug / การกำหนดค่าอย่างละเอียดสามารถเข้าไปแก้ไขได้ที่ nano -w /etc/openshift/resource_limits.conf
Configure SELinux and System Control Settings
* NODE Host
OpenShift จะเน้นเรื่องการใช้งาน SELinux ดังนั้นต้องแน่ใจว่าเราได้กำหนดค่าต่างอย่างครบถ้วน เพราะถ้าตั้ง SELinux ไม่ถูกนี่เราไม่สามารถเรียกใช้งานได้เลยนะครับ ให้ทำตามทีละขั้นดังนี้
Configuring SELinux
setsebool -P httpd_unified=on httpd_can_network_connect=on httpd_can_network_relay=on \ httpd_read_user_content=on httpd_enable_homedirs=on httpd_run_stickshift=on \ allow_polyinstantiation=on httpd_run_stickshift=on httpd_execmem=on restorecon -rv /var/run restorecon -rv /usr/sbin/mcollectived /var/log/mcollective.log /var/run/mcollectived.pid restorecon -rv /var/lib/openshift /etc/openshift/node.conf /etc/httpd/conf.d/openshift
Configuring System Control Settings
แก้ไขค่าของ sysctl.conf ด้วยคำสั่งดังนี้
cat <<EOF | augtool set /files/etc/sysctl.conf/kernel.sem "250 32000 32 4096" set /files/etc/sysctl.conf/net.ipv4.ip_local_port_range "15000 35530" set /files/etc/sysctl.conf/net.netfilter.nf_conntrack_max "1048576" save EOF
update ค่าที่แก้ไขไป อาจจะมีบางค่า error ก็ไม่ต้องตกใจครับ sysctl -p /etc/sysctl.conf
Configure SSH, OpenShift Port Proxy, and Node Configuration
* NODE Host เพิ่มค่าให้กับ ssh server เพื่อให้สามารถติดต่อผ่านทาง git ได้ ใช้คำสั่งดังนี้
cat <<EOF >> /etc/ssh/sshd_config AcceptEnv GIT_SSH EOF
ปรับค่า MaxSessions ให้ ssh server เป็น 40 ถ้าใข้งานจริงก็ต้องดูความเหมาะสมตามเนื้องานครับ
cat <<EOF | augtool set /files/etc/ssh/sshd_config/MaxSessions 40 save EOF
Initialize Traffic Control
* NODE Host chkconfig openshift-tc on
Configuring the Port Proxy
* NODE Host
เปิด firewall ตั้งค่า service และเริ่มใช้งาน OpenShift Proxy ซึ่งใช้สำหรับติดต่อสื่อสารภายในไปยัง gear ต่างๆ
lokkit --port=35531-65535:tcp chkconfig openshift-port-proxy on service openshift-port-proxy start chkconfig openshift-gears on
Configuring Node Settings for Domain Name
* NODE Host เป็นการกำหนดค่าให้กับ Node ถ้า set node อื่นๆ เพิ่มก็ตั้งชื่อ และ IP ให้ถูกต้องครับ nano -w /etc/openshift/node.conf
PUBLIC_HOSTNAME="node.example.com" PUBLIC_IP="192.168.5.2" BROKER_HOST="broker.example.com" CLOUD_DOMAIN="example.com"
Update login.defs
* NODE Host กำหนดค่า uid ตำสุดของระบบให้สอดคล้องกับ GEAR_MIN_UID ใน node.conf
cat <<EOF | augtool set /files/etc/login.defs/UID_MIN 500 set /files/etc/login.defs/GID_MIN 500 save EOF
Update the facter Database
* NODE Host จริงๆ ตรงนี้จะมี crontab คอยอัปเดทให้แต่ถ้าอยากให้อัปเดทตอนนี้เลยก็สั่งดังนี้ /etc/cron.minutely/openshift-facts
Reboot Node Host
* NODE Host
เมื่อทำทุกอย่างสำเร็จเสร็จสิ้นก็ถึงคราวทดสอบจริงๆ ก็ให้ reboot หนึ่งรอบครับ หลังจาก reboot มาแล้วแนะนำให้ snapshot VM ไว้ด้วยนะครับเผื่อมีอะไรผิดพลาดจะได้กลับมา หรือจะ snapshot มาทีละขั้นตอนข้างบนก็ได้ และ ถ้าเห็นว่าเป็น node ที่สมบุรณ์แล้วก็ให้ทำการ clone VM ไปเป็น node2 node3 ต่อไปแต่อย่าลืมตามไปแก้ตามที่เคยแนะนำในหัวข้อ clone ในบทความนี้ในตอนต้นนะครับ
ทดสอบระบบ
* Host OS
การทดสอบระบบเราสามารถทดสอบบนเครื่อง Host OS หรือเครื่องแม่ที่ลง VirtualBox ไว้นั่นเอง ของผมก็เป็น OS X ผมก็สามารถทดสอบบน Browser ได้ โดยการตั้งค่า DNS Server ของ OS X ให้ชี้ไปยังเครื่อง broker ครับเมื่อกำหนด ค่า DNS Server เรียบร้อยก็เปิด Browser ขึ้นมาใส่ URL ดังนี้
https://broker.example.com
แล้วใช้ login password ที่ตั้งไว้ด้วย htpasswd ในที่นี้คือ openshift:openshift
ถ้าหาก Broker และ Node สามารถเชื่อมต่อกันได้อย่างถูกต้องท่านจะเห็นรายการ Cartrigdes ประมาณนี้
รูปที่ 27 รายการ Cartrigde ที่มีทางฝั่ง Node
ส่วนการใช้งานถ้ามีโอกาสจะเขียนกันอีกสักยกขอตัวไปศึกษาก่อนครับ