Hero Image
How to automatically resize virtual box disk with vagrant

How to automatically resize virtual box disk with vagrant Increasing Disk Space of a Linux-based Vagrant Box on Provisioning Vagrant.configure(2) do |config| config.vm.box = "centos/7" config.disksize.size = '20GB' end $ sudo parted /dev/sda resizepart 2 100% $ sudo lvextend -l +100%FREE /dev/centos/root $ sudo xfs_growfs /dev/centos/root Automate Part Vagrant.configure(2) do |config| common = <<-SCRIPT sudo parted /dev/sda resizepart 2 100% sudo pvresize /dev/sda2 sudo lvextend -l +100%FREE /dev/centos/root sudo xfs_growfs /dev/centos/root SCRIPT config.vm.define "node01" do |node1| node1.vm.hostname = "node01" node1.vm.network "private_network", ip: "192.168.56.121" config.vm.provision :shell, :inline => common end end vagrant plugin install vagrant-disksize Vagrantfile # Fail if the vagrant-disksize plugin is not installed unless Vagrant.has_plugin?("vagrant-disksize") raise 'vagrant-disksize is not installed!' end Vagrant.configure("2") do |config| config.vm.provider "virtualbox" do |vb| vb.name = "DISKEXTEND" vb.memory = 2048 vb.cpus = 2 end config.vm.define :"DISKEXTEND" do |t| end config.vm.hostname = "DISKEXTEND" config.vm.box = "bento/ubuntu-18.04" # Increase the default disk size of the bento image (64GB) to 96GB config.disksize.size = "96GB" # Run a script on provisioning the box to format the file system config.vm.provision "shell", path: "disk-extend.sh" end Provisioning Script: disk-extend.sh #!/bin/bash echo "> Installing required tools for file system management" if [ -n "$(command -v yum)" ]; then echo ">> Detected yum-based Linux" sudo yum makecache sudo yum install -y util-linux sudo yum install -y lvm2 sudo yum install -y e2fsprogs fi if [ -n "$(command -v apt-get)" ]; then echo ">> Detected apt-based Linux" sudo apt-get update -y sudo apt-get install -y fdisk sudo apt-get install -y lvm2 sudo apt-get install -y e2fsprogs fi ROOT_DISK_DEVICE="/dev/sda" ROOT_DISK_DEVICE_PART="/dev/sda1" LV_PATH=`sudo lvdisplay -c | sed -n 1p | awk -F ":" '{print $1;}'` FS_PATH=`df / | sed -n 2p | awk '{print $1;}'` ROOT_FS_SIZE=`df -h / | sed -n 2p | awk '{print $2;}'` echo "The root file system (/) has a size of $ROOT_FS_SIZE" echo "> Increasing disk size of $ROOT_DISK_DEVICE to available maximum" sudo fdisk $ROOT_DISK_DEVICE <<EOF d n p 1 2048 no w EOF sudo pvresize $ROOT_DISK_DEVICE_PART sudo lvextend -l +100%FREE $LV_PATH sudo resize2fs -p $FS_PATH ROOT_FS_SIZE=`df -h / | sed -n 2p | awk '{print $2;}'` echo "The root file system (/) has a size of $ROOT_FS_SIZE" exit 0

Hero Image
Google Search Operators: The Complete List (44 Advanced Operators)

Google Search Operators: The Complete List (44 Advanced Operators) Working Search operator What it does Example " " Search for results that mention a word or phrase. "steve jobs" OR Search for results related to X or Y. jobs OR gates | Same as OR. jobs | gates AND Search for results related to X and Y. jobs AND gates - Search for results that don’t mention a word or phrase. jobs -apple * Wildcard matching any word or phrase. steve * apple ( ) Group multiple searches. (ipad OR iphone) apple define: Search for the definition of a word or phrase. define:entrepreneur cache: Find the most recent cache of a webpage. cache:apple.com filetype: Search for particular types of files (e.g., PDF). apple filetype:pdf ext: Same as filetype: apple ext:pdf site: Search for results from a particular website. site:apple.com related: Search for sites related to a given domain. related:apple.com intitle: Search for pages with a particular word in the title tag. intitle:apple allintitle: Search for pages with multiple words in the title tag. allintitle:apple iphone inurl: Search for pages with a particular word in the URL. inurl:apple allinurl: Search for pages with multiple words in the URL. allinurl:apple iphone intext: Search for pages with a particular word in their content. intext:apple iphone allintext: Search for pages with multiple words in their content. allintext:apple iphone weather: Search for the weather in a location. weather:san francisco stocks: Search for stock information for a ticker. stocks:aapl map: Force Google to show map results. map:silicon valley movie: Search for information about a movie. movie:steve jobs in Convert one unit to another. $329 in GBP source: Search for results from a particular source in Google News. apple source:the_verge before: Search for results from before a particular date. apple before:2007-06-29 after: Search for results from after a particular date. apple after:2007-06-29 Unreliable Search operator What it does Example #..# Search within a range of numbers. iphone case $50..$60 inanchor: Search for pages with backlinks containing specific anchor text. inanchor:apple allinanchor: Search for pages with backlinks containing multiple words in their anchor text. allinanchor:apple iphone AROUND(X) Search for pages with two words or phrases within X words of one another. apple AROUND(4) iphone loc: Find results from a given area. loc:"san francisco" apple location: Find news from a certain location in Google News. location:"san francisco" apple daterange: Search for results from a particular date range. daterange:11278-13278 Not working (officially dropped by Google) Search operator What it does Example ~ Include synonyms in the search (dropped 2013). ~apple + Search for results mentioning an exact word or phrase (dropped 2011). jobs +apple inpostauthor: Search for posts by a specific author in Google Blog Search (discontinued). inpostauthor:"steve jobs" allinpostauthor: Same as inpostauthor:, but removes the need for quotes. allinpostauthor:steve jobs inposttitle: Search for posts with certain words in the title in Google’s discontinued Blog Search. inposttitle:apple iphone link: Search for pages linking to a particular domain or URL (dropped 2017). link:apple.com info: Search for information about a specific page or website (dropped 2017). info:apple.com id: Same as info: id:apple.com phonebook: Search for someone’s phone number (dropped 2010). phonebook:tim cook # Search for hashtags on Google+ (dropped 2019). #apple

Hero Image
SSH 证书登录教程

SSH 证书登录教程 证书登录的流程 SSH 证书登录之前,如果还没有证书,需要生成证书。具体方法是: 用户和服务器都将自己的公钥,发给 CA CA 使用服务器公钥,生成服务器证书,发给服务器 CA 使用用户的公钥,生成用户证书,发给用户。 有了证书以后,用户就可以登录服务器了。整个过程都是 SSH 自动处理,用户无感知。 用户登录服务器时,SSH 自动将用户证书发给服务器。 服务器检查用户证书是否有效,以及是否由可信的 CA 颁发。 SSH 自动将服务器证书发给用户。 用户检查服务器证书是否有效,以及是否由信任的 CA 颁发。 双方建立连接,服务器允许用户登录。 生成 CA 的密钥 虽然 CA 可以用同一对密码签发用户证书和服务器证书,但是出于安全性和灵活性,最好用不同的密钥分别签发。所以,CA 至少需要两对密钥,一对是签发用户证书的密钥,假设叫做 user_ca,另一对是签发服务器证书的密钥,假设叫做 host_ca。 # 生成 CA 签发用户证书的密钥 # 会在~/.ssh目录生成一对密钥:user_ca(私钥)和user_ca.pub(公钥) # 各个参数含义如下 # -t rsa:指定密钥算法 RSA。 # -b 4096:指定密钥的位数是4096位。安全性要求不高的场合,这个值可以小一点,但是不应小于1024。 # -f ~/.ssh/user_ca:指定生成密钥的位置和文件名。 # -C user_ca:指定密钥的识别字符串,相当于注释,可以随意设置。 $ ssh-keygen -t rsa -b 4096 -f ~/.ssh/user_ca -C user_ca # 生成 CA 签发服务器证书的密钥 # 会在~/.ssh目录生成一对密钥:host_ca(私钥)和host_ca.pub(公钥) # 现在,~/.ssh目录应该至少有四把密钥。 # - ~/.ssh/user_ca # - ~/.ssh/user_ca.pub # - ~/.ssh/host_ca # - ~/.ssh/host_ca.pub $ ssh-keygen -t rsa -b 4096 -f host_ca -C host_ca 服务器安装 CA 公钥 # 为了让服务器信任用户证书,必须将 CA 签发用户证书的公钥`user_ca.pub`,拷贝到服务器 $ scp ~/.ssh/user_ca.pub root@host.example.com:/etc/ssh/ 然后,将下面一行添加到服务器配置文件 /etc/ssh/sshd_config TrustedUserCAKeys /etc/ssh/user_ca.pub 上面的做法是将user_ca.pub加到/etc/ssh/sshd_config,这会产生全局效果,即服务器的所有账户都会信任user_ca签发的所有用户证书。

Hero Image
nginx 添加第三方nginx_upstream_check_module 模块实现健康状态检测

nginx 添加第三方 nginx_upstream_check_module 模块实现健康状态检测 nginx_upstream_check_module Health check HTTP servers inside an upstream nginx.conf http { upstream cluster { # simple round-robin server 192.168.0.1:80; server 192.168.0.2:80; check interval=5000 rise=1 fall=3 timeout=4000; #check interval=3000 rise=2 fall=5 timeout=1000 type=ssl_hello; #check interval=3000 rise=2 fall=5 timeout=1000 type=http; #check_http_send "HEAD / HTTP/1.0\r\n\r\n"; #check_http_expect_alive http_2xx http_3xx; } ... check syntax: *check interval=milliseconds [fall=count] [rise=count] [timeout=milliseconds] [default_down=true|false] [type=tcp|http|ssl_hello|mysql|ajp|fastcgi]* 默认配置:interval=3000 fall=5 rise=2 timeout=1000 default_down=true type=tcp* ... interval: 检测间隔 3 秒 fall: 连续检测失败次数 5 次时,认定 relaserver is down rise: 连续检测成功 2 次时,认定 relaserver is up timeout: 超时 1 秒 default_down: 初始状态为 down,只有检测通过后才为 up type: 检测类型方式 tcp tcp :tcp 套接字,不建议使用,后端业务未 100%启动完成,前端已经放开访问的情况 ssl_hello: 发送 hello 报文并接收 relaserver 返回的 hello 报文 http: 自定义发送一个请求,判断上游 relaserver 接收并处理 mysql: 连接到 mysql 服务器,判断上游 relaserver 是否还存在 ajp: 发送 AJP Cping 数据包,接收并解析 AJP Cpong 响应以诊断上游 relaserver 是否还存活(AJP tomcat 内置的一种协议) fastcgi: php 程序是否存活 example