ÎÞÓÇÆô¶¯ÂÛ̳

 ÕÒ»ØÃÜÂë
 ×¢²á
ËÑË÷
ϵͳgho:×î´¿¾»ºÃÓÃϵͳÏÂÔØվͶ·Å¹ã¸æ¡¢¼ÓÈëVIP»áÔ±£¬ÇëÁªÏµ ΢ÐÅ:wuyouceo
²é¿´: 280|»Ø¸´: 0
´òÓ¡ ÉÏÒ»Ö÷Ìâ ÏÂÒ»Ö÷Ìâ

ÔõÑùÔÚÒ»¸ödockerÀïÆô¶¯apache2+mysql

[¸´ÖÆÁ´½Ó]
Ìøתµ½Ö¸¶¨Â¥²ã
1#
±¾Ìû×îºóÓÉ chenandjun ÓÚ 2024-11-5 02:59 ±à¼­

Õâ¸öÊÇÎÒ×ßÍä·×î¶àµÄÒ»´Î,Ç°Ç°ºóºóÕÛÌÚÁËÓÐÒ»¸öÔÂ,ÕÒ²»µ½½Ì³ÌҲûÓÐÈË°ïÖú,¸ãµÃ²îµã±ÀÀ£,Ö÷ÒªÊDz»¶®,¶Ôdocker»úÖƲ»¶®,Ô­Àí²»¶®,ubuntuÃüÁîÒ²ÊǸÕѧ,ÆäʵdockerhubÉÏÃæÒ²ÓÐapache2+mysqlµÄ¾µÏñµÄ,µ«ÊDz»·ûºÏÎÒµÄÐÄÒ⣬ÎÒÏëµÄÊÇ°´ÕÕÎÒ×ÔÒѵÄÏ뷨ʵÏÖ,»òÕß°´ÕÕÍøÉϵÄ˵·¨»òÊÇdockerµÄ±¾ÒâÊÇÒ»¸ödockerÈÝÆ÷Ö»Æô¶¯Ò»¸ö·þÎñ,ÕâÑù½á¹¹Çå³þ,ά»¤¼òµ¥,µ«ÊÇÎÒ¸ù±¾²»ÊÇÕâÑùÏëµÄ,ÎÒ¾Íϲ»¶¸ã¼¯Öй©µç,ûµÃ°ì·¨,ÎÒµÄÏë·¨ÊÇÄã´´½¨ÁËÒ»¸öapache2ÈÝÆ÷ºÍÒ»¸ömysqlÈÝÆ÷È»ºóͨ¹ýÓ³Éä³öÀ´µÄ¶Ë¿ÚÁ¬½ÓÄѵÀÒª±ÈÔÚÒ»¸ödockerÀïÖ±½Óapache2Á¬½Óͬһ¸ödockerÀïµÄmysql¿ìÂð,ÓÐÈË»á˵,Èç¹ûÓжà¸ö·þÎñÁ¬mysqlµÄ»°¿ÉÒÔÖ»´´½¨Ò»¸ömysqlÈÝÆ÷,È»ºóÔÚÀïÃæ´´½¨¶à¸öÊý¾Ý¿â,µ«ÕâÑùÕâ¸ömysqlÈÝÆ÷¾ÍÊǹÊÕϵã,Ò»µ©Õâ¸öÈÝÆ÷³ö¹ÊÕϾÍÈ«ÍêÁË.ÎÒµÄСÖ÷»úÉÏÊ®¼¸¸öÈÝÆ÷´ó¶àÊý¶¼ÊÇÎÒ×ÔÒÑ×öµÄ¾µÏñŪµÄ,ÓÐһЩʵÔÚûÓа취»¹Ö»ÄÜÓÃdockerhubÉϵľµÏñ,±ÈÈçjsbin,Óж®jsbinµÄ´óÀв»ÖªÄܲ»ÄÜ°ï°ïÎÒ,jsbin¾ÍÊÇÒ»¸öÁ·Ï°htmlºÍjavascriptµÄ,ËüÊÇÔÚͬһ¸öÍøÒ³ÉÏ×ó±ßд´úÂëÓÒ±ßÖ±½ÓÏÔʾ½á¹ûµÄ,ÎÒ°´ÕÕ×÷ÕßgithubÒ³ÉϵĹ¹½¨±¾µØµÄ·½·¨×öһֱû³É¹¦,npm installÒÀÀµÒ»Ö±Ï²»ÏÂÀ´node°æ±¾»»ÁËÈô¸É7 8 6 18 0.8 1.0 1.2 1.1¶¼ÓÃÁ˸ù±¾Ã»ÓÃ,ÓиßÊÖÇë°ï°ïÎÒ.˵»ØÕýÌâ,ÔõÑùÔÚͬһ¸ödockerÀïÔËÐÐÁ½¸ö·þÎñ,Ò»¿ªÊ¼ÎÒÓõÄdocker¾µÏñÊÇ16.04lts,ÏÈÏÂÔØÒ»¸öubuntu16.04µÄ¾µÏñdocker pull ubuntu:16.04»òÕßÄãÒ²¿ÉÒÔÓÃdebootstrap×ÔÒÑ×ödocker¾µÏñ£¨µ«ÓÃdebootstrap×ÔÒÑ×ö¾µÏñʱÔÚdocker runʱ×îºóÒª¼ÓÉÏ/bin/bash,ÒòΪËüûÓÐÆô¶¯ÃüÁÎÒ¿ªÊ¼Ê±Ã»×¢Òâ¸ãÁ˺ü¸´Îµ¼Èëtar°üµ½Èºêͳö´í»¹ÒÔΪû¸ã³É¹¦,ºóÀ´ÔÚȺêÍÃüÁîÐÐÀïÓÃdocker import µ¼ÈëÓÖÔËÐв»ÆðÀ´,ÈÝÆ÷Ò»Æô¶¯¾ÍÍ˳ö,¾ÍÊÇûÓÐ/bin/bashÔËÐÐÃüÁî,»òÕßÄãÒ²¿ÉÒ԰ѵ¼ÈëµÄ¾µÏñÔÙdocker build -f dockfile -t "оµÏñ:±êÇ©" .Öؽ¨Ò»´Î,dockerfileÎļþ¼ÓÉÏCMD ["/bin/bash"]»òENTRYPOINT ["/bin/bash"]Èç¹ûÄãÐèÒªÔÚdockerÀïÔËÐÐsystemctl¶ø²»ÊÇserviceµÄ»°ÃüÁî¾Í²»ÊÇ/bin/bash¶øÊÇ/usr/sbin/initÁË.
ÓÐÁËubuntu16.04¾µÏñÎÒÃǾͿÉÒÔ´´½¨ÈÝÆ÷ÁË,docker run -itd --name ubuntu ubuntu:16.04,Äã¿´,Õâ¾ÍÊÇÎÒÉÏƪ˵µÄ±£ÁôÒ»¸öȺêÍϵͳµÄÓÃÒâËùÔÚ,ÎÒÔÚÔËÐÐdocker runʱʲôҲû¼Ó,û¼Ó¶Ë¿Ú£¬Ò²Ã»Ó³ÉäÎļþ¼Ð,ÒòΪ¿ªÊ¼»¹Ã»ÏëºÃÒªÓ³Éäʲô¶Ë¿Ú,Ó³ÉäʲôÎļþ¼Ð,È»ºó¾ÍÊÇubuntu»ù±¾²Ù×÷.
apt update È»ºóҪװһ¸öhttps,¡¡apt install apt-transport-httpsÒòÓÐЩ¹úÄÚÔ´µÄµØÖ·ÊÇhttpsµÄ²»×°µÄ»°¸üлá³ö´í.ÔÙ×°Ò»¸önanoÓÃÀ´±à¼­Ô´Áбí,Ôݲ»×°vimÊÇÒòÏÖÔÚ»¹Ã»»»Ô´Á¬µÄ»¹ÊǹúÍâvim´ó,×°ÁËÂýÄã»»¹ýÔ´ºó¿ÉÒÔÔÙ×°vim£®ÓÃnanoÀ´±à¼­sources.listÎļþnano /etc/apt/sources.list¿ÉÒÔÓð¢ÀïµÄÔ´(Çë×¢ÒâÌí¼ÓԴʱһ¶¨Òª¿´×¼ÄãµÄubuntuµÄ´úºÅ,ÎÒµÄÊÇubuntu16.04,´úºÅÊÇxenial,Òª¿´Ô´ÀïµÄ´úºÅºÍÄãµÄ°æ±¾Ò»Ñù,¿´´úºÅÓÃcat /etc/os-release)


deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main

deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main

deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe

È»ºóctrl+x±£´æÊäÈëyÈ»ºó»Ø³µÔÙapt updateÒ²¿ÉÒÔÓñðµÄ¹úÄÚÔ´£¬¿´¸÷ÈËϲºÃÁË.
»»ºÃÔ´¾Í¿ÉÒÔ°²×°×ÔÒÑϲ»¶µÄÈí¼þÁËÎÒ×°µÄÊÇapt install vim net-tools wget cpio unzip xz-utils lsof lshw curl iputils-pingÄǸösudoÃüÁîÎÒûװ,ÈÝÆ÷ÀïÎÒÖ»ÓÐrootûн¨Óû§ËùÒÔûװ,¶ÔÁË»¹ÓÐÒ»¸ö×°Ê®ÈýµÄÃüÁîÎÒÒ²×°ÁËapt install neofetch #ÏÔʾϵͳÐÅÏ¢,¾ÍÏñÏÂÃæÕâÑù, ´ó¼ÒÒ²¿ÉÒÔ×°Ò»ÏÂ.


»¹ÓоÍÊÇÖÕ¶ËÖÐÎÄ,¿ÉÄܶÔÓÚ¸ßÊÖÊÇϲ»¶Ó¢ÎĵÄ,ÒòΪÖÐÎÄÓÐʱ·­ÒëµÄ¿ÉÄܲ»¶Ô,µ«ÏñÎÒÕâÖÖС°×ûÓÐÖÐÎĵĻ°¸ù±¾ÎÞ´ÓÏÂÊÖ,¾ÍûÄǸßÒªÇóÁË,ÖÐÎıØÐëÕûÆðÀ´ °²×°ÖÕ¶ËÖÐÎÄ»·¾³:apt install language-pack-zh*
È»ºóÔÚ /etc/skel/.bashrcºÍ~/.bashrcºÍ~/.profileÖÐÌí¼Ó»·¾³±äÁ¿(Äã¿ÉÒÔ¾ÍÔÚ~/.bashrcÖÐÌí¼Ó¼´¿É,/etc/skel/.bashrcºÍ/etc/skel/.profileÊÇ´´½¨ÐÂÓû§Ê±×Ô¶¯Ìí¼ÓÓõÄ,Õâ¸öÎÒ×ß¹ýµÄÍ䷾Ͳ»ËµÁË,һ˵ȫÊÇÀá,~´ú±íÓû§Ä¿Â¼,ÈçÄãÊÇrootµÇ½µÄÄÇĿ¼¾ÍÊÇ/root)ÏÂÃæÊÇÒªÌí¼ÓµÄ»·¾³±äÁ¿:
export LANG="zh_CN.UTF-8"
export LANGUAGE="zh_CN:zh"
export LC_ALL="zh_CN.UTF-8"
Ìí¼ÓÍê³ÉºóҪˢл·¾³±äÁ¿ÉÏÃæexportÌí¼ÓµÄ¾ÍÊÇ»·¾³±äÁ¿ÒªË¢Ð¿ÉÒÔÓÃupdate-locale  locale-gen  »ò¡¡source ~/.bashrcÎÒÒ»°ãÓúóÕß,¼òµ¥Ö±½Ó,È»ºóÄã¿ÉÒÔËæÒâÊäÈ뼸¸öÓ¢ÎÄ×Ö·û±ÈÈçsdfsdfϵͳ»áÌáʾÖÐÎÄÐÅÏ¢ÁË˵ÕÒ²»µ½ÃüÁî,ÎÒÖªµÀÕÒ²»µ½¾ÍÊÇÏë¿´¿´ÓÐûÓбä³ÉÖÐÎÄ
È»ºó¾ÍÊÇ×°apache2 apt install apache2(libapache2-mod-phpºÃÏñĬÈϾͰüº¬Á˲»ÐèÒªÔÙ×°ÁË)²»¹ýapache2°²×°ºÃÆô¶¯Ê±»á³öÒ»¸ö´íÎó,Òª¸ÄÒ»ÏÂ/etc/apache2/apache2.confÔÚ×îĩβÌí¼Ó ServerName localhostÈ»ºóÖØÆôapache2 service apache2 restart¾ÍºÃÁË)


ÔÙÏÂÀ´ÊÇ×°php,ĬÈϵÄubuntu16.04µÄphp°æ±¾ÊÇ7.0,Ҫװphp7.4»¹µÃ°²×°¸ö´æ´¢¿â,ÎÒµÚÒ»´ÎÌý˵ÕâÍæÒÕapt -y install software-properties-common±¾À´Ïë×°php8.0µÄºÃÏñ×°²»ÁË.°²×°ºÃ´æ´¢¿âºó»¹µÃÌí¼ÓÒ»¸ö±ðÈ˵ĵÚÈý·½´æ´¢¿â
add-apt-repository ppa:ondrej/php(¸Ã´æ´¢¿âÒÑÎÞÓÃ), Õâ¸öÒѾ­ÎÞÓÃÁË,´ó¼Ò²»ÒªÌí¼ÓÁË£¬ÓÃÏÂÃæÕâ¸ö
add-apt-repository ppa:jczaplicki/xenial-php74-temp
apt update
apt -y install php7.4


»òÐíÄãµÄÓ¦ÓûáÐèҪһЩphpÀ©Õ¹,Äã¿ÉÒÔ°²×°Ò»Ð©phpÀ©Õ¹,ÎÒ·´ÕýÊÇȫװÁË(²»¹ÜÓÐûÓÃ,×°ÁËÔÙ˵)
һЩphpÀ©Õ¹ apt-get install -y php7.4-cli php7.4-json php7.4-common php7.4-mysql php7.4-zip php7.4-gd php7.4-mbstring php7.4-curl php7.4-xml php7.4-bcmath
wordpressÀ©Õ¹ apt install -y php7.4-mysql php7.4-dom php7.4-simplexml php7.4-ssh2 php7.4-xml php7.4-xmlreader php7.4-curl  php7.4-exif  php7.4-ftp php7.4-gd
php7.4-iconv php7.4-imagick php7.4-json  php7.4-mbstring php7.4-posix php7.4-sockets php7.4-tokenizer
ÆäËüÀ©Õ¹ apt install -y php7.4-mysqli php7.4-pdo  php7.4-sqlite3 php7.4-ctype php7.4-fileinfo php7.4-zip php7.4-exif php7.4-tidy(×¢,php7.4-tidyÊÇdzzofficeÀïÓиöÎļ¯ÉÏ´«txtС˵ҪÓõ½µÄ£©
APCuÊÇÒ»¸ö»º´æÀ©Õ¹£¬¿ÉÒÔ»º´æ²¢ÓÅ»¯PHPÖмä´úÂ룬ǿÁÒ½¨Òé°²×°¡£
apt -y install php7.4-apcu
apache2ÆôÓùرÕÄ£¿éÃüÁî
¹Ø±ÕÄ£¿éa2dismod Ä£¿é
ÆôÓÃÄ£¿éa2enmod Ä£¿é
ÈçÆôÓÃphp7.4  a2enmod php7.4
apache2ÆôÓõÄһЩģ¿é
a2enmod rewrite
a2enmod file_cache
a2enmod cache
a2enmod socache_memcache
a2enmod deflate  Ñ¹Ëõ
ÆôÓÃssl  a2enmod ssl
£¨Çë×¢ÒâÉÏÃæµÄÄ£¿éÆôÓúóÒªservice apache2 restartÒ»´Î,Èç¹ûÄã¸Õ²Å×°apache2ûÓÐÆô¶¯apache2¾ÍÏÈservice apache2 startÈ»ºóÔÙservice apache2 restartÒ»´Î,ÎÒ¿ªÊ¼Ê±ÊÇÍ£Ö¹ÈÝÆ÷ÔÙÆô¶¯ÈÝÆ÷,·¢ÏÖûÓñØÐëservice apache2 restartÒ»´Î)
»¹Òª¸ÄÒ»ÏÂphp.iniÎļþÈ¥³ýÉÏ´«Îļþ´óСµÄÏÞÖÆ
nano»òvim /etc/php/7.4/apache2/php.ini
upload_max_filesize = 8m ;ÍûÎÄÉúÒ⣬¼´ÔÊÐíÉÏ´«Îļþ´óСµÄ×î´óÖµ¡£Ä¬ÈÏΪ2M(ÎҸijÉÁË256M)
post_max_size = 8m ;ָͨ¹ý±íµ¥POST¸øPHPµÄËùÄܽÓÊÕµÄ×î´óÖµ£¬°üÀ¨±íµ¥ÀïµÄËùÓÐÖµ¡£Ä¬ÈÏΪ8M(ÎҸijÉÁË256M)
max_execution_time = 600 ;ÿ¸öPHPÒ³ÃæÔËÐеÄ×î´óʱ¼äÖµ(Ãë)£¬Ä¬ÈÏ30Ãë
max_input_time = 600 ;ÿ¸öPHPÒ³Ãæ½ÓÊÕÊý¾ÝËùÐèµÄ×î´óʱ¼ä£¬Ä¬ÈÏ60Ãë
memory_limit = 8m ;ÿ¸öPHPÒ³ÃæËù³ÔµôµÄ×î´óÄڴ棬ĬÈÏ8M(php7.4ĬÈÏ128MÎÒûÓиĴó)
max_file_uploads=20   Ò»¸öÒ³ÃæĬÈÏÉÏ´«¶àÉÙÕŸijÉ512(ÎҸijÉÁË512M)
ÕâЩ¸ÄÍêºóÖØÆôapache2 service apache2 restart
È»ºóÄã¿ÉÒÔ²âÊÔÒ»ÏÂhttpºÍphpÓÐûÓгɹ¦Ä¬ÈÏÍøÕ¾µÄĿ¼ÊÇÔÚ/var/www/htmlÏ»áÉú³ÉÒ»¸öindex.htmlÄã¿ÉÒÔÏÈnetstat -an¿´¿´·þÎñ¾¿¾¹ÓÐûÓÐÆðÀ´

Äã¿´µ½Óиö0.0.0.0:80˵Ã÷ÆðÀ´ÁË,¿ÉÒÔ²âÊÔÏÂcurl localhost:80»á³öÀ´Ò»¶Ñhtml´úÂë(ÎÒûӳÉä¶Ë¿Úû·¨´ò¿ªä¯ÀÀÆ÷²âÊÔ)¾Í˵Ã÷ÒѾ­ÔÚ½âÊÍhtml´úÂëÁË,ÔÙÔÚ/var/www/htmlÏ´´½¨Ò»¸öphpÎļþ¿´Äܲ»ÄܽâÊÍphpÏÈcdµ½htmlÏÂcd /var/www/html
touch info.php
echo "<?php phpinfo(); ?>" > info.php
È»ºócurl localhost/info.phpÄãÏÈÓÖ¿´µ½Ò»¶ÑµÄhtml´úÂë±íʾphpÒ²ÄܽâÊÍÁË,ÏÂÃæ¾Í¿ªÊ¼×°mysqlÁË
ubuntu16.04×Ô´øµÄ²Ö¿âµÄmysqlÊÇ5.7Èç¹ûÄãÖ±½Óapt install mysql-serverµÄ»°ÊÇ×°µÄmysql5.7,ÕâÎÒÄÇÔ¸Òâ(ÆäʵÕæʵµÄÇé¿öÊÇmysql5.7ÔÚºóÃæµÄdockerÓ³ÉäÎļþ¼ÐʱºÜ·³,ÒªÏȵ¼³ösqlÎļþÔÙµ¼ÈëÌرðÊǹý¼¸Ìì»áͻȻÀïÃæµÄdebianÕË»§»áÏûʧ¸ãµÃÈκÎÓû§¶¼µÇ½²»ÁË,³ÔÁ˲»ÉÙ¿÷,mysql8Ƥʵһµã,»¹ÓÐmysql5.7ÔÚ´´½¨mysqlÓû§Ê±ÔÚ/etc/passwdÀïµÇ¼ÇÊÇÕâÑùµÄmysql:x:110:106:MySQL Server,,,:/nonexistent:/bin/falseÖ±½Óµ¼ÖÂÔÚÆô¶¯mysqlʱ»á³ö¸öÕÒ²»µ½/homeµÄ´íÎó,Òª¸Ä³Émysql:x:106:111:MySQL Server,,,:/var/lib/mysql/:/bin/false²Å¿ÉÒÔ)
ÏÂÃ濪ʼ°²×°mysql,ÓÉÓÚ±¾Éí²Ö¿âÖ»Ö§³Ömysql5.7,ËùÒÔҪȥmysql¹ÙÍøÏÂһϰ²×°½Å±¾ÅäÖÆÎļþ:
ÏÈcdµ½/tmpÏÂÒòµÈ°²×°ÍêÁËҪɾ³ýÕâ¸öÎļþcd /tmpÈ»ºó
wget https://dev.mysql.com/get/mysql-apt-config_0.8.10-1_all.debÄãÈç¹ûûÓÐ×°wget¾Í×°Ò»ÏÂ
apt install wget
dpkg -i mysql-apt-config_0.8.10-1_all.deb
apt update
È»ºó¾ÍÊÇ°²×° apt install mysql-server php7.4-mysql(ÄǸömysql-client ÎÒûÓÐ×°,²»ÖªµÀÓÐûÓÐÓÃÎÒ¿´Ò²²»Ó°ÏìʹÓÃ)»á³öÀ´ÓÐ4¸öÑ¡ÏîµÄ´°¿Ú,Ñ¡Ôñ4.okÓÖ»á³öÀ´Ò»¸ö´°¿Ú£¬ÌáʾÄãÊäÈëmysqlµÄrootÃÜÂë,Ëæ±ãÊäÈëÖ»ÒªÄã¼Çס¾ÍºÃÒÔºóÒªÁ¬Êý¾Ý¿âÒªÓõ½

½ÓÏÂÀ´µÄ´°¿ÚÊÇ£§Äú¿ÉÒÔÈ·ÈÏÊÇ·ñҪʹÓÃеÄÃÜÂë¼ÓÃܹ¦ÄÜ¡­¡­¡°ÍƼö",ÎÒûÓÐÒªËü"ÍƼö"ÎÒÑ¡Á˺Ímysql5x¼æÈÝ.
È»ºó¾ÍÊÇ°²×°Ö±µ½Íê³É.

µ«Êǵ±ÎÒÆô¶¯mysql·þÎñʱ service mysql start¸æËßÎÒûÓÐÕâ¸ö·þÎñ,ÕâÔõô¿ÉÄÜ,ÎÒ¸Õ¸Õ×°µÄÎÒcdµ½init.dÏÂÃæ cd/etc/init.d
lsһϷ¢ÏÖȷʵûÓÐmysqlÆô¶¯½Å±¾,ÕâÊÇÔõô»ØÊÂ,ºóÀ´¾­¹ý¶à·½Á˽â,ÓÖÈ¥¹Ù·½ÍøÕ¾ÉÏ¿´ÁË,"ÓÐÒ»ÖÖÐèÒª½ÐËûÃÇÈÏΪÄã²»ÐèÒª",Ô­À´ÊÇ´Óubuntu16¿ªÊ¼²»ÓÃÒÔÇ°µÄserviceÁ˸ÄÓÃsystemctlÁË,ÕâÑùµÄ»°µÃ×°systemd¿ÉÎÒÓÖ²»Ïë×°,ûÓÐÄǾ͵ÃÏë°ì·¨,ÎÒÖØн¨Á˸öÈÝÆ÷×°ÁËmysql5.7°ÑÀïÃæµÄmysql½Å±¾Ìá³öÀ´·Åµ½init.dÀï,Æô¶¯·¢ÏÖ²»ÐÐ,Ìáʾ»µµÄ.ºóÀ´ÓÖÈ¥¹Ù·½ÕÒ,¿´µ½¹Ù·½µÄmysql8ÓÐÒ»ÖÖ¶þ½øÖÆ°²×°°ü,ÎÒ°ÑËüÏÂÔØÏÂÀ´,ËüÖ»Ðè°Ñ°²×°°üµÄÎļþ¸´ÖƵ½/usr/localÏÂÃæ¾Í¿ÉÔËÐÐ,ÎÒ°ÑËüµÄÆô¶¯½Å±¾¿½±´³öÀ´,ÓÃnotepad++´ò¿ª°´ÕÕµÄmysql8µÄ°²×°Ä¿Â¼¸ÄÁËϸ´ÖƵ½init.dÏÂ,¼ÓÖ´ÐÐȨÏÞ,chmod +x mysqlºóservice mysql startÖÕÓÚÔËÐÐÆðÀ´ÁË.¾Í¸ÄÒ²ÏÂÃæÕ⼸Ïî

Ïë°Ñmysql ½Å±¾´«ÉÏÀ´,¸ù±¾¾Í´«²»ÁË,¸Ä³Ézip txt¶¼Ëµ²»Ö§³Ö,Ã÷Ã÷¸½¼þÀàÐÍÀïÓÐÕâÖÖÀàÐÍ,ҲСÓÚ1M²»ÖªµÀÔõô»Ø²»,´ó¼Ò¿ÉÒÔ´Ómysql¹ÙÍøÏÂÔضþ½øÖÆ°üÌáÈ¡ÀïÃæµÄmysql½Å±¾È»ºó°´ÕÕÄãµÄmysqlĿ¼ÏñÎÒÉÏÃæÄÇÑù¸Ä¾Í¿ÉÒÔÁË.ÏÖÔÚapache2ºÍmysqlÁ½¸ö·þÎñ¶¼¿ÉÒÔÔËÐÐÁË,ÊÇÓ¦¸Ã°ÑËü±£´æ³É¾µÏñÁË
docker commit ubuntu "ubuntucn:new"
È»ºóÓÃÕâ¸öеľµÏñÖØд´½¨ÈÝÆ÷,ÕâÒ»´ÎµÃ¹æ»¯ºÃ,Ê×ÏÈÔÚÖ÷»úµÄ/dockÎļþ¼ÐÏÂн¨Á˸ödzzofficeÎļþ¼Ð,ÔÙÔÚdzzofficeÎļþ¼ÐÏÂн¨dataºÍhtml
cd /dock
mkdir dzzoffice
cd /dzzoffice
mkdir data html
chown -R www-data:www-data /dock/dzzoffice
chmod 777 /dock/dzzoffice
ÉÏÃæµÄchownÊǸü¸ÄËùÓÐÕß,www-dataÊÇubuntu×Ô´øµÄÒ»¸öÓû§,chmod 777ÎÒ¸øÁËÍêÈ«µÄȨÏÞ,ÓÐÈË˵Õâ²»°²È«,µ«¶ÔÎÒÃÇÕâЩС°×À´Ëµ, ÔËÐÐÆðÀ´²ÅÊÇÍ·µÈ´óÊÂ,ÆäËüµÄÒÔºóÔÙ˵.
¶Ë¿ÚÔÝʱ¶¨Îª8080:80 8081:3306¿ªÊ¼docker run
docker run -itd --privileged --name ubuntunew -p 8080:80 -p 8081:3306 -v /dock/dzzoffice/data:/var/lib/mysql -v /dock/dzzoffice/html:/var/www/html ubuntucn:new
ÈÝÆ÷ÔËÐÐÆðÀ´ÁË,ÎÒÁ¬Ã¦´ò¿ªä¯ÀÀÆ÷ÊäÈëÖ÷»úµØÖ·+8080,http://192.168.18.20:8080¸æËßÎÒÎÞ·¨·ÃÎÊ´ËÍøÕ¾,àÅ,docker exec½øÈ¥¿´Ò»ÏÂ
netstat -anÒ»¸ö·þÎñҲûÓÐÆô¶¯,àÞ,ûÓмÓÈëÆô¶¯×é,È¥ÍøÉÏËÑÈçºÎʱ°Ñubuntu·þÎñ¼ÓÈëÆô¶¯×é,update-rc.d ·þÎñ defaults 99ÓÚÊÇÎÒ°Ñapache2ºÍmysql¶¼¼ÓÈëÆô¶¯×éºóÀ´ÓÖ

update-rc.d ·þÎñ enable
ÓÖ
sysv-rc-conf ·þÎñ on
Ò²¿´ÁË/etc/ÏÂÃærc0.d~rc6.dÀïÃ涼ÓÐapache2ºÍmysql,µ«ÊÇÖØ×ö¾µÏñºóÕâÁ½·þÎñ¾ÍÊDz»Æô¶¯.ÓÖÊÇÒ»¶Ù¿ñËÑ,ÂýÂýµÄÁ˽âÁËdockerÆô¶¯µÄ»úÖÆ,Ëü¾ÍÊÇÒ»¸ö½ø³Ì,¸ù±¾Ã»ÓÐÆô¶¯×éһ˵,Äã¾Í°ÑËüÏë³ÉwindowsÀïµÄÒ»¸öÈí¼þÈçqq,Ö»²»¹ýÕâ¸öÈí¼þÀïÃæÓÖ¿ÉÒÔ×°Èí¼þ,ÈÃÄãÒÔΪËüÊÇÒ»¸öϵͳ,Ϊ²»²»ºÍÔ­À´µÄÈí¼þ³åÍ»,,ÓÃÁËһЩ¹Ø¼ü×Ö×÷¸ôÀë,µ¼ÖÂÖ÷»úϵͳ¸ù±¾ÕÒ²»µ½ÈÝÆ÷ÀïµÄÈí¼þ,̸ºÎÆô¶¯(ÕâЩֻÊÇÎÒÏëÏñµÄ,Ò²²»ÖªµÀ¶Ô²»¶Ô,ÓиßÊÖÈç¹û¾õµÃ²»¶Ô,»¶Ó­¶ÔÎÒÌá³öÅúÆÀ,°ïÎÒ¾ÀÕý¹ýÀ´.)ËùÒÔdockerÌṩÁËÒ»¸öÆô¶¯ÃüÁî,²»¹ýÒªÖØй¹½¨.
ÓÃdocker build -f dockerfile -t "new:tag" .
ÓÚÊÇдÁËdockerfileÎļþchen
touch chen
nano chen
chenÄÚÈÝ:
#!/bin/bash
FROM ubuntucn:new
CMD service apache2 start && service mysql start

tail -f /dev/null
ctrl+x±£´æÊäÈëy¼Ó»Ø³µ
docker build -f chen -t "ubuntucn:new1" .
ÖØд´½¨ÈÝÆ÷,docker run -itd --privileged --name ubuntunew1 -p 8080:80 -p 8081:3306 -v /dock/dzzoffice/data:/var/lib/mysql -v /dock/dzzoffice/html:/var/www/html ubuntucn:new1Õâ´Î¸ÕÔËÐÐÁ¢ÂíÈÝÆ÷¾ÍÍ˳öÁË,ÒâÍâÖÐÖ¹,ÕâÊÇÈçºÎÒ»»ØÊÂ,³éÁËÒ»¸ùÑÌ,ÔÚÄÇ˼Ë÷.
ÌýÁ˼¸Ê׸è,»¹ÊǹýÀ´¸ã,Õâ´ÎÎÒ°Ñ

CMD service apache2 start && service mysql start
¸Ä³ÉCMD service apache2 start
Ö»Æô¶¯Ò»¸ö,˳ÀûÆô¶¯,ÄÇÎÊÌâ³öÔÚmysqlÉÏ,ÎÒ
docker exec -it ubuntunew1 /bin/bash
½øÈ¥service mysql start
¾¹È»Ã»Æô¶¯ÆðÀ´,ÔÙÒ»¿´,/var/lib/mysqlĿ¼һƬ¿Õ°×,Ô­À´ÊÇÎÒÓ³ÉäĿ¼/dock/dzzoffice/data:/var/lib/mysqlÓÃÖ÷»úµÄdataĿ¼°ÑmysqlĿ¼¸²¸ÇÁË,Õâ¿ÉÔõô°ì,µ«mysqlĿ¼±ØÐëÓ³Éä³öÀ´,ÒòÈÝÆ÷һɾ³ýµÄ»°¶«Î÷ȫûÁ˱ØÐëÓ³Éäµ½ÍⲿĿ¼²ÅÐÐ,ÕýºÃÄǶÎʱ¼ägpt¿ªÊ¼Á÷ÐÐ,¾Ý˵gptÎÞËù²»Öª,ÎÒÒ²½øµ½ËüµÄÍøÒ³°æºÍgpt¸ô¿Õ¶Ô»°ÁËÒ»´Î,Ëü¸ø³öÁËÁ½¸ö½¨Òé,Ò»ÊǹҾô洢,»¹ÓÐÒ»¸öÊÇmount¼ÓroÖ»¶Á,ÕâÁ½¸ö·½·¨¶¼²»ÊÇÎÒÏëÒªµÄ,ÎÊËü»¹Ã»ÓÐÓбðµÄ°ì·¨,Ëü½¨ÒéÎÒÈ¥dock¹Ù·½È¥Á˽â,¶¼È¥¹Ù·½ÁË»¹ÒªÄã¸ÉÂï,ûÏëµ½gptÒ²»á·¢»ð,"ÎÒÖ»ÊǸö³ÌÐòÄã¸úÎÒ·¢Ê²Ã´»ð"Ò»¸öÆƳÌÐòÒ²·¢ÀÎɧ,ÐÄÀïÏëgptÒ²²»¹ý¶û¶û,(µ±Ê±ºÃÏñÒ²ºÍgptÌÖÂÛÁËdockerÈÝÆ÷µÄÆô¶¯»úÖÆ,Ó³ÉäÖ÷»úĿ¼ÊÇÔÚdockerÆô¶¯Ö®Ç°¾ÍÓ³É仹ÊÇdockerÆô¶¯ÆðÀ´²ÅÓ³Éä,±¾À´»¹ÏëÔÚÕâÀïÏëÏë°ì·¨µÄ,ËüÒ»·¢ÀÎɧ°ÑÎÒµÄ˼Ð÷È«´òÂÒÁË)û°ì·¨ÓÖÈ¥¹Ù·½Á˽â,È«ÎÄ·­ÒëÂýÂýµÄ¿´,»ù±¾ÉÏÒ²¾ÍÄÇÁ½ÕÐ,ÐÄÀïÍÛÁ¹,ÂþÎÞÄ¿µÄµÄÔÚgoogleÉÏËÑ,ͻȻһ¸öÌù×ÓÒýÆðÁËÎÒµÄ×¢Òâ,ÊǹØÓÚmysqlÖØгõʼ»¯µÄ,ÎÒµã½øÈ¥Ò»¿´,Õâ²»ÕýÊÇÎÒËùÐèÒªµÄÂð,ÎÒÁ¬Ã¦°ÑËûµÄÕâ¶ÎÎÄ×ÖÓÃnotepad++¸´ÖÆÁ˱£´æÁËÆðÀ´,µ«Ëûû½²ÈçºÎ³õʼ»¯,ÕâºÃ°ì,ÓÐÁËÄ¿µÄËÑË÷,¸ù±¾²»ÐèÒªgpt,ÎÄÐÄÒ»ÑÔ¶¼ÖªµÀÁË,²¢ÇÒ¸ø³öÁ˽ű¾,»¹ÓÐ×¢ÒâÊÂÏî.
mysql8³õʼ»¯
mysqld --initialize-insecure
chown -R mysql:mysql /var/lib/mysql /var/run/mysqld
service mysql start
sleep 5
mysql -uroot --skip-password <<EOF
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "$MYSQL_ROOT_PASSWORD";
create user 'root'@'%' identified with mysql_native_password by "$MYSQL_ROOT_PASSWORD";
grant all privileges on *.* to 'root'@'%' with grant option;
FLUSH PRIVILEGES;
quit
ÆäÖÐchown -R mysql:mysql /var/lib/mysql /var/run/mysqldÊÇÎÒºó¼ÓµÄ,ÒòÀÏÊDz»ÊÇlogÎļþÎÞ·¨´´½¨¾ÍÊÇmysqld.sock²»ÄÜ´´½¨,ËùÒÔÎÒÒ»¹ÅÄÔ¶¼¼ÓÁË
$MYSQL_ROOT_PASSWORDÒ²ÊǺó¼ÓµÄÄ¿µÄÊÇÌáÈ¡»·¾³±äÁ¿µÄÖµ,ÕâÑùÔÚ½¨ÈÝÆ÷ʱ¿ÉÒÔÖ¸¶¨mysqlµÄrootÃÜÂë,ÎÒ¿ªÊ¼Ôڽű¾ÖÐû¼ÓË«ÒýºÅµ¼ÖÂmysqlÒýÓõÄÃÜÂëÊÇ$MYSQL_ROOT_PASSWORD±¾Éí¶ø·ÇËüµÄÖµ,ÄãÓÃecho $MYSQL_ROOT_PASSWORDÈ¥¿´¾Í¶ÔµÄµ«mysqlÒýÓþͳö´íËùÒÔÒª¼ÓË«ÒýºÅ
ÓÚÊÇdockerfileÎļþÒªÐÞ¸ÄÁË,ÏÈɾ³ýÎÒ´´½¨µÄubuntucn1ÈÝÆ÷ÔÙɾ³ýbuildµÄ¾µÏñ
docker stop ubuntunew1
docker rm ubuntunew1
docker images
docker rmi ubuntucn:new1
Ô­chenÄÚÈÝ
#!/bin/bash
FROM ubuntucn:new
CMD service apache2 start && service mysql start
Ð޸ĺó
#!/bin/bash
FROM ubuntucn:new
ENTRYPOINT  ["/usr/bin/chen.sh"]
È»ºóÔÚ/usr/bin´´½¨chen.sh½Å±¾
cd /usr/bin
touch chen.sh
chmod +x chen.sh
nano chen.sh
chen.shÄÚÈÝ
#!/bin/bash
#³õʼ»¯Mysql Êý¾Ý¿â
mysqld --initialize-insecure
echo "ÕýÔÚ³õʼ»¯MYSQLÊý¾Ý¿â"
chown -R mysql:mysql /var/lib/mysql /var/run/mysqld /var/log/mysql
service mysql start
echo "ÕýÔÚÆô¶¯MYSQLÊý¾Ý¿â,ÉèÖÃÃÜÂëºÍÔ¶³Ì"
sleep 5
mysql -uroot --skip-password <<EOF
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "$MYSQL_ROOT_PASSWORD";
create user 'root'@'%' identified by "$MYSQL_ROOT_PASSWORD";
grant all privileges on *.* to 'root'@'%' with grant option;
FLUSH PRIVILEGES;
quit
EOF
echo "ÕýÔڹرÕMYSQL·þÎñÆ÷"
service mysql stop
echo "ÕýÔÚÆô¶¯ÍøÒ³·þÎñÆ÷"
service apache2 start
#Æô¶¯ Mysql ·þÎñÆ÷
service mysql start
echo "MYSQL+apache+phpÆô¶¯Íê³É,AMP»·¾³´î½¨Íê³É,¿ÉÒÔʹÓÃÁË"
tail -f /dev/null
ÖØб¾µØ¹¹½¨
docker build -f chen -t "ubuntucn:new1" .
Ôٴδ´½¨ÈÝÆ÷
docker run -itd --privileged --name ubuntunew1 -p 8080:80 -p 8081:3306 -v /dock/dzzoffice/data:/var/lib/mysql -v /dock/dzzoffice/html:/var/www/html ubuntucn:new1
ÈÝÆ÷³É¹¦ÔËÐÐÁË,ÎÒdocker exec½øÈ¥·¢ÏÖmysqlȷʵÆô¶¯³É¹¦ÁË,µ«ÊÇÎÒûÓз¢ÏÖapache2·þÎñ,ÔٴιرÕÈÝÆ÷£¬ÔÙÖØÆô¶¯,ÈÝÆ÷ÓÖÍ˳öÁË,ÒâÍâÖÐÖ¹,Ôõô»ØÊ°¡,µã¿ªubuntunew1ÈÝÆ÷ÈÕÖ¾²é¿´·¢ÏÖÓÖÔÚ³õʼ»¯mysql,ÄѵÀÿ´Î´ò¿ªÈÝÆ÷Ëü¶¼³õʼ»¯Ò»±é,ÓÚÊǼÓÁËÌõ¼þÅжÏ,ÔÙ´Îbuild,½Å±¾ÄÚÈÝÐÞ¸ÄÈçÏÂ:
chen.shÄÚÈÝ
#!/bin/bash
#³õʼ»¯Mysql Êý¾Ý¿â
if [ ! -f "/var/lib/mysql/initialized" ]; then
mysqld --initialize-insecure
echo "ÕýÔÚ³õʼ»¯MYSQLÊý¾Ý¿â"
chown -R mysql:mysql /var/lib/mysql /var/run/mysqld /var/log/mysql
service mysql start
echo "ÕýÔÚÆô¶¯MYSQLÊý¾Ý¿â,ÉèÖÃÃÜÂëºÍÔ¶³Ì"
sleep 5

mysql -uroot --skip-password <<EOF
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "$MYSQL_ROOT_PASSWORD";
create user 'root'@'%' identified by "$MYSQL_ROOT_PASSWORD";
grant all privileges on *.* to 'root'@'%' with grant option;
FLUSH PRIVILEGES;
quit
EOF

echo "MYSQL³õʼ»¯Íê³É,ÕýÔÚдÈë±êÖ¾Îļþ"
touch /var/lib/mysql/initialized
echo "ÕýÔڹرÕMYSQL·þÎñÆ÷"
service mysql stop
fi
echo "ÕýÔڹرÕMYSQL·þÎñÆ÷"
service mysql stop
echo "ÕýÔÚÆô¶¯ÍøÒ³·þÎñÆ÷"
service apache2 start
#Æô¶¯ Mysql ·þÎñÆ÷
service mysql start
echo "MYSQL+apache+phpÆô¶¯Íê³É,AMP»·¾³´î½¨Íê³É,¿ÉÒÔʹÓÃÁË"
tail -f /dev/null
Õâ´ÎÎÒ²»docker exec½øÈ¥ÁË£¬ÎҾͿ´ÈÕÖ¾ÁË,·¢ÏÖµÚ¶þ´Î²¢Ã»Óгõʼ»¯,ÏÔʾ"MYSQL+apache+phpÆô¶¯Íê³É,AMP»·¾³´î½¨Íê³É,¿ÉÒÔʹÓÃÁË"
ÎҲŽøÈ¥¿´,·¢ÏÖapache2»¹ÊDz»¼ûÁË,ÄѵÀdockerÖ»ÄÜÆô¶¯Ò»¸ö·þÎñ,²»¶Ô°¡,ÎÒÔÚÀïÃæÔÙservice apache2 startÊÇ¿ÉÒԵİ¡,¶øÇÒÒ²ÓÐÈË×öÁËapache2+mysql8µÄ¾µÏñµÄ°¡,ÓÚÊÇÔٴθĶ¯,ÎÒ°Ñapache2ÒƵ½½Å±¾¶¥ÉÏ,ÓÖ¼ÓÁËÁ½Ãë͢ʱ,ÐÞ¸ÄÈçÏÂ
chen.shÄÚÈÝ
#!/bin/bash
echo "ÕýÔÚÆô¶¯ÍøÒ³·þÎñÆ÷"
service apache2 start
sleep 2
#³õʼ»¯Mysql Êý¾Ý¿â
if [ ! -f "/var/lib/mysql/initialized" ]; then
mysqld --initialize-insecure
echo "ÕýÔÚ³õʼ»¯MYSQLÊý¾Ý¿â"
chown -R mysql:mysql /var/lib/mysql /var/run/mysqld /var/log/mysql
service mysql start
echo "ÕýÔÚÆô¶¯MYSQLÊý¾Ý¿â,ÉèÖÃÃÜÂëºÍÔ¶³Ì"
sleep 5

mysql -uroot --skip-password <<EOF
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "$MYSQL_ROOT_PASSWORD";
create user 'root'@'%' identified by "$MYSQL_ROOT_PASSWORD";
grant all privileges on *.* to 'root'@'%' with grant option;
FLUSH PRIVILEGES;
quit
EOF

echo "MYSQL³õʼ»¯Íê³É,ÕýÔÚдÈë±êÖ¾Îļþ"
touch /var/lib/mysql/initialized
echo "ÕýÔڹرÕMYSQL·þÎñÆ÷"
service mysql stop
fi
echo "ÕýÔڹرÕMYSQL·þÎñÆ÷"
service mysql stop
#Æô¶¯ Mysql ·þÎñÆ÷
service mysql start
echo "MYSQL+apache+phpÆô¶¯Íê³É,AMP»·¾³´î½¨Íê³É,¿ÉÒÔʹÓÃÁË"
tail -f /dev/null
Õâ´Î˳ÀûÆô¶¯³É¹¦,½øÈ¥netstat -an ²é¿´apache2ºÍmysql·þÎñ¶¼Æô¶¯µÃºÃºÃµÄ.ÕâÏÂÍòÊ´ó¼ªÁË,°ÑÈÝÆ÷ɾ³ýÁË,Öع¹Á˾µÏñ,ÖØÃüÃûΪubuntucn:base×÷ΪÎÒµÄamp»ù´¡¾µÏñ²¢docker save±£´æÁËÒ»¸ötarÎļþ±¸·Ýµ½ÎҵıʼDZ¾ÉÏ,ºÃ²»ÈÝÒ××öµÄ,²»Äܶª.
È»ºó¾ÍÊÇÓÃÕâ¸ö»ù´¡¾µÏñ´´½¨ÁËdzzofficeÈÝÆ÷ºÍwordpressÈÝÆ÷,µ±Á½¸öÈÝÆ÷¶¼Æô¶¯Ê±,ÎÊÌâÀ´ÁË,²»ÊÇdzzofficeµÄmysqlÆô¶¯²»³É¹¦¾ÍÊÇwordpressµÄmysqlÆô¶¯Î´³É¹¦,Òª½øÈ¥ÔÙservice mysql startһϲÅÐÐ,ÐÄÀïÏëÊDz»ÊÇÁ½¸öÈÝÆ÷µÄmysqlͬʱÆô¶¯´ò¼ÜÁË,ÓÚÊÇÎÒµ÷ÁËһϽű¾ÀïµÄsleepʱ¼ä,
°ÑÆäÖÐÒ»¸öÆô¶¯Ê±¼ä¾³¼ÓÁË5Ãë,ÔÙ´ÎÁ½¸öÈÝÆ÷ͬʱÆô¶¯,ºÃÏñÊÇÐеÄ,µ«ÊÇÐÄÀï×ÜÊDz»Êæ·þ,ÎÒҲûÓÐÖع¹¾µÏñ.¾ÍÕâôÏÈÓðÉ,¹ýÁËÒ»¶Îʱ¼ä,ÓÐÒ»ÌìÔÚÍøÉϲ»ÖªËÑʲô¶«Î÷ʱ¿´µ½ÓÐÒ»¸öÌù×Ó,½²dockerÈÝÆ÷¹Ø±ÕʱÈçºÎÓÅÑŵĹرշþÎñ,ºÃÆæµã½øÈ¥¿´ÁËÒ»ÏÂ,½²µÄÊÇlinux¶¼ÓÐÒ»¸ötrapÃüÁî,¿ÉÒÔÔڽű¾Öе÷ÓÃtrapÃüÁîÖ´ÐÐһЩָÁî,ÒªÏëÓÃtrapÃüÁîÏȵù¹½¨Ò»¸öº¯Êý.ÈçÏÂ
clean_up_term() {ÃüÁî}
trap clean_up_term SIGTERM
º¯Êý¹¹½¨ÔÚÇ°,µ÷ÓÃÔÚºó,ÎÒÒ»Ïë,ÎÒÒ²Òª±£»¤ÎÒµÄÊý¾Ý,Ò²¸ú×ÅÔÚdzzofficeµÄchen.sh½Å±¾ÖмÓÁËÕâ¸ö´úÂë
clean_up_term() {
service mysql stop
echo "mysqlÒѹرÕ"
}
trap clean_up_term SIGTERM
·¢ÏÖ¸ù±¾²»Æð×÷ÓÃ,²é¿´ÈÕ־ûÓз¢ÏÖ"mysqlÒѹرÕ"µÄÌáʾ,Ò²¾Í²»ÔÚÑо¿,·´ÕýdzzofficeºÍwordpressÄÜÓþʹպÏ×ÅÓÃ×Å,Ö±µ½ÉÏÐÇÆÚ,ÎÒ×°jsbinÍøÒ³Á·Ï°Æ÷ʱ˳±ãÎÊÁËgptÒ»´ÎtrapÃüÁîΪʲôûÆð×÷ÓÃ,ÖÕÓڵõ½ÁËÓÐÓõĻشð,jsbinµ¹ÊÇûŪÆðhttpsÀ´.
gpt½¨ÒéÎÒ°Ñtail -f /dev/null»»³Éwait -n,È»ºóÆô¶¯apache2ºÍmysql¶¼ÓÃǰ̨ÃüÁî,ÕâÑù²ÅÄÜ·½±ãtrap²¶×½µ½½ø³ÌÐźÅ,²ÅÄÜÓÅÑŵĹرÕËüÃÇ.
ÄǸöapache2ǰ̨ÔËÐÐÎÒÖªµÀµÄapachectl -D FOREGROUND &µ«ÊÇmysqlǰ̨ÎÒ²»ÖªµÀ,ÓÚÊÇÎÒ°´ÕÕÎÒ×ÔÒѵÄÏë·¨°Ñ½Å±¾×÷ÈçϸĶ¯.
#!/bin/bash
#³õʼ»¯Mysql Êý¾Ý¿â
if [ ! -f "/var/lib/mysql/initialized" ]; then
mysqld --initialize-insecure
echo "ÕýÔÚ³õʼ»¯MYSQLÊý¾Ý¿â"
chown -R mysql:mysql /var/lib/mysql /var/run/mysqld /var/log/mysql
service mysql start
echo "ÕýÔÚÆô¶¯MYSQLÊý¾Ý¿â,ÉèÖÃÃÜÂëºÍÔ¶³Ì"
sleep 5

mysql -uroot --skip-password <<EOF
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "$MYSQL_ROOT_PASSWORD";
create user 'root'@'%' identified by "$MYSQL_ROOT_PASSWORD";
grant all privileges on *.* to 'root'@'%' with grant option;
FLUSH PRIVILEGES;
quit
EOF

echo "MYSQL³õʼ»¯Íê³É,ÕýÔÚдÈë±êÖ¾Îļþ"
touch /var/lib/mysql/initialized
echo "ÕýÔڹرÕMYSQL·þÎñÆ÷"
service mysql stop
fi

#Æô¶¯ Mysql ·þÎñÆ÷
echo "ÕýÔÚÆô¶¯MYSQL·þÎñÆ÷"
service mysql start

echo "ÕýÔÚÆô¶¯ÍøÒ³·þÎñÆ÷"
apachectl -D FOREGROUND &
echo "MYSQL+apache+phpÆô¶¯Íê³É,AMP»·¾³´î½¨Íê³É,¿ÉÒÔʹÓÃÁË"

clean_up_term() {
echo "ÈÝÆ÷ÕýÔÚÍ£Ö¹£¬¹Ø±Õ MySQL..."
mysqladmin -uroot -p$MYSQL_ROOT_PASSWORD shutdown
echo "¹Ø±Õ Apache..."
apachectl -k stop
sleep 5
if ! pgrep mysqld > /dev/null && ! ps aux | grep -v grep | grep apache2 > /dev/null; then
echo "mysqlÒѹرÕ"
echo "apache2ÒѹرÕ"
else
echo "mysql»¹ÔÚÔËÐÐ"
echo "apache2»¹ÔÚÔËÐÐ"
fi
}

trap clean_up_term SIGTERM

wait -n
ÕâЩ½Å±¾Åж϶¼ÓÉÎÊgpt¼ÓÉÏÎÒÕûÀíÔÙ¼ÓÉÏÎÒµÄÏë·¨¶øÀ´,ºóÀ´ÎÒÓÖ¼ÓÁËÒ»¸öphpmyadmin,ÎÒÔÚphpmyadminÍøÕ¾ÉÏÏÂÁËphpMyAdmin-5.2.1-all-languages.zip°ÑËü½âѹµ½ÁË/usr/shareĿ¼ÏÂÖØÃüÃû³ÉphpmyadminÎļþ¼Ð,È»ºóÔڽű¾Àï¼ÓÁË·ûºÅ¼ü½Ó,×îÖսű¾ÈçÏÂ:
#!/bin/bash
#³õʼ»¯Mysql Êý¾Ý¿â
if [ ! -f "/var/lib/mysql/initialized" ]; then
mysqld --initialize-insecure
echo "ÕýÔÚ³õʼ»¯MYSQLÊý¾Ý¿â"
chown -R mysql:mysql /var/lib/mysql /var/run/mysqld /var/log/mysql
service mysql start
echo "ÕýÔÚÆô¶¯MYSQLÊý¾Ý¿â,ÉèÖÃÃÜÂëºÍÔ¶³Ì"
sleep 5

mysql -uroot --skip-password <<EOF
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY "$MYSQL_ROOT_PASSWORD";
create user 'root'@'%' identified by "$MYSQL_ROOT_PASSWORD";
grant all privileges on *.* to 'root'@'%' with grant option;
FLUSH PRIVILEGES;
quit
EOF

echo "MYSQL³õʼ»¯Íê³É,ÕýÔÚдÈë±êÖ¾Îļþ"
touch /var/lib/mysql/initialized
echo "ÕýÔڹرÕMYSQL·þÎñÆ÷"
service mysql stop
fi

#´´½¨·ûºÅÁ´½Ó
if [ ! -L /var/www/html/phpmyadmin ]; then
  ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
fi

#Æô¶¯ Mysql ·þÎñÆ÷
echo "ÕýÔÚÆô¶¯MYSQL·þÎñÆ÷"
service mysql start

echo "ÕýÔÚÆô¶¯ÍøÒ³·þÎñÆ÷"
apachectl -D FOREGROUND &
echo "MYSQL+apache+phpÆô¶¯Íê³É,AMP»·¾³´î½¨Íê³É,¿ÉÒÔʹÓÃÁË"

clean_up_term() {
echo "ÈÝÆ÷ÕýÔÚÍ£Ö¹£¬¹Ø±Õ MySQL..."
mysqladmin -uroot -p$MYSQL_ROOT_PASSWORD shutdown
echo "¹Ø±Õ Apache..."
apachectl -k stop
sleep 5
if ! pgrep mysqld > /dev/null && ! ps aux | grep -v grep | grep apache2 > /dev/null; then
echo "mysqlÒѹرÕ"
echo "apache2ÒѹرÕ"
else
echo "mysql»¹ÔÚÔËÐÐ"
echo "apache2»¹ÔÚÔËÐÐ"
fi
}

trap clean_up_term SIGTERM

wait -n
Õâ¾ÍÊÇÎÒÏÖÔÚÓõĽű¾,ͬʱÆô¶¯Ò²Ã»ÓÐÎÊÌâ.
дµ½ÕâÀï,ÎÒ»ØÍ·Ò»¿´,²»Öª²»¾õÖÐдÁËÒ»´ó¶Ñ,ÎÒÖªµÀÎÒ²»ÊʺÏдÕâ¸ö,ÂÞÂÞàÂàµÄ,˵ÁËÕâô¶àÒ²²»ÖªµÀ´ó¼ÒÄÜ·ñ¿´µÃÃ÷°×,ÆäʵÎÒÃÇÕâЩС°×ÐÂÊÖѧµã¶«Î÷ºÜÄÑ,ÏÖÔÚÍøÉÏÓÐÓõĶ«Î÷ÒѾ­²»¶àÁË,½øÂÛ̳ÓÖµÃ×¢²á˵²»¶¨»¹ÒªÑûÇëÂë»òÇ¿ÖƾèÔù,¼´Ê¹½øÈ¥ÁË,Ò²»¹Òªµ½ÐÂÊÖ´åѧϰÌáÎʵÄÖÇ»Û,¼´Ê¹ÎÊÁËҲû¶àÉÙÈËÀíÄã,´ó¼Ò¶¼ºÜæ,ÎÒÖ»ÊÇÏòͬÑùÊÇÐÂÊÖµÄÈËÌṩÎÒµÄһЩ¸öÈ˾­Àú,Ï໥·ö³Ö£®










ÄúÐèÒªµÇ¼ºó²Å¿ÉÒÔ»ØÌû µÇ¼ | ×¢²á

±¾°æ»ý·Ö¹æÔò

СºÚÎÝ|ÊÖ»ú°æ|Archiver|¾èÖúÖ§³Ö|ÎÞÓÇÆô¶¯ ( ÃöICP±¸05002490ºÅ-1 )

Ãö¹«Íø°²±¸ 35020302032614ºÅ

GMT+8, 2024-11-29 01:28

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

¿ìËٻظ´ ·µ»Ø¶¥²¿ ·µ»ØÁбí