麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 網(wǎng)站 > CMS建站 > 正文

再Docker中架設(shè)完整的WordPress站點(diǎn)全攻略

2020-03-22 19:30:41
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
1. 安裝 Docker在我們真正開(kāi)始之前,我們需要確保在我們的 Linux 機(jī)器上已經(jīng)安裝了 Docker。我們使用的主機(jī)是 CentOS 7,因此我們用下面的命令使用 yum 管理器安裝 docker。 # yum install docker # systemctl restart docker.service2. 創(chuàng)建 WordPress 的 Dockerfile我們需要?jiǎng)?chuàng)建用于自動(dòng)安裝 wordpress 以及其前置需求的 Dockerfile。這個(gè) Dockerfile 將用于構(gòu)建 WordPress 的安裝鏡像。這個(gè) WordPress Dockerfile 會(huì)從 Docker Registry Hub 獲取 CentOS 7 鏡像并用最新的可用更新升級(jí)系統(tǒng)。然后它會(huì)安裝必要的軟件,例如 Nginx Web 服務(wù)器、PHP、MariaDB、Open SSH 服務(wù)器,以及其它保證 Docker 容器正常運(yùn)行不可缺少的組件。最后它會(huì)執(zhí)行一個(gè)初始化 WordPress 安裝的腳本。 # nano Dockerfile然后,我們需要將下面的配置行添加到 Dockerfile中。 FROM centos:centos7 MAINTAINER The CentOS Project [email protected] RUN yum -y update; yum clean all RUN yum -y install epel-release; yum clean all RUN yum -y install mariadb mariadb-server mariadb-client nginx php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-magickwand php-magpierss php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy php-apc pwgen python-setuptools curl git tar; yum clean all ADD ./start.sh /start.sh ADD ./nginx-site.conf /nginx.conf RUN mv /nginx.conf /etc/nginx/nginx.conf RUN rm -rf /usr/share/nginx/html/* RUN /usr/bin/easy_install supervisor RUN /usr/bin/easy_install supervisor-stdout ADD ./supervisord.conf /etc/supervisord.conf RUN echo %sudo ALL=NOPASSWD: ALL /etc/sudoers ADD http://wordpress.org/latest.tar.gz /wordpress.tar.gz RUN tar xvzf /wordpress.tar.gz RUN mv /wordpress/* /usr/share/nginx/html/. RUN chown -R apache:apache /usr/share/nginx/ RUN chmod 755 /start.sh RUN mkdir /var/run/sshd EXPOSE 80 EXPOSE 22 CMD ["/bin/bash", "/start.sh"] 3. 創(chuàng)建啟動(dòng)腳本我們創(chuàng)建了 Dockerfile 之后,我們需要?jiǎng)?chuàng)建用于運(yùn)行和配置 WordPress 安裝的腳本,名稱為 start.sh。它會(huì)為 WordPress 創(chuàng)建并配置數(shù)據(jù)庫(kù)和密碼。用我們喜歡的文本編輯器打開(kāi) start.sh。 # nano start.sh打開(kāi) start.sh 之后,我們要添加下面的配置行到文件中。 #!/bin/bash __check() { if [ -f /usr/share/nginx/html/wp-config.php ]; then exit __create_user() { # 創(chuàng)建用于 SSH 登錄的用戶 SSH_USERPASS=`pwgen -c -n -1 8` useradd -G wheel user echo user:$SSH_USERPASS | chpasswd echo ssh user password: $SSH_USERPASS __mysql_config() { # 啟用并運(yùn)行 MySQL yum -y erase mariadb mariadb-server rm -rf /var/lib/mysql/ /etc/my.cnf yum -y install mariadb mariadb-server mysql_install_db chown -R mysql:mysql /var/lib/mysql /usr/bin/mysqld_safe & sleep 10 __handle_passwords() { # 在這里我們生成隨機(jī)密碼(多虧了 pwgen)。前面兩個(gè)用于 mysql 用戶,最后一個(gè)用于 wp-config.php 的隨機(jī)密鑰。 WORDPRESS_DB="wordpress" MYSQL_PASSWORD=`pwgen -c -n -1 12` WORDPRESS_PASSWORD=`pwgen -c -n -1 12` # 這是在日志中顯示的密碼。 echo mysql root password: $MYSQL_PASSWORD echo wordpress password: $WORDPRESS_PASSWORD echo $MYSQL_PASSWORD /mysql-root-pw.txt echo $WORDPRESS_PASSWORD /wordpress-db-pw.txt # 這里原來(lái)是一個(gè)包括 sed、cat、pipe 和 stuff 的很長(zhǎng)的行,但多虧了 # @djfiander 的 https://gist.github.com/djfiander/6141138 # 現(xiàn)在沒(méi)有了 sed -e "s/database_name_here/$WORDPRESS_DB/ s/username_here/$WORDPRESS_DB/ s/password_here/$WORDPRESS_PASSWORD/ /'AUTH_KEY'/s/put your unique phrase here/`pwgen -c -n -1 65`/ /'SECURE_AUTH_KEY'/s/put your unique phrase here/`pwgen -c -n -1 65`/ /'LOGGED_IN_KEY'/s/put your unique phrase here/`pwgen -c -n -1 65`/ /'NONCE_KEY'/s/put your unique phrase here/`pwgen -c -n -1 65`/ /'AUTH_SALT'/s/put your unique phrase here/`pwgen -c -n -1 65`/ /'SECURE_AUTH_SALT'/s/put your unique phrase here/`pwgen -c -n -1 65`/ /'LOGGED_IN_SALT'/s/put your unique phrase here/`pwgen -c -n -1 65`/ /'NONCE_SALT'/s/put your unique phrase here/`pwgen -c -n -1 65`/" /usr/share/nginx/html/wp-config-sample.php /usr/share/nginx/html/wp-config.php __httpd_perms() { chown apache:apache /usr/share/nginx/html/wp-config.php __start_mysql() { # systemctl 啟動(dòng) mysqld 服務(wù) mysqladmin -u root password $MYSQL_PASSWORD mysql -uroot -p$MYSQL_PASSWORD -e "CREATE DATABASE wordpress; GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY '$WORDPRESS_PASSWORD'; FLUSH PRIVILEGES;" killall mysqld sleep 10 __run_supervisor() { supervisord -n # 調(diào)用所有函數(shù) __check __create_user __mysql_config __handle_passwords __httpd_perms __start_mysql __run_supervisor 增加完上面的配置之后,保存并關(guān)閉文件。
4. 創(chuàng)建配置文件現(xiàn)在,我們需要?jiǎng)?chuàng)建 Nginx Web 服務(wù)器的配置文件,命名為 nginx-site.conf。 # nano nginx-site.conf然后,增加下面的配置信息到配置文件。user nginx; worker_processes 1; error_log /var/log/nginx/error.log; #error_log /var/log/nginx/error.log notice; #error_log /var/log/nginx/error.log info; pid /run/nginx.pid; events { worker_connections 1024; http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; index index.html index.htm index.php; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; root /usr/share/nginx/html; #error_page 404 /404.html; # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root html; # proxy the PHP scripts to Apache listening on 127.0.0.1:80 #location ~ /.php$ { # proxy_pass http://127.0.0.1; # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ /.php$ { root /usr/share/nginx/html; try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; # deny access to .htaccess files, if Apache's document root # concurs with nginx's one #location ~ //.ht { # deny all; 現(xiàn)在,創(chuàng)建 supervisor.conf 文件并添加下面的行。 # nano supervisord.conf然后,添加以下行。 [unix_http_server] file=/tmp/supervisor.sock ; (the path to the socket file) [supervisord] logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log) logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB) logfile_backups=10 ; (num of main logfile rotation backups;default 10) loglevel=info ; (log level;default info; others: debug,warn,trace) pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid) nodaemon=false ; (start in foreground if true;default false) minfds=1024 ; (min. avail startup file descriptors;default 1024) minprocs=200 ; (min. avail process descriptors;default 200) ; the below section must remain in the config file for RPC ; (supervisorctl/web interface) to work, additional interfaces may be ; added by defining them in separate rpcinterface: sections [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket [program:php-fpm] command=/usr/sbin/php-fpm -c /etc/php/fpm stdout_events_enabled=true stderr_events_enabled=true [program:php-fpm-log] command=tail -f /var/log/php-fpm/php-fpm.log stdout_events_enabled=true stderr_events_enabled=true [program:mysql] command=/usr/bin/mysql --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306 stdout_events_enabled=true stderr_events_enabled=true [program:nginx] command=/usr/sbin/nginx stdout_events_enabled=true stderr_events_enabled=true [eventlistener:stdout] command = supervisor_stdout buffer_size = 100 events = PROCESS_LOG result_handler = supervisor_stdout:event_handler 添加完后,保存并關(guān)閉文件。
5. 構(gòu)建 WordPress 容器現(xiàn)在,完成了創(chuàng)建配置文件和腳本之后,我們終于要使用 Dockerfile 來(lái)創(chuàng)建安裝最新的 WordPress CMS(譯者注:Content Management System,內(nèi)容管理系統(tǒng))所需要的容器,并根據(jù)配置文件進(jìn)行配置。做到這點(diǎn),我們需要在對(duì)應(yīng)的目錄中運(yùn)行以下命令。 # docker build --rm -t wordpress:centos7 . 6. 運(yùn)行 WordPress 容器現(xiàn)在,執(zhí)行以下命令運(yùn)行新構(gòu)建的容器,并為 Nginx Web 服務(wù)器和 SSH 訪問(wèn)打開(kāi)88 和 22號(hào)相應(yīng)端口 。 # CID=$(docker run -d -p 80:80 wordpress:centos7) 運(yùn)行以下命令檢查進(jìn)程以及容器內(nèi)部執(zhí)行的命令。 # echo "$(docker logs $CID )"運(yùn)行以下命令檢查端口映射是否正確。 # docker ps
7. Web 界面最后如果一切正常的話,當(dāng)我們用瀏覽器打開(kāi) http://ip-address/ 或者 http://mywebsite.com/ 的時(shí)候會(huì)看到 WordPress 的歡迎界面。
現(xiàn)在,我們將通過(guò) Web 界面為 WordPress 面板設(shè)置 WordPress 的配置、用戶名和密碼。
然后,用上面用戶名和密碼輸入到 WordPress 登錄界面。
總結(jié)我們已經(jīng)成功地在以 CentOS 7 作為 docker OS 的 LEMP 棧上構(gòu)建并運(yùn)行了 WordPress CMS。從安全層面來(lái)說(shuō),在容器中運(yùn)行 WordPress 對(duì)于宿主系統(tǒng)更加安全可靠。這篇文章介紹了在 Docker 容器中運(yùn)行的 Nginx Web 服務(wù)器上使用 WordPress 的完整配置。如果你有任何問(wèn)題、建議、反饋,請(qǐng)?jiān)谙旅娴脑u(píng)論框中寫(xiě)下來(lái),讓我們可以改進(jìn)和更新我們的內(nèi)容。非常感謝!Enjoy :-)
PHP教程

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 97超级碰碰人国产在线观看 | 国产手机国产手机在线 | 日本中文字幕电影在线观看 | 88xx成人精品视频 | a级高清免费毛片av在线 | 久久99综合久久爱伊人 | 午夜视频亚洲 | 在线中文字幕亚洲 | 亚洲aⅴ免费在线观看 | 欧美视频国产 | 国产亚洲精品久久久久久久久 | 撅高 自己扒开 调教 | 黄污网址 | 国产自在线| 欧美日韩国产成人在线观看 | 色综av | 福利在线免费视频 | 日本免费a∨ | 久久久久久久久久久久久久av | 黄色片免费看看 | 九九热视频这里只有精品 | 高清av免费 | 久久国产乱子伦精品 | 丰满年轻岳中文字幕一区二区 | 成人午夜精品久久久久久久3d | 国产日韩中文字幕 | 国产成年人小视频 | 色婷婷久久久久久 | 午夜亚洲影院 | 亚洲精品一区二区三区大胸 | 蜜桃一本色道久久综合亚洲精品冫 | 成人福利视频在线观看 | 中文在线观看视频 | 久草在线精品观看 | 久草在线看片 | 久久丝袜脚交足黄网站免费 | 在线成人免费观看 | 国产免费一区二区三区网站免费 | 姑娘第5集高清在线观看 | 国产乱淫av | 日日草夜夜操 |