使用Dockerfile创建自己的单一LNMP镜像

突然想到回顾docker创建自己常用镜像,做个记录。
环境为windows11、docker desktop,复制以下内容保存成对应文件

1.Dockerfile.ubuntu

# 指定基础镜像
FROM ubuntu
# 镜像维护者作者
MAINTAINER Netpc.com.cn-ken

# 环境变量
ENV MYPATH /usr/local
# 工作路径,容器创建后,终端默认进入的工作目录,或者理解为落脚点
WORKDIR $MYPATH

# 构成镜像时,执行的命令
# 从Dockerfile到images的过程中会执行的命令

# 备份原镜像软件源
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak
# 更改镜像为阿里镜像源
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse" >> /etc/apt/sources.list

RUN apt-get update
RUN apt-get install -y vim
RUN apt-get install -y net-tools
RUN apt-get install -y iputils-ping
RUN apt-get install -y php7.4 php7.4-fpm php7.4-gd php7.4-mbstring php7.4-pdo php7.4-curl php7.4-mysql php7.4-mysqli php7.4-json php7.4-mbstring php7.4-xml
RUN apt-get install -y nginx
RUN apt-get install -y mysql-server mysql-client
RUN usermod -d /var/lib/mysql/ mysql

# 暴露端口
EXPOSE 80
EXPOSE 443
EXPOSE 3306

# 将宿主机的文件复制到镜像中
ADD mysql.sh /mysql.sh
RUN chmod 777 /mysql.sh && /mysql.sh
RUN rm -rf /mysql.sh

# 将脚本复制到容器中
ADD a.php /var/www/html/
ADD start.sh /usr/local/bin/
ADD default /etc/nginx/sites-available/default

# 设置脚本可执行权限
RUN chmod +x /usr/local/bin/start.sh

# 在容器启动时执行脚本
CMD ["/usr/local/bin/start.sh"]

2.mysql.sh #启动mysql,修改默认账号信息

#!/bin/sh
service mysql start
mysql -uroot -e "use mysql;update user set Host='%' where User='root';flush privileges;ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';flush privileges;"
echo 'bind-address = 0.0.0.0' >> /etc/mysql/mysql.conf.d/mysqld.cnf

3.default #为了替换原有的启动php

server {
	listen 80 default_server;
	listen [::]:80 default_server;

	root /var/www/html;

	# Add index.php to the list if you are using PHP
	index index.html index.htm index.nginx-debian.html;

	server_name _;

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ =404;
	}

	# pass PHP scripts to FastCGI server
	#
	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
	}

}

4.start.sh

#!/bin/sh
service php7.4-fpm start
service mysql start
nginx -g "daemon off;" #不这样可能容器运行后会自动关闭

5.生成镜像命令:docker build -f Dockerfile.ubuntu -t ‘ubuntu-netpc’ .

6.docker run 映射到对应/var/www/html目录,就能把php放进去运行,映射端口3306就能直接访问容器内的mysql了。

上图

创建自己的docker镜像lnmp 创建自己的docker镜像lnmp2 创建自己的docker镜像lnmp1

发表在 服务器 | 标签为 , | 留下评论

windows11在docker上部署LNMP环境

1.我已经在windows11安装好docker desktop了,还没的要先安装。
根据官方教程下载安装docker desktop执行文件.exe,可以参考文章

2.终端直接运行以下命令:

2.1创建mysql
docker run -d -p 3307:3306 –name mysql5.7.23 –privileged=true -v D:\docker\mysql-5.7.23\conf.d:/etc/mysql/conf.d -v D:\docker\mysql-5.7.23\logs:/var/log/mysql -v D:\docker\mysql-5.7.23\data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7.23

2.2创建php
docker run -p 9003:9000 –name php7.4 -v D:\docker\nginx-1.21.5\html:/usr/share/nginx/html –link mysql5.7.23:docker-mysql -d php:7.4-fpm

2.3创建nginx
docker run –name nginx1.21.5new -p 8080:80 -p 8081-8089:8081-8089-v D:\docker\nginx-1.21.5\html:/usr/share/nginx/html:ro -v D:\docker\nginx-1.21.5\conf:/etc/nginx:ro –link php7.4:localhost -d nginx

说明:

  • -p 8080:80: 端口映射,把 nginx 中的 80 映射到本地的 8080端口。
  • D:\docker\nginx-1.21.5\html: 是本地 html 文件的存储目录,/usr/share/nginx/html 是容器内 html 文件的存储目录。
  • D:\docker\nginx-1.21.5\conf: 是本地 nginx 配置文件的存储目录,/etc/nginx是容器内 nginx 配置文件的存储目录,这里我把整个nginx目录都映射下来,方便修改。
  • –link php7.4:localhost: 把 php7.4 的网络并入 nginx容器,nginx 可以直接通过localhost:9000 访问 php-fpm。
  • –link mysql5.7.23:docker-mysql 把mysql容器的荒落并入php容器,可以直接通过docker-mysql别名调用3306 端口访问mysql

3.nginx配置文件D:\docker\nginx-1.21.5\conf\conf.d\default.conf

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

	root   /usr/share/nginx/html;
	index  index.html index.htm index.php;

	location / {
        try_files $uri $uri/ /index.php$is_args$args;
		autoindex on;
    }
	
    location ~ \.php$ {
        add_header X-debug-message "A php file was used $document_root" always;
	fastcgi_index  index.php;
	fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
	fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
	fastcgi_param  PATH_INFO  $fastcgi_path_info;
	fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
	include        fastcgi_params;
	fastcgi_pass   localhost:9000;
    }
}

说明:

3.1localhost:9000 表示 php-fpm 服务的访问路径, 已经通过link参数绑定了容器网络互通。

3.2/usr/share/nginx/html是nginx和php经docker映射变成本地路径D:\docker\nginx-1.21.5\html,都放一起就可以直接通过设置root参数,使用$document_root来指定SCRIPT_FILENAME的php文件路径,不然一不小心就找不到php文件出现404

4.最后都跑起来,放个phpmyadmin记得修改config.inc.php参数为上面起的别名,在容器内直接能访问到。

$cfg[‘Servers’][$i][‘host’] = ‘docker-mysql’;
docker里应该不能用locaohost,不然提示会mysqli_real_connect(): (HY000/2002): No such file or directory,用本地系统会去找mysql.stock,php容器里又不和MySQL一起,所以。。。

5.调试容器内通讯缺少工具的时候就执行下面几个常用命令安装下

apt update
apt install net-tools // 查看ip
apt install telnet //验证端口
apt install iputils-ping //ping

发表在 服务器 | 标签为 | 留下评论

linux或windows上的修改原docker容器挂载盘文件映射端口等

在windows或linux下不重新创建新的容器,直接修改原docker容器挂载盘或文件,IP映射端口等信息。

过程都是一样,停止docker服务,修改配置文件,启动docker。

windows下修改docker配置
运行环境windwos11、wsl2、ubuntu、Docker Desktop
1、确保服务里停掉docker容器和docker服务进程

windows下停止docker服务2.在文件资源管理器里找到\\wsl.localhost\docker-desktop-data\data\docker\containers文件夹,对应着你实际容器的ID进入,找到config.v2.json和hostconfig.json,看名字就知道是josn格式了,内容很简单,先备份再修改,然后保存。
window下修改docker容器配置 3.重新启动Docker Desktop即可。

linux下修改docker配置

和windows一样,先停止docker服务,接着在/var/lib/docker/containers/路径下找到对应容器ID目录进入,修改config.v2.json和hostconfig.json,保存,重启docker服务。

发表在 服务器 | 标签为 | 留下评论

showdoc忘记管理员密码

进入目录修改sqlite3数据库文件showdoc.db.php为可以读写修改。

[root@netpc.com.cn ~]# cd /showdoc/Sqlite/
sqlite3 showdoc.db.php
SQLite version 3.3.6
Enter “.help” for instructions
sqlite> update user set password=”a89da13684490eb9ec9e613f91d24d00″ where username=”showdoc”

以上sql语句修改默认showdoc账号,密码初始化为:123456,重新登录后再修改。

发表在 服务器 | 标签为 , | 留下评论

@vue-cli 5.0.8创建VUE3或VUE2项目

1、首先查看版本并安装个,这里的环境如下

vue:@vue/cli 5.0.8
npm:8.1.0
node:v16.13.0

2.开始创建项目

2.1创建命令:vue create test 并选择创建项目类型

Vue CLI v5.0.8
? Please pick a preset:
vue3 ([Vue 3] dart-sass, babel, router, eslint) // 保存过自定义默认选项
Default ([Vue 3] babel, eslint)//默认(安装bable、eslint)
Default ([Vue 2] babel, eslint)//默认(安装bable、eslint)
> Manually select features //自定义

2.2选择自定义配置:

Vue CLI v5.0.8
? Please pick a preset: Manually select features
? Check the features needed for your project: (Press <space> to select, <a> to toggle all, <i> to invert selection, and
<enter> to proceed)
>(*) Babel //是一个 JavaScript 编译器ES6先后兼容ES5
( ) TypeScript // 微软开发的一个开源的编程语言,在JS的基础上构建而成超集
( ) Progressive Web App (PWA) Support //  渐进式Web应用
( ) Router // 路由
( ) Vuex // 状态管理库
( ) CSS Pre-processors // CSS预处理
(*) Linter / Formatter // 规范代码检查工具
( ) Unit Testing // 测试
( ) E2E Testing  // 测试

2.3选择组件相关参数

Vue CLI v5.0.8
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router, Vuex, CSS Pre-processors, Linter

2.3.1选择vue版本
? Choose a version of Vue.js that you want to start the project with (Use arrow keys)
> 3.x
2.x

2.3.2选择是否使用history历史模式的路由
? Use history mode for router? (Requires proper server setup for index fallback in production) (Y/n)

2.3.3选择CSS预处理器
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): (Use arrow keys)
> Sass/SCSS (with dart-sass)
Less
Stylus

2.3.4选择哪个自动化代码格式化检测
? Pick a linter / formatter config: (Use arrow keys)
ESLint with error prevention only
ESLint + Airbnb config
ESLint + Standard config
> ESLint + Prettier

2.3.5选择什么时候进行语法检查
? Pick additional lint features: (Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed)
>(*) Lint on save // 语法检查配置文件保存时检查
( ) Lint and fix on commit // 文件提交时检查

2.3.6配置文件的存放位置(推荐独立放置配置文件)
? Where do you prefer placing config for Babel, ESLint, etc.? (Use arrow keys)
> In dedicated config files // 独立配置文件
In package.json // 放package.json里

2.3.6 是否保存以上设置(选择yes的话下次就可以直接使用刚才的配置了)
? Save this as a preset for future projects? (y/N)

3.最后回车等待组件下载创建成功

Vue CLI v5.0.8
✨ Creating project in D:\www\test\test.
🗃 Initializing git repository…
⚙️ Installing CLI plugins. This might take a while…

added 861 packages in 3m
🚀 Invoking generators…
📦 Installing additional dependencies…

added 113 packages in 2m
⚓ Running completion hooks…

📄 Generating README.md…

🎉 Successfully created project test.
👉 Get started with the following commands:

$ cd test
$ npm run serve

 

 

发表在 服务器 | 留下评论

windows7安装nodejs14成功创建VUE3

在windows7上是必须用node14才能正常创建vue3,刚开始很多网上还写着@vue/cli3.X结果创建出来的实际是vue2.6,根据查看package.json文件查看能知道实际使用的vue版本

"dependencies": {
 "core-js": "^3.8.3",
 "vue": "^3.2.13",
 "vue-router": "^4.0.3",
 "vuex": "^4.0.0"
},

最后是成功的,但是最高只能到nodejs14.17.6,不然会有dll动态链接库接口错误提示:无法定位程序输入点 getHostNameW 于动态链接库 WS2_32.dll

1、先下载windows7最后一个正常安装node-v13.4.0版本,下面地址
https://registry.npmmirror.com/-/binary/node/v13.4.0/node-v13.4.0-x64.msi

2、上面安装好后,下载下载的解压覆盖
https://registry.npmmirror.com/-/binary/node/v14.17.6/node-v14.17.6-win-x64.zip

3、打开cmd输入set NODE_SKIP_PLATFORM_CHECK=1,忽略版本检测
接着node -v看版本

以上都是镜像下载地址,官网不知为啥打不开

接着安装npm install-g @vue/cli,查看vue -V
@vue/cli 5.0.8

查看npm -v
8.13.2

执行vue create test
就可以选择创建vue3或vue2了

发表在 服务器 | 标签为 | 留下评论

WinMerge对比文件夹忽略svn目录

如题,很简单,可以使用WinMerge自带的过滤器

如下图,点击文件夹过滤器的选择,弹出过滤器界面,点击新建,弹出让你选择私有还是共享用户,随便喜欢,然后找个地方起个svn名字保存,弹出svn.flt记事本,内容如下,name和desc修改为SVN,注释掉F(过滤文件),留下D过滤目录改成 \.svn$,保存后点击安装,加载刚才保存的svn.flt文件,下拉下列表在下面选择SVN,点确定,这样就能在你对比过程中过滤svn目录了

WinMerge对比文件夹忽略svn

自从公司不让用破解Beyond Compare后,就习惯上使用WinMerge了.

发表在 服务器 | 标签为 , | 留下评论

安装Kibana管理Elasticsearch单机版

环境centos7,目前项目需要用到分布式,Elasticsearch直接做单机版,需要配置副本分片为0,让它不要去同步即可,不然状态会变成yellow,正常是green。

Elasticsearch
安装环境:yum install java-1.8.0-openjdk* -y
下载:wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.8.4.tar.gz
解压:tar -zxvf ./elasticsearch-6.8.4.tar.gz
root下不能跑,添加用户:useradd elasticsearch
设置目录所属:chown -R elasticsearch.elasticsearch ./elasticsearch-6.8.4
切换用户:su elasticsearch
启动:./bin/elasticsearch -d
停止:./bin/elasticsearch stop

配置文件:config/elasticsearch.yml
network.host: 127.0.0.1
http.port: 9200

kibana官网
https://www.elastic.co/cn/downloads/past-releases/kibana-6-8-23
下载:wget https://artifacts.elastic.co/downloads/kibana/kibana-6.8.23-linux-x86_64.tar.gz
解压:tar -zxvf kibana-6.8.23-linux-x86_64.tar.gz

root下不能跑,添加用户:useradd kibana
设置目录所属: chown -R kibana.kibana ./kibana-6.8.23-linux-x86_64
切换用户:su kibana
启动:./bin/kibana

配置文件:config/kibana.yml
server.port: 9800
server.host: “172.27.126.154”
elasticsearch.hosts: [“http://127.0.0.1:9200”]
kibana.index: “.kibana”
i18n.locale: “zh-CN”

Kibana报错:版本对应不上
FATAL ProductNotSupportedError: The client noticed that the server is not Elasticsearch and we do not support this unknown product.
Unable to retrieve version information from Elasticsearch nodes

修改elasticsearch配置

PUT /index/_settings
{
“number_of_replicas”: 0
}

{
“acknowledged” : true
}

查看elasticsearch状态,正常status为green
GET _cluster/health

发表在 服务器 | 标签为 , | 留下评论

python提示ImportError: No module named mysql.connector

今天在centos7下Python版本2.7.5执行脚本提示缺少mysql模块

很简单执行yum install mysql-connector-python安装下模块即可

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
–> Running transaction check
—> Package mysql-connector-python.noarch 0:1.1.6-1.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================
Package Arch Version Repository Size
====================================================================================================================
Installing:
mysql-connector-python noarch 1.1.6-1.el7 epel 154 k

Transaction Summary
====================================================================================================================
Install 1 Package

Total download size: 154 k
Installed size: 636 k
Is this ok [y/d/N]: y
Downloading packages:
mysql-connector-python-1.1.6-1.el7.noarch.rpm | 154 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql-connector-python-1.1.6-1.el7.noarch 1/1
Verifying : mysql-connector-python-1.1.6-1.el7.noarch 1/1

Installed:
mysql-connector-python.noarch 0:1.1.6-1.el7

Complete!

发表在 服务器 | 标签为 | 留下评论

恢复Microsoft Store微软应用商店卸载找不到了

可能是ghost系统的关系,压根就没见过有这东西

1、按下Win+X快捷键,选择“Windows PowerShell(管理员)”。

2、输入以下内容,可以一行一行复制粘贴,再按回车执行。
get-appxpackage *store* | remove-Appxpackage
add-appxpackage -register "C:\Program Files\WindowsApps\*Store*\AppxManifest.xml" -disabledevelopmentmode

Windows Terminal3、再搜索关键字store,打开即可,可能需要刷新或重新第二次打开才能正常显示。
microsoft store微软应用商店

发表在 服务器 | 标签为 | 留下评论