ตอนนั้นเรายังไม่รู้จัก เราก็ใช้ iptables ไปก่อน ก็ใช้งานได้นะ
และ iptables ตอนนั้นเราก็ยังไม่ได้ Save Config พอเครื่อง Server Restart ก็เจอปัญหาว่ามันลืมค่า
ตอนนี้เราจะมาดูกันว่า เวลาที่เราจะเปิดให้ข้างนอกเข้ามา Container ได้โดยใช้ Proxy Device นั้นทำยังไง
การใช้งาน SSH เข้าไปใน Container
การเพิ่ม Proxy Device
ข้อมูลอ้างอิงจาก : https://lxd.readthedocs.io/en/latest/containers/1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # listen ให้รอรับข้อมูลทางไหน ส่วนใหญ่ก็จะเป็น 0.0.0.0:80 # connect ให้ต่อเข้ากับช่องทางไหน ก็จะเป็น 127.0.0.1:80 # type คือ Connection Type ก็พวก TCP, UDP lxc config device add <container-name> <device-name> proxy \ listen=< type >:<address>:<port> connect=< type >:<address>:<port> # listen จะเป็น Port ของ Host # connect จะเป็น Port ของ Container # คำสั่งที่ใช้ในการลบ Config ออก lxc config device remove <container-name> <device-name> # ตัวอย่างการใช้ lxc config device add ubuntu-80 ubuntu-device-80 proxy \ listen=tcp:0.0.0.0:80 connect=tcp:127.0.0.1:80 |
เราจะลองสร้าง Container 2 อันโดย อันแรกจะใช้ Port 80 อีกอันใช้ Port 82 เปิดเป็นเว็บดู
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # สร้าง Container lxc launch images:ubuntu /18 .04 ubuntu-80 เข้าไปใน Container lxc exec ubuntu-80 -- bash # ติดตั้ง Apache2 และ Curl apt install -y apache2 curl # ทดสอบมันทุกอัน เสร็จแล้วออกจาก Container curl 0.0.0.0 curl 127.0.0.1 curl localhost exit # ทำการเพิ่ม Proxy Device lxc config device add ubuntu-80 ubuntu-device-80 proxy \ listen=tcp:0.0.0.0:80 connect=tcp:127.0.0.1:80 |
เสร็จแล้วทำอีกรอบแต่เป็น ubuntu-82 แล้วลองเข้า IP ของ Host ดูทั้ง 2 Port (80, 82) ว่าเว็บขึ้นไหม
ผลที่ได้คือขึ้นทั้ง 2 ตัว
ก่อนทำการเพิ่ม Proxy Device
หลังทำการเพิ่ม Proxy Device 80 และ 82
1 2 3 4 5 | # ตรวจสอบ Port ที่เปิดฟังอยู่ จะเห็นว่ามี :::80 และ :::82 netstat -plnt # ลองลบ Proxy Device แล้วใช้ netstat -plnt เช็ค Port อีกรอบ 80 ต้องหายไปแล้ว lxc config device remove ubuntu-80 ubuntu-device-80 |
ไม่มีความคิดเห็น:
แสดงความคิดเห็น