青蛙小白
#Mysql

MySQL实用整理

查看锁表线程 使用下面的命令查看哪个表被锁了: show open tables where in_use>0; +----------+-------+--------+-------------+ | Database | Table | In_use | Name_locked | +------------------+--------+-------------+ | test | t_user | 0 | 0 | | test | t_role | 4 | 0 | In_use表示有多少线程正在使用该表,这些线程有可能已经给该表加锁,或者正在等待或得锁给该表加锁 Name_locked是否表名称被锁定,表名称被锁定一般发生在rename table时。 结合show processlist可查看哪个线程锁表了:

#Linux

Linux系统磁盘与文件系统管理

磁盘的分区、格式化、挂载 使用fdisk -l列出系统上所有的磁盘分区信息。它会显示您系统中的硬盘设备以及每个设备上的分区情况,包括分区的起始扇区、大小、文件系统类型等。 fdisk -l Disk /dev/vda: 100 GiB, 107374182400 bytes, 209715200 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xa26fc47b Device Boot Start End Sectors Size Id Type /dev/vda1 2048 4194303 4192256 2G e W95 FAT16 (LBA) /dev/vda2 4194304 83886079 79691776 38G 83 Linux Disk /dev/vdb: 8 GiB, 8589934592 bytes, 16777216 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes 使用df -h命令显示系统上各个文件系统的磁盘使用情况和剩余空间。它会显示文件系统的挂载点、总容量、已用空间、剩余空间和使用率等信息。

#Gradle

Gradle实用整理

使用账号密码访问受保护的maven仓库 当nexus中禁用了匿名用户(Anonymous)对仓库的访问时,我们需要在构建脚本中指定访问仓库的账号和密码。 repositories { maven { url "http://192.168.1.10:8081/nexus/content/repositories/releases/" credentials { username 'user' password 'password' } } } 上门的配置虽然能达到目的,但是用户名和密码是明文写到构建脚本中的,构建脚本需要被提交到版本管理系统中,这显然是不安全的,而且不支持针对每个开发人员使用不同的用户和密码。 更进一步,我们可以将用户名密码写到GRADLE_USER_HOME\gradle.properties中:

#Rabbitmq

使用RabbitMQ Java Client

Publishing Messages 连接到Broker 获取Channel 声明一个Exchange 创建一个Message 发布这个Message 关闭Channel 关闭Connection ConnectionFactory connectionFactory = new ConnectionFactory(); // AMQP URI amqp://userName:password@hostName:portNumber/virtualHost" connectionFactory.setUri("amqp://test:[email protected]:5672/demo"); Connection connection = connectionFactory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare("first-exchange", "direct", true); byte[] msgBody = "Hello, World!".getBytes("UTF-8"); channel.basicPublish("first-exchange", "helloRoutingKey", null, msgBody); channel.close(); connection.close(); Receiving Messages by Subscription public static void main(String[] args) throws Exception { ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setUri("amqp://test:[email protected]:5672/demo"); Connection connection = connectionFactory.newConnection(); final Channel channel = connection.createChannel(); channel.exchangeDeclare("first-exchange", "direct", true); channel.queueDeclare("hello-queue", true, false, false, null); channel.queueBind("hello-queue", "first-exchange", "helloRoutingKey"); channel.basicConsume("hello-queue", new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException { String msg = new String(body, "UTF-8"); System.out.println(msg); channel.basicAck(envelope.getDeliveryTag(), false); } }); Scanner scanner = new Scanner(System.in); scanner.nextLine(); scanner.close(); channel.close(); connection.close(); }

#Rabbitmq

安装RabbitMQ

RabbitMQ是一个开源的AMQP实现,服务端使用Erlang语言编写,支持多种客户端, 如:Python、Ruby、.NET、Java、JMS、C、PHP、ActionScript、XMPP、STOPMP等。 构建和安装Erlang 提前安装所需依赖: yum install ncurses-devel yum install openssl yum install openssl-devel yum install unixODBC yum install unixODBC-devel yum install gcc yum install gcc-c++ 从Erlang官网下载Erlang源码。 以下构建和安装的过程参考这里。

#Rabbitmq

AMQP协议简介

简介 AMQP即Advanced Message Queuing Protocol,高级消息队列协议,是面向消息中间件设计的应用层协议的一个开放标准。 它的主要特点是面向消息、队列、路由(包括点对点和发布/订阅)]、可靠性和安全。 AMQP允许来自不同供应商的消息生产者和消费者实现真正的互操作扩展,就如同SMTP、HTTP、FTP等协议采用的方式一样。而此前对于消息中间件的标准化努力则集中在API层面上(比如JMS),且没有提供互操作性的途径。不同于JMS的仅仅定义API,AMQP是一个线路级的协议——它描述了通过网络传输的字节流的数据格式。因此,遵从这个协议的任何语言编写的工具均可以操作AMQP消息。