尊龙凯时人生就是博

ÔõÑù¾ÙÐÐLinuxϵͳµÄÓ¦ÓóÌÐò°²ÅźÍÖÎÀí

ÔÚ½ñÌìµÄITʱ´ú £¬Linuxϵͳ³ÉΪÁ˺ÜÊÇÊ¢ÐеIJÙ×÷ϵͳ֮һ¡£Ðí¶àÒµÄÚÈËʿϲ»¶Ê¹ÓÃLinux°²ÅÅÓ¦ÓóÌÐò £¬ÓÉÓÚLinuxϵͳÎȹÌÇÒ¿ª·ÅÔ´´úÂë £¬¿ª·¢Õß¿ÉÒÔÀû±ãµØ¿ª·¢ºÍ¼¯³ÉÓ¦ÓóÌÐò¡£

±¾ÎĽ«ÏÈÈÝÔõÑù¾ÙÐÐLinuxϵͳµÄÓ¦ÓóÌÐò°²ÅźÍÖÎÀí¡£ÎÒÃǽ«Ê¹ÓÃÒ»¸öÏÖʵµÄÓ¦ÓóÌÐò×÷Ϊ°¸Àý £¬Í¨¹ýÏêϸµÄ´úÂëʾÀýÀ´ÑÝʾÔõÑùʵÏÖ°²ÅźÍÖÎÀí¡£

Ó¦ÓóÌÐòµÄ×¼±¸

ÔÚÎÒÃÇ×îÏÈ֮ǰ £¬ÎÒÃÇÐèҪ׼±¸Ò»¸ö¼òÆÓµÄÓ¦ÓóÌÐò £¬²¢´ò°ü³É¿ÉÖ´ÐÐÎļþ¡£ÎÒÃǽ«Ê¹ÓÃÒ»¸ö¼òÆÓµÄPython¾ç±¾ £¬¸Ã¾ç±¾½«Êä³ö¡°Hello, World!¡±¡£

ÒÔÏÂÊÇPython¾ç±¾µÄ´úÂëʾÀý£º

#!/usr/bin/env python3
print('Hello, World!')

µÇ¼ºó¸´ÖÆ

ÔÚÔËÐд˾籾֮ǰ £¬ÎÒÃÇÐèҪȷ±£×°ÖÃÁËPython 3¡£Äú¿ÉÒÔÔÚÏÂÁîÐнçÃæÊäÈëÒÔÏÂÏÂÁîÀ´¼ì²é£º

python3 --version

µÇ¼ºó¸´ÖÆ

ÈôÊÇPython 3ÒÑÀÖ³É×°Öà £¬ÄúÓ¦¸Ã»á¿´µ½ÀàËÆÈçϵÄÊä³ö£º

Python 3.8.5

µÇ¼ºó¸´ÖÆ

½ÓÏÂÀ´ £¬ÎÒÃǽ«Ê¹ÓÃPyInstaller½«Python¾ç±¾´ò°ü³É¿ÉÖ´ÐÐÎļþ¡£PyInstallerÊÇÒ»¸öÓÃÓÚPythonÓ¦ÓóÌÐòµÄ´ò°ü¹¤¾ß £¬Ëü¿ÉÒÔ½«Python´úÂë´ò°ü³É¿É×ÔÁ¦Ö´ÐеĶþ½øÖÆÎļþ¡£Äú¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÀ´×°Öãº

pip3 install pyinstaller

µÇ¼ºó¸´ÖÆ

×°ÖÃÍêPyInstallerºó £¬ÊäÈëÒÔÏÂÏÂÁî¶ÔPython¾ç±¾¾ÙÐдò°ü£º

pyinstaller --onefile hello.py

µÇ¼ºó¸´ÖÆ

ÔËÐÐÍê±Ïºó £¬Ó¦¸Ã»áÔÚdistĿ¼Ï¿´µ½´ò°üºÃµÄhello¿ÉÖ´ÐÐÎļþ¡£

Ó¦ÓóÌÐò°²ÅÅ

ÏÖÔÚ £¬ÎÒÃÇ¿ÉÒÔ½«´ò°üºÃµÄÓ¦ÓóÌÐò°²Åŵ½LinuxϵͳÖС£ÎÒÃǽ«Ê¹ÓÃDebianϵÁеÄLinuxϵͳ£¨ÀýÈçUbuntu£©×÷ΪʾÀý¡£

Ê×ÏÈ £¬½«´ò°üºÃµÄhello¿ÉÖ´ÐÐÎļþÉÏ´«µ½LinuxϵͳÖС£Äú¿ÉÒÔʹÓÃscpÏÂÁÎļþÉÏ´«ÖÁÔ¶³ÌЧÀÍÆ÷£º

scp -P <port> /path/to/hello user@server:/path/to/destination

µÇ¼ºó¸´ÖÆ

ÔÚ´ËÏÂÁîÖÐ £¬ ÊÇSSH¶Ë¿Ú £¬/path/to/helloÊÇ´ò°üºÃµÄ¿ÉÖ´ÐÐÎļþµÄ·¾¶ £¬userÊÇLinuxϵͳµÄÓû§Ãû £¬serverÊÇLinuxϵͳµÄIPµØµã»òÓòÃû £¬/path/to/destinationÊÇÄúÏëÒª½«Îļþ°²ÅŵÄÄ¿µÄ·¾¶¡£

ÔÚ½«ÎļþÉÏ´«µ½ÏµÍ³Öкó £¬ÎÒÃÇ¿ÉÒÔʹÓÃchmodÏÂÁÎļþÉèÖÃΪ¿ÉÖ´ÐÐÎļþ£º

chmod +x /path/to/hello

µÇ¼ºó¸´ÖÆ

ÏÖÔÚ £¬ÎÒÃÇ¿ÉÒÔÖ±½ÓÔËÐÐÎļþÀ´Æô¶¯Ó¦ÓóÌÐò£º

./hello

µÇ¼ºó¸´ÖÆ

ÄúÓ¦¸Ã»á¿´µ½Êä³ö£º

Hello, World!

µÇ¼ºó¸´ÖÆ

Ó¦ÓóÌÐòÖÎÀí

Ò»µ©ÎÒÃÇÀֳɵذ²ÅÅÁËÓ¦ÓóÌÐò £¬¾ÍÐèҪ˼Á¿ÔõÑùÖÎÀíËü¡£ÒÔÏÂÊÇһЩӦÓóÌÐòÖÎÀíµÄÒªÁ죺

ʹÓÃsystemd

systemdÊÇÏÖ´úLinuxϵͳµÄÒ»¸ö»ù±¾Ð§ÀÍÖÎÀíÆ÷¡£Äú¿ÉÒÔʹÓÃsystemctlÏÂÁîÆô¶¯¡¢×èÖ¹¡¢ÖØÔØ¡¢ÖØÐÂÆô¶¯µÈЧÀÍ¡£ÒªÔÚsystemdÖÐÉèÖÃÓ¦ÓóÌÐòЧÀÍ £¬ÄúÐèÒª½¨ÉèÒ»¸öunitÎļþ¡£ÒÔÏÂÊÇÒ»¸öʾÀýhello.serviceµ¥Î»Îļþ£º

[Unit]
Description=hello service

[Service]
WorkingDirectory=/path/to/application
ExecStart=/path/to/hello

[Install]
WantedBy=multi-user.target

µÇ¼ºó¸´ÖÆ

ÄúÐèÒª½«ÆäÉúÑĵ½/etc/systemd/system/Ŀ¼Ï £¬²¢ÔÚsystemdÖØÔغóÆô¶¯Ëü£º

systemctl daemon-reload
systemctl start hello.service

µÇ¼ºó¸´ÖÆ

ËäÈ» £¬Äú»¹¿ÉÒÔʹÓÃsystemctlÏÂÁî¾ÙÐÐÆäËû²Ù×÷ £¬ÀýÈç×èÖ¹¡¢ÖØÆô¡¢ÖØÐÂÔØÈëµÈ¡£

ʹÓÃsupervisor

SupervisorÊÇÒ»¸öÔÚLinuxЧÀÍÆ÷ÉÏÖÎÀí¶à¸öÀú³ÌµÄ¹¤¾ß¡£ËüÔÊÐíÄúÔÚÊØ»¤Àú³ÌģʽÏÂÔËÐÐÓ¦ÓóÌÐò £¬²¢ÔÚÓ¦ÓóÌÐòÍß½âʱ×Ô¶¯ÖØÆôËüÃÇ¡£ÒÔÏÂÊÇÒ»¸öʾÀýhello.confÎļþ£º

[program:hello]
command=/path/to/hello
directory=/path/to/application
autostart=true
autorestart=true
startretries=3
stderr_logfile=/var/log/hello.err.log
stdout_logfile=/var/log/hello.out.log

µÇ¼ºó¸´ÖÆ

ÄúÐèÒª½«ÆäÉúÑĵ½/etc/supervisor/conf.d/Ŀ¼Ï £¬²¢ÖØмÓÔØSupervisor£º

systemctl reload supervisor

µÇ¼ºó¸´ÖÆ

ÏÖÔÚ £¬Ê¹ÓÃsupervisorctlÏÂÁîÆô¶¯Ó¦ÓóÌÐò£º

supervisorctl start hello

µÇ¼ºó¸´ÖÆ

ʹÓôËÏÂÁî×èÖ¹Ó¦ÓóÌÐò£º

supervisorctl stop hello

µÇ¼ºó¸´ÖÆ

Äú»¹¿ÉÒÔʹÓÃÆäËûÏÂÁî £¬ÀýÈçrestart¡¢reloadµÈ¡£

½áÂÛ

ÔÚ±¾ÎÄÖÐ £¬ÎÒÃÇÏêϸÏÈÈÝÁËÔõÑù°²ÅźÍÖÎÀíÓ¦ÓóÌÐò¡£ÎÒÃÇÒÔÒ»¸öPython¾ç±¾ÎªÀý £¬Í¨¹ýPyInstaller½«Æä´ò°üΪ¿ÉÖ´ÐÐÎļþ £¬È»ºó°²Åŵ½LinuxϵͳÖС£Ëæºó £¬ÎÒÃÇÌÖÂÛÁËһЩӦÓóÌÐòÖÎÀíÒªÁì £¬ÀýÈçsystemdºÍSupervisor¡£ÒÔÉÏʾÀý¶¼ÌṩÁË¿ÉÒÔÖ±½ÓʹÓõĴúÂ롣ϣÍûÕâƪÎÄÕÂÄܹ»ÎªÄúÌṩÓÐÒæµÄÖ¸µ¼ £¬È·±£ÄúÄܹ»Àֳɵذ²ÅźÍÖÎÀíÓ¦ÓóÌÐò¡£

ÒÔÉϾÍÊÇÔõÑù¾ÙÐÐLinuxϵͳµÄÓ¦ÓóÌÐò°²ÅźÍÖÎÀíµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是博ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是博ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

13452372176

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ