1, 配置nfs存储卷
1,在docker swarm集群中所有节点都确认安装nfs客户端软件
# yum install nfs-utils rpcbind -y
2, 在192.168.122.1 上搭建nfs,共享目录给docker swarm集群中所有节点挂载
[root@nfs ~]# mkdir /opt/dockervolume
[root@nfs ~]# vim /etc/exports
/opt/dockervolume *(rw,no_root_squash,sync)
[root@nfs ~]# systemctl restart rpcbind nfs-server [root@nfs ~]# systemctl enble rpcbind nfs-server
3, 在docker swarm集群中所有节点创建存储卷,并验证
# docker volume inspect nginx_volume [
{
"CreatedAt": "2019-06-12T13:24:09+08:00",
"Driver": "local",
"Labels": {}, "Mountpoint":
"/var/lib/docker/volumes/nginx_volume/_data", "Name": "nginx_volume",
"Options": {
"device": ":/opt/dockervolume", "o": "addr=192.168.122.1,rw",
注意这里的挂载参数要有
"type": "nfs"
},
"Scope": "local"
}
# docker volume ls |grep nginx_volume
local nginx_volume
# docker volume create --driver local --opt type=nfs --opt o=addr=192.168.122.1,rw --opt device=:/opt/dockervolume
nginx_volume
在任意能上外网的机器上操作
[root@nfs ~]# docker pull richarvey/nginx-php-fpm
[root@nfs ~]# mkdir /root/discuz/dockerfile -p
[root@nfs ~]# cd /root/discuz/dockerfile
准备nginx主配置文件
[root@nfs dockerfile]# vim nginx.conf user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
use epoll; worker_connections 65535;
}
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
sendfile #tcp_nopush
/var/log/nginx/access.log on;
on;
main;
keepalive_timeout 65; #gzip on;
include /etc/nginx/conf.d/*.conf;
}
准备nginx子配置文件
[root@nfs dockerfile]# vim web.conf server {
listen 80; server_name _;
index index.php index.html; root /var/www/html;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name; include fastcgi_params;
}
}
准备时区文件
[root@nfs dockerfile]# cp /etc/localtime .
准备php-fpm子配置文件
[root@nfs dockerfile]# vim php-fpm-www.conf [www]
user = nginx group = nginx
listen = 127.0.0.1:9000
pm = dynamic pm.max_children = 64
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
编写Dockerfile
[root@nfs dockerfile]# vim dockerfile FROM richarvey/nginx-php-fpm
MAINTAINER daniel@itcast.cn
RUN echo 'Asia/Shanghai' > /etc/timezone && rm -f
/etc/nginx/nginx.conf && rm -f /usr/local/etc/php- fpm.d/www.conf
COPY localtime /etc/localtime
COPY nginx.conf /etc/nginx/nginx.conf COPY web.conf /etc/nginx/conf.d/web.conf
COPY php-fpm-www.conf /usr/local/etc/php-fpm.d/www.conf
CMD /usr/sbin/nginx -c /etc/nginx/nginx.conf &&
/usr/local/sbin/php-fpm -c /usr/local/etc/php-fpm.conf
构建镜像
[root@nfs dockerfile]# docker build -f dockerfile -t 192.168.122.18/library/nginx-php-fpm:v1 .
上传镜像到harbor
[root@nfs dockerfile]# docker login 192.168.122.18
[root@nfs dockerfile]# docker push 192.168.122.18/library/nginx-php-fpm:v1
编写YMAL文件
在docker swarm集群中的管理节点进行操作
[root@manager ~]# cat discuz.yml version: '3'
services: db:
image: 192.168.122.18/library/mysql:5.7 environment:
MYSQL_ROOT_PASSWORD: 123
MYSQL_DATABASE: discuz MYSQL_USER: discuz_user MYSQL_PASSWORD: 123
deploy:
replicas: 1
nginx-php:
image: 192.168.122.18/library/nginx-php-fpm:v1 depends_on:
- db ports:
- "8011:80"
volumes:
- "nginx_volume:/var/www/html" deploy:
replicas: 1
volumes:
nginx_volume: driver: local driver_opts:
type: "nfs"
o: "addr=192.168.122.1,rw"
device: ":/opt/dockervolume"
一键发布stack
[root@manager ~]# docker stack deploy -c discuz2.yml discuz
Creating network discuz_default
Creating service discuz_db
Creating service discuz_nginx-php
在nfs服务器上操作
[root@nfs dockerfile]# git clone https://gitee.com/ComsenzDiscuz/DiscuzX.git
[root@nfs dockerfile]# cp DiscuzX/upload/* /opt/dockervolume/
-rf
cp: overwrite ‘/opt/dockervolume/index.php’? y
[root@nfs dockerfile]# chmod o+w -R /opt/dockervolume/
上图少了-R参数,请加上
、了解Linux软件的安装方式
2、掌握更新yum源
3、掌握YUM软件安装方式
4、了解LAMP环境以及AMP的关系
5、了解阿里云ECS的创建过程
6、能够yum方式搭建lamp环境
7、能够实现Discuz!论坛部署
8、能够购买域名与解析域名
学员小白,目前刚入职了一家电子商务公司。主要负责大型商城系统维护,公司主营母婴用品,如奶瓶、奶嘴、童装等等,最近,很多客服发现一个问题:很多宝妈会在评论区互相咨询产品相关信息。
于是公司决定针对这一需求,要求运维为公司迅速上线一款论坛系统,方便宝妈交流产品、育儿心得等等。
满足功能,并且省钱
Discuz! = Apache + PHP + MySQL
在CentOS系统中,软件管理方式通常有三种方式:rpm安装、yum安装以及编译安装。
编译安装,从过程上来讲比较麻烦,包需要用户自行下载,下载的是源码包,需要进行编译操作,编译好了才能进行安装,这个过程对于刚接触Linux的人来说比较麻烦,而且还容易出错。好处在于是源码包,对于有需要自定义模块的用户来说非常方便。(就业班会着重讲解)
Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。
基于rpm包管理,能够从指定的服务器(yum源)自动下载RPM包并且安装,可以==自动处理依赖性关系==,并且==一次安装所有依赖的软件包==,无须繁琐地一次次下载、安装。
yum配置文件位置
#cd /etc/yum.repos.d/
#ll
-rw-r--r--. 1 root root 1991 Mar 28 2017 CentOS-Base.repo 网络yum源配置文件 -rw-r--r--. 1 root root 647 Mar 28 2017 CentOS-Debuginfo.repo 内核相关的更新包 -rw-r--r--. 1 root root 289 Mar 28 2017 CentOS-fasttrack.repo 快速通道 -rw-r--r--. 1 root root 630 Mar 28 2017 CentOS-Media.repo 本地yum源配置文件 -rw-r--r--. 1 root root 7989 Mar 28 2017 CentOS-Vault.repo 最近版本加入老本的YUM配置
使用阿里yum源代替系统默认的yum源
① 备份默认源
#cd /etc/yum.repos.d/
#mv CentOS-Base.repo CentOS-Base.repo.bak
② 下载新CentOS-Base.repo
#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
含义:使用阿里云的yum源代替默认的yum源,下载软件更快
③ 清除所有缓存
#yum clean all
④ 重新生成缓存
#yum makecache
http://mirrors.aliyun.com/repo/选择不同centos版本的yum源
语法:# yum search 关键词
语法:# yum [-y] install 关键词
语法:# yum [-y] remove 关键词
语法:#yum [-y] update [包的关键词]
特别注意:包的关键词如果不写,则表示更新整个系统(全局更新,也包含内核)
LAMP:==L==inux + ==A==pache + ==M==ySQL + ==P==HP LAMP 架构(组合)
LNMP:Linux + Nginx + MySQL + php-fpm LNMP 架构(组合)
LNMPA:Linux + Nginx(80) + MySQL + PHP + Apache Nginx 代理方式
Apache:Apache是世界使用排名第一的Web服务器软件。
PHP:一种专门用于Web开发的编程语言。
MySQL:MySQL是一个关系型数据库管理系统,主要用于永久存储项目数据。
要想部署一个互联网上可以访问到的环境,必须先具备以下内容 :
服务器(IP、帐号密码、终端)、相应的软件、域名(备案、解析)、代码等。
阿里云官网:https://www.aliyun.com/
步骤1:鼠标移动到屏幕右上角的头像,在弹出菜单中选择实名认证
步骤2:在认证页面,需选择个人实名认证
步骤3:选择支付宝授权认证
步骤4:勾选同意,点击提交
步骤5:支付宝扫描二维码,手机上选择确认登录
步骤6:填写相关信息,点击确认
#systemctl stop firewalld
#setenforce 0
临时关闭
#getenforce
查看当前是否关闭了selinux
#vim /etc/selinux/config
编辑selinux配置文件,永久关闭
使用rpm命令
使用rpm命令
使用rpm命令
建议使用一台新装的Linux,因为卸载如果有残留,也容易给后续搭建带来未知的问题。
① 使用yum命令安装httpd软件包
② 配置/etc/httpd/conf/httpd.conf文件
搜索ServerName,在下面添加一行:
ServerName Localhost:80
#vim /etc/httpd/conf/httpd.conf
ServerName localhost:80
问题:保存退出用什么命令?
答:
③ 使用systemctl命令重启httpd服务,使用netstat -ntlp命令,查看是否有80端口监听
④ 设置httpd服务开机启动
⑤ 查看本机的IP地址,阿里云服务器从控制台可以看到
⑥在浏览器中,输入本机IP地址,如下图所示:
注意:自己的服务器在设置时,一定要管理防火墙与SELinux,避免产生异常
① 关闭防火墙 命令:# service iptables stop
② 关系SELinux 命令:# setenforce 0
由于yum源上默认没有mysql-server。所以必须去官网下载后在安装
#wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
含义:下载myslq的yum源
#rpm -ivh mysql-community-release-el7-5.noarch.rpm
含义:安装mysql的yum源存储库包
#yum -y install mysql-community-server
#systemctl restart mysqld.service
#netstat -ntlp
默认情况下,数据库没有密码,也没有任何数据,必须要初始化
#mysql_secure_installation
含义:mysql自己带的初始化程序
设置超级管理员root密码,注:默认为空,直接回车即可
移除匿名账户:
不禁用root远程连接:
不移除默认数据库(测试用例):
重新加载权限:Y
提示已完成,感谢使用MySQL
默认已经开机启动,这里可以跳过
#mysql -uroot -p
含义:-u是参数,后面跟用户名,没有空格
-p表示密码
看到mysql>表示已经连接到mysql
myslq> show databases;
含义:显示所有数据库
注意:命令结尾要有“;”
mysql>下输入exit,退出mysql,回到#提示符
① 使用yum命令安装php、
#yum -y install php
#systemctl restart httpd
② 重启httpd服务
更改php配置一定要重启httpd服务
③ 测试LAMP环境是否可以使用
第一步:使用cd命令进入/var/www/html目录
第二步:使用vim命令创建index.php文件
第三步:编写php代码
代码示例:
#cd /var/www/html/
#vim index.php
<?php
echo 'hello world';
?>
第四步:在浏览器,输入公网IP,如下图所示:
Discuz!是一套开源的社区论坛软件系统。
下载地址:https://gitee.com/ComsenzDiscuz/DiscuzX
1)把ComsenzDiscuz-DiscuzX-master.zip文件通过MobaXterm上传到ECS服务器的/usr/local目录
2)安装unzip命令并且解压缩论坛代码
#yum -y install unzip
#unzip ComsenzDiscuz-DiscuzX-master.zip
含义:解压缩ComsenzDiscuz-DiscuzX-master.zip文件
#ll
解压缩后,得到DiscuzX目录,其中upload文件夹下是真正的网站代码文件
3)将网站代码拷贝到/var/www/html下
示例代码:
#cp -r /usr/local/DiscuzX/upload/* /var/www/html/
#cd /var/www/html/
#ll
首先查看Discuz!源代码文件是否已经上传完成,必须完成后,才可以进行Discuz!论坛安装。
看到下面的页面表示访问成功,点击我同意
如上图所示,系统提示很多文件没有可写权限,设置如下:
#chmod -R a+w /var/www/html/
重新刷新,如下图所示:
如上图所示:以上结果代表系统缺少php-mysqli扩展,安装后即可解决。
① 使用yum命令安装php-mysqli扩展
#yum -y install php-mysqli
② 重启httpd服务
重新刷新网页,如下图所示:
开始安装页面已经没有任何报错,点击下一步,进入设置运行环境页面
进入论坛首页,如下图所示:
到此,关于LAMP环境配置与开源Discuz!项目实战就全部搞定了!
我们现在访问论坛是通过IP地址实现的,但是IP地址比较复杂,更重要的是不方便用户记忆。
1)登录阿里云控制台
https://account.aliyun.com/
2)登录后选择阿里云首页右上角的控制台,鼠标移动到左上角会出现如下菜单,选择域名
3)点击域名注册:
输入一个想注册的域名名称,例如ityunweiketangyanshi
如下图所示:
加入清单,立即结算:
配置域名持有者,学习环境直接选择个人即可:
现在国家要求实名制,所以还要创建信息模板,点击创建信息模板
点击页面右上角,创建新信息模板
添加完个人信息后,回到订单页面刷新,重新选择个人,会看到自己添加的信息模板,还要认证邮箱,就是往你注册的邮箱里发一封邮件,需要登录邮箱,点击验证链接,最终完成信息登记
看到如下页面:
勾选:我已阅读,理解并接受,然后单击立即购买,支付,如下图所示:
① 点击控制台,右侧菜单选择域名,进入域名管理页面
点击解析按钮
② 添加A记录
将http://www.ketangyanshi.com 指向公网IP
点击确定,完成设置。几分钟后就可以通过域名访问刚刚搭建的网站了。
注意:由于国家要求,域名解析需要首先实名制认证,所以目前我这个域名无法实际使用,我还没有完成实名制认证
近用 Discuz 搭建了个网站——(www.91kaiye.cn),用到了门户功能,不得不说Discuz 的功能还是非常强大的,但在使用过程中发现在发表文章时添加了图片却不能像 WordPress 这样自动添加 alt 标签,经过一番研究,初步解决了这个问题,目前还没有 Bug,等待长时间验证,方法如下:
在实施本方法之前请先备份网站数据,以防不测;这次修改需要修改两个文件,分别是:
static/image/editor/editor_function.js
template/default/home/spacecp_blog.htm
同时增加一个文件为:
static/image/editor/editor_function.js–复制一份,重命名为:bgeditor_function.js
下面开始修改:editor_function.js
查找代码:
function insertImage(image, url, width, height) {
url = typeof url == 'undefined' || url === null ? image : url;
width = typeof width == 'undefined' || width === null ? 0 : parseInt(width);
height = typeof height == 'undefined' || height === null ? 0 : parseInt(height);
var html = '<p><a href="' + url + '" target="_blank"><img src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
edit_insert(html);
}
修改为:
function insertImage(image, url, width, height, subject) {
url = typeof url == 'undefined' || url === null ? image : url;
width = typeof width == 'undefined' || width === null ? 0 : parseInt(width);
height = typeof height == 'undefined' || height === null ? 0 : parseInt(height);
subject = $('title').value;
var html = '<p><a href="' + url + '" target="_blank"><img alt="'+subject+'" src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
edit_insert(html);
}
再修改刚刚建立的bgeditor_function.js
同样查找代码:
function insertImage(image, url, width, height) {
url = typeof url == 'undefined' || url === null ? image : url;
width = typeof width == 'undefined' || width === null ? 0 : parseInt(width);
height = typeof height == 'undefined' || height === null ? 0 : parseInt(height);
var html = '<p><a href="' + url + '" target="_blank"><img src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
edit_insert(html);
}
修改为:
function insertImage(image, url, width, height, subject) {
url = typeof url == 'undefined' || url === null ? image : url;
width = typeof width == 'undefined' || width === null ? 0 : parseInt(width);
height = typeof height == 'undefined' || height === null ? 0 : parseInt(height);
var html = '<p><a href="' + url + '" target="_blank"><img alt="'+subject+'" src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
edit_insert(html);
}
再编辑:template/default/home/spacecp_blog.htm
查找:editor_function.js
替换为:bgeditor_function.js
编辑完毕保存,把文件上传到原来位置,增加的bgeditor_function.js与editor_function.js一块放在同一目录。后台发布一片文章,输入文章标题,上传图片,进入源代码模式,看看图片是不是有了 alt 标签?
效果如图:
*请认真填写需求信息,我们会在24小时内与您取得联系。