作者存档: nick - 第4页

Wonderland 成功迁入 Kubernetes

1.kubernetes 安装
2.本地镜像仓库搭建
3.nginx+php-fpm镜像构建
4.mysql镜像构建
5.配置service和stateful
6.启用、测试访问成功

NAME          READY   STATUS    RESTARTS   AGE     IP            NODE          NOMINATED NODE   READINESS GATES
image-bar-0   1/1     Running   1          4d12h   10.244.4.17   k8s.worker0              
mysql-0       1/1     Running   0          80m     10.244.4.30   k8s.worker0              
nginx-0       1/1     Running   0          106s    10.244.4.34   k8s.worker0              
nginx-1       1/1     Running   0          101s    10.244.4.35   k8s.worker0              

7.其它模块迁入…

[原创]开启 adb 远程调试

场景:手机接在一台公用的Linux服务器A上,开发机B与服务器A在同一局域网,需要远程连接手机调试
步骤:
1. ssh 登录 A
2. adb tcpip 5555 // 手机5555上监听adb连接
3. adb forward tcp:5555 tcp:5555 // 服务器A的5555转发到手机5555端口
4. nohup ssh -N -L 0.0.0.0:5556:127.0.0.1:5555 root@localhost 2>&1 >/dev/null & // 由于adb forward绑定的IP是127.0.0.1,需要转发下,这里简单点直接用ssh隧道,监听5556端口转发到本地5555端口。
5. 在开发机上 adb connect ipA:5556 // adb连接A的5556端口
6. Android Studio 上运行测试,显示以下就OK了
ADB
其它:
1. 速度上比USB要慢不少,但在可接受范围,单步断点调试也正常
BreakPoint
2. 一段时间不使用可能会断开,需要重复第3和5步,重新连接
3. 如果手机也连了wifi,且在同一局域网中,也可以跳过第3和4步,直接连接手机

AS删除iml的解决方案

一直被此问题困扰,google后找到解决方案:

I had this annoying issue where Android Studio kept deleting my top-level project file (.iml) whenever I do a gradle sync. For months I had no idea why and Google search doesn’t seem to show this as a common issue. Finally today I got to the bottom of this.

The issue was the casing of the file names. For the project file, I had mixed capital and lowercase, whereas the project folder name was all lowercase. This inconsistency was due to a move of the project from a windows environment to a mac where I had a different folder name.

The fix for this issue was simple: Close the project in Android Studio and delete all the .iml files. Then use File > Import project and select the project folder and this will regenerate all the .iml files. The new .iml files should now match the case of the folder.

k8s pod一直处于ContainerCreating状态

问题排查:
kubectl describe pods xxx
显示 Error syncing pod, skipping: failed to “StartContainer” for “POD” with ErrImagePull: “image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request. details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)”
ll -h /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt 显示指向 /etc/rhsm/ca/redhat-uep.pem
/etc/rhsm/ca/redhat-uep.pem 不存在导致问题

解决问题:
网上解决方案 yum install python-rhsm-certificates 现在失效了 Package python-rhsm-certificates-1.19.10-1.el7_4.x86_64 is obsoleted by subscription-manager-rhsm-certificates-1.20.11-1.el7.centos.x86_64 which is already installed
需要手动下载和生成pem
wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm
rpm2cpio python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm | cpio -iv –to-stdout ./etc/rhsm/ca/redhat-uep.pem | tee /etc/rhsm/ca/redhat-uep.pem

iOS网页安装app

1、使用企业证书打包ipa;
2、写plist,放到https站点上

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">  
<plist version="1.0">  
<dict>  
    <key>items</key>  
    <array>  
        <dict>  
            <key>assets</key>  
            <array>  
                <dict>  
                    <key>kind</key>  
                    <string>software-package</string>  
                    <key>url</key>  
                    <string>ipa的URL,http即可</string>  
                </dict>  
                <dict>  
                    <key>kind</key>  
                    <string>full-size-image</string>  
                    <key>needs-shine</key>  
                    <true/>  
                    <key>url</key>  
                    <string>2x图标URL</string>  
                </dict>  
                <dict>  
                    <key>kind</key>  
                    <string>display-image</string>  
                    <key>needs-shine</key>  
                    <true/>  
                    <key>url</key>  
                    <string>图标URL</string>  
                </dict>  
            </array>  
            <key>metadata</key>  
            <dict>  
                <key>bundle-identifier</key>  
                <string>这里填bundle-id</string>  
                <key>bundle-version</key>  
                <string>这里是版本号</string>  
                <key>kind</key>  
                <string>software</string>  
                <key>title</key>  
                <string>标题</string>  
            </dict>  
        </dict>  
    </array>  
</dict>  
</plist>

3、填入下载链接:itms-services://?action=download-manifest&url=https://www.xx.com/download/xx.plist

MySQL 事务

MySQL 事务主要用于处理操作量大,复杂度高的数据。比如说,在人员管理系统中,你删除一个人员,你即需要删除人员的基本资料,也要删除和该人员相关的信息,如信箱,文章等等,这样,这些数据库操作语句就构成一个事务!
在 MySQL 中只有使用了 Innodb 数据库引擎的数据库或表才支持事务。
事务处理可以用来维护数据库的完整性,保证成批的 SQL 语句要么全部执行,要么全部不执行。
事务用来管理 insert,update,delete 语句

一般来说,事务是必须满足4个条件(ACID)::原子性(Atomicity,或称不可分割性)、一致性(Consistency)、隔离性(Isolation,又称独立性)、持久性(Durability)。
原子性:一个事务(transaction)中的所有操作,要么全部完成,要么全部不完成,不会结束在中间某个环节。事务在执行过程中发生错误,会被回滚(Rollback)到事务开始前的状态,就像这个事务从来没有执行过一样。
一致性:在事务开始之前和事务结束以后,数据库的完整性没有被破坏。这表示写入的资料必须完全符合所有的预设规则,这包含资料的精确度、串联性以及后续数据库可以自发性地完成预定的工作。
隔离性:数据库允许多个并发事务同时对其数据进行读写和修改的能力,隔离性可以防止多个事务并发执行时由于交叉执行而导致数据的不一致。事务隔离分为不同级别,包括读未提交(Read uncommitted)、读提交(read committed)、可重复读(repeatable read)和串行化(Serializable)。
持久性:事务处理结束后,对数据的修改就是永久的,即便系统故障也不会丢失。

在 MySQL 命令行的默认设置下,事务都是自动提交的,即执行 SQL 语句后就会马上执行 COMMIT 操作。因此要显式地开启一个事务务须使用命令 BEGIN 或 START TRANSACTION,或者执行命令 SET AUTOCOMMIT=0,用来禁止使用当前会话的自动提交。

事务控制语句:
BEGIN或START TRANSACTION;显式地开启一个事务;
COMMIT;也可以使用COMMIT WORK,不过二者是等价的。COMMIT会提交事务,并使已对数据库进行的所有修改称为永久性的;
ROLLBACK;有可以使用ROLLBACK WORK,不过二者是等价的。回滚会结束用户的事务,并撤销正在进行的所有未提交的修改;
SAVEPOINT identifier;SAVEPOINT允许在事务中创建一个保存点,一个事务中可以有多个SAVEPOINT;
RELEASE SAVEPOINT identifier;删除一个事务的保存点,当没有指定的保存点时,执行该语句会抛出一个异常;
ROLLBACK TO identifier;把事务回滚到标记点;
SET TRANSACTION;用来设置事务的隔离级别。InnoDB存储引擎提供事务的隔离级别有READ UNCOMMITTED、READ COMMITTED、REPEATABLE READ和SERIALIZABLE。

MYSQL 事务处理主要有两种方法:
1、用 BEGIN, ROLLBACK, COMMIT来实现
BEGIN 开始一个事务
ROLLBACK 事务回滚
COMMIT 事务确认

2、直接用 SET 来改变 MySQL 的自动提交模式:
SET AUTOCOMMIT=0 禁止自动提交
SET AUTOCOMMIT=1 开启自动提交

mysql> use RUNOOB;
Database changed
mysql> CREATE TABLE runoob_transaction_test( id int(5)) engine=innodb;  # 创建数据表
Query OK, 0 rows affected (0.04 sec)
 
mysql> select * from runoob_transaction_test;
Empty set (0.01 sec)
 
mysql> begin;  # 开始事务
Query OK, 0 rows affected (0.00 sec)
 
mysql> insert into runoob_transaction_test value(5);
Query OK, 1 rows affected (0.01 sec)
 
mysql> insert into runoob_transaction_test value(6);
Query OK, 1 rows affected (0.00 sec)
 
mysql> commit; # 提交事务
Query OK, 0 rows affected (0.01 sec)
 
mysql>  select * from runoob_transaction_test;
+------+
| id   |
+------+
| 5    |
| 6    |
+------+
2 rows in set (0.01 sec)
 
mysql> begin;    # 开始事务
Query OK, 0 rows affected (0.00 sec)
 
mysql>  insert into runoob_transaction_test values(7);
Query OK, 1 rows affected (0.00 sec)
 
mysql> rollback;   # 回滚
Query OK, 0 rows affected (0.00 sec)
 
mysql>   select * from runoob_transaction_test;   # 因为回滚所以数据没有插入
+------+
| id   |
+------+
| 5    |
| 6    |
+------+
2 rows in set (0.01 sec)
 
mysql>
<?php
$dbhost = 'localhost:3306';  // mysql服务器主机地址
$dbuser = 'root';            // mysql用户名
$dbpass = '123456';          // mysql用户名密码
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
    die('连接失败: ' . mysqli_error($conn));
}
// 设置编码,防止中文乱码
mysqli_query($conn, "set names utf8");
mysqli_select_db( $conn, 'RUNOOB' );
mysqli_query($conn, "SET AUTOCOMMIT=0"); // 设置为不自动提交,因为MYSQL默认立即执行
mysqli_begin_transaction($conn);            // 开始事务定义
 
if(!mysqli_query($conn, "insert into runoob_transaction_test (id) values(8)"))
{
    mysqli_query($conn, "ROLLBACK");     // 判断当执行失败时回滚
}
 
if(!mysqli_query($conn, "insert into runoob_transaction_test (id) values(9)"))
{
    mysqli_query($conn, "ROLLBACK");      // 判断执行失败时回滚
}
mysqli_commit($conn);            //执行事务
mysqli_close($conn);
?>

20180324

浏览器缓存策略

两张图阐述浏览器缓存策略

20180203 美好时光

CentOS7使用firewalld配置

1、firewalld的基本使用
启动: systemctl start firewalld
查看状态: systemctl status firewalld
停止: systemctl disable firewalld
禁用: systemctl stop firewalld

2.systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。
启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl –failed

3.配置firewalld-cmd

查看版本: firewall-cmd –version
查看帮助: firewall-cmd –help
显示状态: firewall-cmd –state
查看所有打开的端口: firewall-cmd –zone=public –list-ports
更新防火墙规则: firewall-cmd –reload
查看区域信息: firewall-cmd –get-active-zones
查看指定接口所属区域: firewall-cmd –get-zone-of-interface=eth0
拒绝所有包:firewall-cmd –panic-on
取消拒绝状态: firewall-cmd –panic-off
查看是否拒绝: firewall-cmd –query-panic

那怎么开启一个端口呢
添加
firewall-cmd –zone=public –add-port=80/tcp –permanent (–permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd –reload
查看
firewall-cmd –zone= public –query-port=80/tcp
删除
firewall-cmd –zone= public –remove-port=80/tcp –permanent