Freebsd 12
2021-08-13 14:49:27
Devops
144

Install Nginx

root@fb:/ # pkg install vim
root@fb:/ # pkg install nginx-full
root@fb:/ # which nginx
/usr/local/sbin/nginx
root@fb:/usr/local/etc/nginx # ll
total 72
drwx------  2 www   wheel   512 Jun  4 11:04 ajp_temp/
-rw-r--r--  1 root  wheel  1007 May 27 02:04 fastcgi_params
-rw-r--r--  1 root  wheel  1007 May 27 02:04 fastcgi_params-dist
-rw-r--r--  1 root  wheel  2837 May 27 02:04 koi-utf
-rw-r--r--  1 root  wheel  2223 May 27 02:04 koi-win
-rw-r--r--  1 root  wheel  5231 May 27 02:04 mime.types
-rw-r--r--  1 root  wheel  5231 May 27 02:04 mime.types-dist
-rw-r--r--  1 root  wheel  6333 May 27 02:04 naxsi_core.rules
-rw-r--r--  1 root  wheel  2989 May 27 02:04 nginx.conf
-rw-r--r--  1 root  wheel  2989 May 27 02:04 nginx.conf-dist
-rw-r--r--  1 root  wheel   636 May 27 02:04 scgi_params
-rw-r--r--  1 root  wheel   636 May 27 02:04 scgi_params-dist
-rw-r--r--  1 root  wheel   664 May 27 02:04 uwsgi_params
-rw-r--r--  1 root  wheel   664 May 27 02:04 uwsgi_params-dist
-rw-r--r--  1 root  wheel  3610 May 27 02:04 win-utf
root@fb:/usr/local/etc/nginx # ll /usr/local/www/
total 4
lrwxr-xr-x  1 root  wheel   25 Jun  4 11:04 nginx@ -> /usr/local/www/nginx-dist
dr-xr-xr-x  2 root  wheel  512 Jun  4 11:04 nginx-dist/

SSH使用PEM文件登录

方式一

ssh -i key.pem root@IP

如果出现报错说明这个问题是文件的权限太大了,需要给小点:
sudo chmod 600 key.pem 

方式二

可以使用ssh-add 添加key文件:
ssh-add -k key.pem  

正常登录堡垒机:
ssh root@IP

Freebsd for ECS 系统盘扩容示例

背景

由于历史遗留问题,Freebsd 系统盘出厂大小是 30G,即使购买的系统盘大小大于 30G,系统内分配的也是 30G 大小,那么云上的 Freebsd 如何扩容系统盘呢?

1,查看磁盘信息,不同于 CentOS/Ubuntu系统使用fdisk,

Freebsd 使用gpart 查看磁盘分区信息

# gpart show
=>      63  83886017  vtbd0  MBR  (40G)
        63         1         - free -  (512B)
        64  41942975      1  freebsd  [active]  (20G)(在用的)
  41943039  41943041         - free -  (20G) (空闲的)

注:根据官方资料介绍,可以到 /var/run/dmesg.boot 看设备信息,但尴尬的是云上IO优化实例使用KVM的虚拟化技术后,该文件记录似乎不准了(文件记录的是ufs的挂载),因此使用gpart show直接查看

Determine the device name of the disk to be resized by inspecting /var/run/dmesg.boot. In this example, there is only one SATA disk in the system, so the drive will appear as ada0.

2,恢复磁盘的空闲大小(新购系统的扩容理论上可以忽略这一步)

# gpart recover vtbd0
vtbd0 recovering is not needed 

3,扩容分区

# gpart resize -i 1 -a 4k -s 39G vtbd0
vtbd0s1 resized
# gpart show
=>      63  83886017  vtbd0  MBR  (40G)
        63         1         - free -  (512B)
        64  81788928      1  freebsd  [active]  (39G)
  81788992   2097088         - free -  (1.0G)

注: -i 1 类似于扩容的分区是/dev/vda1 -a 4k 4k对齐 -s 39G 扩容后大小 由于有启动分区的占用,因此不能写满 40G,写满的话会报错+

# gpart resize -i 1 -a 4k -s 40G vtbd0 
gpart: size '83886080': Invalid argument

4,文件系统扩容

# service growfs onestart
Growing root partition to fill device
vtbd0s1 resized
super-block backups (for fsck_ffs -b #) at:
 42314112, 43596352, 44878592, 46160832, 47443072, 48725312, 50007552, 51289792, 52572032, 53854272, 55136512, 56418752, 57700992, 58983232, 60265472, 61547712,
 62829952, 64112192, 65394432, 66676672, 67958912, 69241152, 70523392, 71805632, 73087872, 74370112, 75652352, 76934592, 78216832, 79499072, 80781312, 82063552,
 83345792
# gpart show
=>      63  83886017  vtbd0  MBR  (40G)
        63         1         - free -  (512B)
        64  83886016      1  freebsd  [active]  (40G)

 # df -lh
Filesystem                     Size    Used   Avail Capacity  Mounted on
/dev/ufsid/59a7effe7885633c     39G    3.9G     32G    11%    /
devfs                          1.0K    1.0K      0B   100%    /dev