Linux实验4(FastDFS、nginx、docker)

Linux实验4

  • FastDFS集群
      • 复制一个虚拟机
    • 1.修改一下路径
    • 2.没有/etc/fdfs/mod_fastdfs.conf文件
    • 3.fdfs_storaged /etc/fdfs/storage.conf start启动失败
    • 4.没有/root/fdfs/logs/trackerd.log文件
    • 5.fdfs_test
    • 6.安装nginx
    • 7.在浏览器上访问,长时间没有响应
  • docker搭建LNMP-PHP
    • 1.docker启动失败
    • 2.之前配置的nginx浏览器访问不了,但是却可以curl

  1. 参考以下博客安装FastDFS集群.至少两台机器构成集群.并测试上传和访问成功.
    https://segmentfault.com/a/1190000018251300?utm_source=tag-newest
    后记:这个博文有点糟糕,推荐这个博文
  2. 参考以下博客利用docker搭建LNMP-PHP运行环境
    https://blog.csdn.net/UserPHP/article/details/100728267

所用环境:
VMWare12.5.7
CentOS-7-x86_64-Minimal-1908

FastDFS集群

复制一个虚拟机

  1. Linux先关机
  2. 在VMWare上,文件->导出为OVA,再导入,即可

1.修改一下路径

~/miao/fdfs-package
/root/miao/fdfs

2.没有/etc/fdfs/mod_fastdfs.conf文件

//在这里,复制一份
/root/miao/fdfs-package/fastdfs-nginx-module-1.20/src

3.fdfs_storaged /etc/fdfs/storage.conf start启动失败

process fdfs_trackerd already running, pid: 3159

4.没有/root/fdfs/logs/trackerd.log文件

tail -n10 ~/miao/fdfs/logs/trackerd.log

5.fdfs_test

新建~/miao/test_images/,rz一个图片
fdfs_test /etc/fdfs/client.conf upload ~/miao/test_images/卡布奇诺.jpg

6.安装nginx

下载安装包,./configure安装

//custom_configure
//去掉第2,3行
//最后一行修改
--add-module=/root/miao/fdfs-package/fastdfs-nginx-module-1.20/src/
//环境依赖
yum -y install gcc
yum -y install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
//若出现编译错误,还需要
yum -y install libxml2 libxml2-dev
yum -y install libxslt-devel
yum -y install gd-devel
yum -y install GeoIP GeoIP-devel GeoIP-data
//编译的时候出现错误
# 修改fastdfs-nginx-module的src/config文件
$ cd /root/miao/fdfs-package/fastdfs-nginx-module-1.20/src
$ vim config
# 修改一下两项:
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
//如下安装成功
#可以记录一下
Configuration summary
  + using threads
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1: using OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/share/nginx"
  nginx binary file: "/usr/share/nginx/sbin/nginx"
  nginx modules path: "/usr/share/nginx/modules"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/run/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "/var/lib/nginx/body"
  nginx http proxy temporary files: "/var/lib/nginx/proxy"
  nginx http fastcgi temporary files: "/var/lib/nginx/fastcgi"
  nginx http uwsgi temporary files: "/var/lib/nginx/uwsgi"
  nginx http scgi temporary files: "/var/lib/nginx/scgi"

配置nginx

文件/etc/nginx/nginx.conf
location / {
	 #root   html;
	 #index  index.html index.htm;
	root /root/miao/fdfs/data;
	ngx_fastdfs_module;
}

开启nginx

//新建目录
mkdir /var/lib/nginx/body
nginx

关闭防火墙(添加信任)

//打开文件
vim /etc/sysconfig/iptables
//添加
-A INPUT -p tcp -m state --state NEW -m tcp --dport 9270 -j ACCEPT

可以利用curl -i 192.168.17.220:9270测试(建议端口号同一改成9270)

7.在浏览器上访问,长时间没有响应

推荐查看一下nginx的日志文件,根据error.log日志debug

tail -f /var/log/nginx/access.log
tail -f /var/log/nginx/error.log
//查看进程
netstat -tupln
//kill掉ngnix
//重新启动nginx
nginx

日志报错

[2015-11-10 21:04:04] ERROR - file: …/common/fdfs_global.c, line: 52,the format of filename “group1/M00/00/00/xxxxxxxxxxx” is invalid

//解决办法
vim /etc/fdfs/mod_fastdfs.conf
url_have_group_name = true

ERROR - file: /root/miao/fdfs-package/fastdfs-nginx-module-1.20/src//common.c, line:1100, stat file:/root/miao/fdfs/storage/data/00/00/wKgR3F6dvzGAAAi2AADDeM3aQtc887_big.jpg fail, errno: 13, error info: Permission denied

vim /etc/nginx/nginx.conf
#在第一行加上
user root;

如果在浏览器上访问,可以看见图片就完成了

docker搭建LNMP-PHP

1.docker启动失败

Process: 16369 ExecStart=/usr/bin/dockerd -H fd://
–containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE) Main PID: 16369 (code=exited, status=1/FAILURE)

4月 21 01:26:58 localhost.localdomain systemd[1]: docker.service: main
process exited, code=exited, stat…URE 4月 21 01:26:58
localhost.localdomain systemd[1]: Failed to start Docker Application
Container Engine. 4月 21 01:26:58 localhost.localdomain systemd[1]:
Unit docker.service entered failed state. 4月 21 01:26:58
localhost.localdomain systemd[1]: docker.service failed. 4月 21
01:27:00 localhost.localdomain systemd[1]: docker.service holdoff time
over, scheduling restart. 4月 21 01:27:00 localhost.localdomain
systemd[1]: Stopped Docker Application Container Engine. 4月 21
01:27:00 localhost.localdomain systemd[1]: start request repeated too
quickly for docker.service 4月 21 01:27:00 localhost.localdomain
systemd[1]: Failed to start Docker Application Container Engine. 4月 21
01:27:00 localhost.localdomain systemd[1]: Unit docker.service entered
failed state. 4月 21 01:27:00 localhost.localdomain systemd[1]:
docker.service failed.

可能原因和解决办法

  1. /etc/docker/daemon.json文件错误
  2. 升级内核
yum update -y kernel
reboot

之后按照步骤来,就完成了

2.之前配置的nginx浏览器访问不了,但是却可以curl

#关闭firewalld
service firewalld stop
#永久关闭
systemctl disable firewalld

常用命令
docker ps -a # 查看容器
docker ps #查看正在运行的容器
docker stop mynginx # 停止正在运行的容器
docker start mynginx # 启动一个已经停止的容器
docker restart mynginx # 重启一个容器
docker rm mynginx # 删除容器
docker logs 容器名
docker run xxxxxxx

docker run命令 宿主机内容:容器内容
-network 指定网络
-name 指定容器名字
-p端口映射
-v文件/目录映射

你可能感兴趣的:(linux实验)