Docker not running on windows 10 error: Hardware assisted virtualization and data execution protecti

Docker not running on windows 10 error: Hardware assisted virtualization and data execution protection must be enabled in the BIOS

Docker 启动异常的解决办法

启动BIOS的虚拟化设置 | 开启CPU虚拟化支持
https://jingyan.baidu.com/article/335530daa55d7e19cb41c3c2.html

具体机型自行百度

Windows 10安装Docker 报“Hardware assisted virtualization and data execution protection must be enabled”

https://my.oschina.net/u/2289161/blog/1647017

记录来自 stackOverFlow 的方法

SOLUTION A (If Hyper-V is totally disabled or not installed)

1、Open PowerShell as administrator and

2、Enable Hyper-V with

dism.exe /Online /Enable-Feature:Microsoft-Hyper-V /All

SOLUTION B (If Hyper-V feature is already enabled but doesn’t work)

Enable Hypervisor with

bcdedit /set hypervisorlaunchtype auto

Now restart the system and try again.

Docker 方式安装Gogs

Gogs 是 一个能够简单自建Git托管服务的开源项目,用 go 语言实现。
Gogs 官方地址

概况

  • 掌握了如何运用Docker安装启动 Gogs
  • 掌握了如何运用Docker安装启动 Mysql
  • 掌握了如何使用Docker compose 命令整合 Gogs & Mysql 两个容器

MySQL 镜像的下载、启动容器

  1. 从默认的仓库拉取mysql镜像:docker pull mysql
  2. 查看本地有哪些镜像:docker images
  3. 运行mysql镜像生成名字叫做mysql2的容器,映射主机端口是13306,root密码是123456 : docker run
  4. 查看本地创建了哪些容器 docker ps
  5. 交互方式进入mysql2容器的shell环境,创建一个数据库testdb docker exec
[root@localhost ~]# docker pull mysql
[root@localhost ~]# docker images
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
mysql                                   latest              eda6a4884645        2 days ago          383.4 MB
hello-world                             latest              c54a2cc56cbb        3 months ago        1.848 kB
index.tenxcloud.com/huangqg/wordpress   latest              88bc02275ad7        12 months ago       485.5 MB
[root@localhost ~]# docker run -d -p 13306:3306  --name mysql2 -v /opt/mydata/:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:latest
01ff7db79a2bba578f4cef7024cd1e02bfec1084478e7835a79aeed317278b03
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES
01ff7db79a2b        mysql:latest        "docker-entrypoint.sh"   29 seconds ago      Up 27 seconds       0.0.0.0:13306->3306/tcp   mysql2
[root@localhost ~]# docker exec -it mysql2 /bin/bash
root@01ff7db79a2b:/# mysql --version
mysql  Ver 14.14 Distrib 5.7.16, for Linux (x86_64) using  EditLine wrapper
root@01ff7db79a2b:/# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.16 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database testdb;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| testdb             |
+--------------------+
5 rows in set (0.00 sec)


主机(Win10中文版)访问虚拟机MySQL的 Docker 容器 mysql2
看到了 testdb 的存在

D:\>mysql -h 192.168.1.161 -P 13306 -uroot -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database testdb;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| testdb             |
+--------------------+
5 rows in set (0.00 sec)

Gogs 镜像的下载、启动容器

[Gogs 镜像地址] (https://hub.docker.com/r/gogs/gogs/)

[root@localhost ~]# docker pull gogs/gogs
Using default tag: latest
latest: Pulling from gogs/gogs
6c123565ed5e: Pull complete
b42f29d13b9c: Pull complete
01150f5f4ffe: Pull complete
be1365fee626: Pull complete
6ccc52766b77: Pull complete
cb0e4cd5b47d: Pull complete
Digest: sha256:f206e8bcc77c8577fe1c4a94e59fe3a3a0ddb8e0f8f4fa6cf4a88d241c645d20
Status: Downloaded newer image for gogs/gogs:latest
[root@localhost ~]# docker images
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
mysql                                   latest              eda6a4884645        4 days ago          383.4 MB
gogs/gogs                               latest              d28f8296a1e9        4 weeks ago         89.22 MB
hello-world                             latest              c54a2cc56cbb        3 months ago        1.848 kB
index.tenxcloud.com/huangqg/wordpress   latest              88bc02275ad7        12 months ago       485.5 MB
[root@localhost ~]# docker run -d --name=mygogs -p 10022:22 -p 10080:3000 -v /var/gogs:/data gogs/gogs 
8d9da372bd4373532623cf875300ef21c0b166f78f2fd73cdf9b733cc747f647
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                            NAMES
8d9da372bd43        gogs/gogs           "docker/start.sh /bin"   7 seconds ago       Up 6 seconds        0.0.0.0:10022->22/tcp, 0.0.0.0:10080->3000/tcp   mygogs
01ff7db79a2b        mysql:latest        "docker-entrypoint.sh"   27 hours ago        Up 42 minutes       0.0.0.0:13306->3306/tcp                          mysql2

Gogs 的配置和使用

  1. 打开chrome 浏览器,输入网址 :http://192.168.1.161:10080/
  2. 第一次访问Gogs,浏览器进入安装页面,如图所示填写字段:
    Paste_Image.png
    Paste_Image.png
  3. 编辑 Gogs 配置文件(vi /var/gogs/gogs/conf/app.ini
    修改 ROOT_URL = http://192.168.1.161:10080/
......
[server]
DOMAIN       = 192.168.1.161
HTTP_PORT    = 3000
ROOT_URL     = http://192.168.1.161:10080/
DISABLE_SSH  = false
SSH_PORT     = 10022
OFFLINE_MODE = false
......

问题:为什么可以修改 Host 的 /var/gogs/ 目录的文件,就可以改变容器里的配置文件?
答案:因为启动容器的时候,我们使用 -v /var/gogs:/data 把 Host 里的目录 /var/gogs 挂载到容器的/data/目录

  1. 查看数据库的情况
C:\Users\andy>mysql -h 192.168.1.161 -P 13306 -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.16 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| gogs               |
| mysql              |
| performance_schema |
| sys                |
| testdb             |
+--------------------+
6 rows in set (0.06 sec)

mysql> use gogs
Database changed
mysql> show tables;
+----------------+
| Tables_in_gogs |
+----------------+
| access         |
| access_token   |
| action         |
| attachment     |
| collaboration  |
| comment        |
| deploy_key     |
| email_address  |
| follow         |
| hook_task      |
| issue          |
| issue_label    |
| issue_user     |
| label          |
| login_source   |
| milestone      |
| mirror         |
| notice         |
| org_user       |
| public_key     |
| pull_request   |
| release        |
| repository     |
| star           |
| team           |
| team_repo      |
| team_user      |
| update_task    |
| upload         |
| user           |
| version        |
| watch          |
| webhook        |
+----------------+
33 rows in set (0.00 sec)

小礼物走一走,来简书关注我

作者:andy0898
链接:https://www.jianshu.com/p/64e9708c23e7
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

redis 4.0 安装

PHP redis 扩展下载:https://pecl.php.net/package/redis

redis 安装包下载:https://redis.io/download

tar zxvf redis-4.0.8.tar.gz

mv redis-4.0.8 redis

make

编译完成之后,可以看到解压文件redis中会有对应的src、conf等文件夹,这和windows下安装解压的文件一样,大部分安装包都会有对应的类文件、配置文件和一些命令文件。

编译成功后,进入src文件夹,执行make install进行Redis安装

cd src
make install

首先为了方便管理,将Redis文件中的conf配置文件和常用命令移动到统一文件中

mkdir -p /usr/local/redis/bin
mkdir -p /usr/local/redis/ect

[root@CentOS6 redis]# mv redis.conf etc/
[root@CentOS6 redis]# cd src/
[root@CentOS6 src]# mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-cli redis-server /usr/local/redis/bin

切换到/usr/local/redis/etc目录,编辑redis.conf文件,将daemonize属性改为yes(表明需要在后台运行)

启动redis
[root@CentOS6 bin]# ./redis-server /usr/local/redis/etc/redis.conf

参考地址:https://www.cnblogs.com/KunGe-13/p/8340309.html

Elasticsearch5.6 安装

1 . 安装jdk 1.8

下载地址 : https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

tar -zxvf jdk-8u191-linux-x64.tar.gz

设置环境变量  /usr/java/jdk1.8.0_151 目录为刚解压的路径

vim /etc/profile

JAVA_HOME=/usr/java/jdk1.8.0_151
JRE_HOME=/usr/java/jdk1.8.0_151/jre
CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

执行命令 source /etc/profile 使用环境变量生效

测试
java -version

[root@MiWiFi-R3-srv ~]# java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
[root@MiWiFi-R3-srv ~]# 

2 . 安装 elasticsearch 5.6

创建es用户

groupadd elasticsearch

-g 加入分组

useradd -g elasticsearch elasticsearch

es目录权限分配给 elasticsearch 用户和组

chown -R elasticsearch:elasticsearch es目录

切换到 elasticsearch 用户登录

su elasticsearch

切换到es 目录

cd es目录

启动es 

./bin/elasticsearch

3 . 错误解决

  • max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

    elasticsearch启动时遇到的错误 问题翻译过来就是:elasticsearch用户拥有的内存权限太小,至少需要262144;

    解决:
    
    切换到root用户
    
    执行命令:
    
    sysctl -w vm.max_map_count=262144
    
    查看结果:
    
    sysctl -a|grep vm.max_map_count
    
    显示:
    
    vm.max_map_count = 262144
    
    上述方法修改之后,如果重启虚拟机将失效,所以:
    
    解决办法:
    
       /etc/sysctl.conf文件最后添加一行
    
    vm.max_map_count=262144

Thinkphp5框架调优

1.生成缓存文件

  • 生成自动加载缓存:

指令执行成功后,会在rumtime目录下面生成classmap.php文件,生成的类库映射文件会扫描系统目录和应用目录的类库。

  • 生成配置文件缓存:

默认生成应用的配置缓存文件,调用后会在runtime目录下面生成init.php文件,生成配置缓存文件后,应用目录下面的config.phpcommon.php以及tags.php不会被加载,被runtime/init.php取代。

  • 生成数据表字段缓存:

可以通过生成数据表字段信息缓存,提升数据库查询的性能,避免多余的SHOW COLUMNS 查询语句

datebase.php 里面设置 debug 为 false  才能生效

  • 生成路由映射缓存:

路由映射缓存用于开启路由延迟解析的情况下,支持路由反解的URL生成,如果你没有开启路由延迟解析或者没有使用URL路由反解生成则不需要生成。

参考文档:https://www.kancloud.cn/manual/thinkphp5_1/354145

ps:代码更新后记得更新缓存文件

 

Xhgui+Tideways 的使用

Tideways

将应用程序性能带出黑暗

不断分析您的应用程序的性能,使您能够找到性能欠佳的区域并从根本上进行修复

安装Tideways  PHP扩展

项目地址:https://github.com/tideways/php-xhprof-extension

编译安装:

配置PHP.ini  文件

[tideways_xhprof]
extension=c_xhprof.so
;不需要自动加载,在程序中控制就行
tideways.auto_prepend_library=0
;频率设置为100,在程序调用时能改
tideways.sample_rate=100

查看tideways 扩展是否安装

1.phpinfo()

2.php -m | grep tideways

xhgui

安装xhgui

安装依赖:

1.mongodb

2.composer

中文项目地址:https://github.com/laynefyc/xhgui-branch

配置文件目录:

xhprof_gui/config

安装xhgui

$ git clone https://github.com/maxincai/xhgui.git
 $ cd xhgui
 $ php install.php
加索引
$ mongo
 > use xhprof
 > db.results.ensureIndex( { 'meta.SERVER.REQUEST_TIME' : -1 } )
 > db.results.ensureIndex( { 'profile.main().wt' : -1 } )
 > db.results.ensureIndex( { 'profile.main().mu' : -1 } )
 > db.results.ensureIndex( { 'profile.main().cpu' : -1 } )
 > db.results.ensureIndex( { 'meta.url' : 1 } )

在需要分析的项目代码执行前引入文件

include "/xhgui/external/header.php";

设置查看分析记录web站点

server {
    listen   80;
    server_name  xhgui.kj120.cn;

    # root directive should be global
    root   /Users/birjemin/Developer/Php/xhprof_gui/webroot;
    index  index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        try_files       $uri =404;
        include         fastcgi_params;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

注意

  • 分析方式请自行更具url设置
    'profiler.enable' => function() {
        // url 中包含debug=1则百分百捕获
        if(!empty($_GET['debug'])){
            return True;
        }else{
            // 1%采样
            return rand(1, 100) === 42;
        }
    },
  • 在xhgui的config/config.default.php中,可设置采样命中次数;
    • return rand(1, 100) === 42; 为1%的采样率,改成return True;则标识每次都采样
  • 分析参数过多则清除mongodb数据
    $ mongo
      $ use xhprof;
      $ db.dropDatabase();

     

  • mongoDb报错这是一个bug(issue),请按照这个方法修改相应文件。替换掉这段代码

参考文档:

https://segmentfault.com/a/1190000013322461?utm_source=tag-newest

http://blog.it2048.cn/article-tideways-xhgui/

php 使用xhprof 性能分析

安装git hub 下载源码:https://github.com/longxinH/xhprof

先解压

cd xhprof/extension/

phpize

./configure

make &&
make install

配置php.ini 文件加载xhprof扩展

xhprof.output_dir  分析文件保存路径

执行

php -m | grep xhprof

可以看见输出,说明php扩展安装成功,然后重启Apache或者php-fpm

简易示例:

Thinkphp5 框架使用xhprof

在application/tags.php配置行为扩展文件

zabbix系统 源码安装

1、下载源码包

# wget -O zabbix-3.4.2.tar.gz http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.4.2/zabbix-3.4.2.tar.gz/download

2、安装依赖库

# yum -y install net-snmp-devel libxml2-devel libcurl-deve libevent libevent-devel

3、解压并编译

# tar -zxf zabbix-3.4.2.tar.gz
# cd zabbix-3.4.2
# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2

4、安装

# make && make install

5、创建zabbix用户和用户组

# groupadd zabbix
# useradd -r -g zabbix zabbix
# cd /usr/local && chown -R zabbix:zabbix zabbix

6、创建zabbix数据库,并导入表结构

复制代码
# mysql -uroot -p
mysql> create database if not exists zabbix default character set utf8 collate utf8_general_ci;
mysql> use zabbix;
mysql> source /tmp/zabbix-3.4.2/database/mysql/schema.sql;
mysql> source /tmp/zabbix-3.4.2/database/mysql/images.sql;
mysql> source /tmp/zabbix-3.4.2/database/mysql/data.sql;
复制代码

7、创建日志目录

# cd /usr/local/zabbix
# mkdir logs
# chown zabbix:zabbix logs

8、修改zabbix_server.conf

复制代码
# vim ./etc/zabbix_server.conf

LogFile=/usr/local/zabbix/logs/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/tmp/mysql.sock
Include=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf
复制代码

9、修改zabbix_agent.conf

# vim ./etc/zabbix_agentd.conf

PidFile=/tmp/zabbix_agentd.pid
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.con

10、启动zabbix_server 和 zabiix_agent服务

# /usr/local/zabbix/sbin/zabbix_server
# /usr/local/zabbix/sbin/zabbix_agent

PS:如果再启动的时候报错:error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory

解决方法:

# ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib/
# ldconfig

然后再次启动服务

11、拷贝WEB应用程序,/data/html为nginx或者Apache的运行PHP程序的目录

# mv /tmp/zabbix-3.4.2/frontends/php/ /data/html/zabbix
# chown -R www:www /data/html/zabbix

12、访问zabbix:http://ip/zabbix/index.php,初始化安装的默认账号:Admin,密码:zabbix

configure: error: Cannot find ldap libraries in /usr/lib 解决办法

configure: error: Cannot find ldap libraries in /usr/lib

解决办法:

cp -frp /usr/lib64/libldap* /usr/lib/