إعداد العقد والتواصل بينها
تعلّم إعداد عدة عقد Erlang وربطها، مع فهم بروتوكول التوزيع الأساسي وآليات الأمان
إعداد العقد والتواصل بينها درس مجاني في Erlang OTP: Distributed & Fault-Tolerant Systems Programming على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Erlang OTP: Distributed & Fault-Tolerant Systems Programming، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Erlang OTP: Distributed & Fault-Tolerant Systems Programming 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Welcome to Distributed Erlang
Erlang shines in building distributed systems! It allows multiple Erlang Virtual Machines (VMs), called nodes, to communicate seamlessly.
This lesson introduces how to set up and connect these nodes, forming the foundation for fault-tolerant and scalable applications.
Understanding Erlang Node Names
Every Erlang node needs a unique name to identify itself in a distributed system. There are two types of names:
- Short names (e.g.,
mynode): Used for nodes on the same local machine or network segment. Started with-sname. - Long names (e.g.,
node1@example.com): Essential for nodes distributed across different hosts and networks. Requires a fully qualified domain name (FQDN) and started with-name.
We'll primarily use short names for local examples.
The Erlang Cookie: Shared Secret
For two Erlang nodes to communicate, they must share a common secret key called the Erlang cookie. Think of it like a password for node-to-node authentication.
- If nodes have different cookies, they cannot connect.
- The cookie is a string (e.g.,
mysecretcookie). - It's crucial for security: keep your cookies secret and generate strong ones!
Starting Your First Node
Let's start an Erlang node with a short name and a cookie. Open your terminal and run:
erl -sname alpha -setcookie myappsecretOnce the Erlang shell loads, you can check your node's name and cookie:
node().(shows the node's full name)erlang:get_cookie().(shows the cookie)
EPMD: The Port Mapper Daemon
When an Erlang node starts, it registers itself with a local process called EPMD (Erlang Port Mapper Daemon).
EPMD's job is to keep track of which Erlang nodes are running on the local host and which TCP ports they are listening on. When one node wants to connect to another on the same machine, it asks EPMD for the target node's port number.
You can see registered nodes with epmd -names in a separate terminal.
Connecting Two Local Nodes
Now, start a second node in another terminal. Make sure to use the same cookie:
erl -sname beta -setcookie myappsecretFrom the alpha node's shell, try to ping beta:
net_adm:ping(beta@~s).Replace ~s with your machine's hostname (e.g., net_adm:ping(beta@localhost).). If it returns pong, they are connected! You can also use nodes(). to see connected nodes.
Demonstrating Node Identity
This simple Erlang module helps identify the current node. It's a full program that reports its own node name.
Save this as node_id.erl, compile it in your Erlang shell (c(node_id).), and then call node_id:print_name(). to see the output.
-module(node_id).
-export([print_name/0]).
print_name() ->
io:format("Current node name: ~p~n", [node()]).Long Node Names for Remote Hosts
For connecting nodes across different physical machines or networks, you must use long node names with the -name flag. This requires using the node's fully qualified domain name (FQDN) or IP address.
Example: erl -name node1@server.example.com -setcookie myappsecret
Using long names ensures that nodes can be uniquely identified and reached over a wider network.
Basic Security Considerations
While the Erlang cookie provides basic authentication, consider these points:
- Strong Cookies: Use long, random strings for production environments.
- Firewall Rules: Configure firewalls to allow EPMD (port 4369) and the dynamic Erlang node ports to communicate only between trusted hosts.
- TLS: For sensitive data or untrusted networks, use Transport Layer Security (TLS) for encrypted communication (covered in a later lesson).
Quick Check on Node Setup
You've learned about Erlang nodes, naming, cookies, and EPMD. Let's test your understanding!
Recap: Node Communication Fundamentals
You've taken the first step into distributed Erlang! We covered:
- Erlang Nodes: Separate Erlang VMs that can communicate.
- Node Names:
-snamefor local,-namefor remote (FQDN). - Erlang Cookie: A shared secret for node authentication.
- EPMD: The daemon for local node discovery.
- Connecting Nodes: Using
net_adm:ping/1to establish communication.
Next, we'll explore how these connected nodes can actually talk to each other!
الأسئلة الشائعة
هل درس «إعداد العقد والتواصل بينها» مجاني؟
نعم — نص درس «إعداد العقد والتواصل بينها» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Erlang OTP: Distributed & Fault-Tolerant Systems Programming، انتقل إلى CoddyKit PRO. تتضمن دورة Erlang OTP: Distributed & Fault-Tolerant Systems Programming 4 دروس في المجموع.
ماذا ستتعلم في «إعداد العقد والتواصل بينها»؟
تعلّم إعداد عدة عقد Erlang وربطها، مع فهم بروتوكول التوزيع الأساسي وآليات الأمان تتمرن على Erlang OTP: Distributed & Fault-Tolerant Systems Programming مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Erlang OTP: Distributed & Fault-Tolerant Systems Programming؟
لا تُشترط خبرة سابقة. Erlang OTP: Distributed & Fault-Tolerant Systems Programming على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.
كم من الوقت يستغرق درس «إعداد العقد والتواصل بينها»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Erlang OTP: Distributed & Fault-Tolerant Systems Programming هذا؟
نعم. كل درس في Erlang OTP: Distributed & Fault-Tolerant Systems Programming يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- إعداد العقد والتواصل بينها
- استدعاءات الإجراءات البعيدة (RPC)
- تسجيل العمليات عالميًا
- أمان التوزيع وملفات Cookies