Press "Enter" to skip to content

分类: Linux

阿里云CentOS8.2系统盘扩容方法

使用阿里云镜像默认为Linux 20G大小,如果选择了40G容量或是更大容量硬盘大小,装好镜像系统后盘还是20G,需要自己动手对系统盘进行扩容操作,这点是真的不方便,有技术底子的人可以分分钟搞定,那对于普通应用者来说是比较麻烦的,其实命令就这几个,记录一下供大家参考:

用fdisk -l查看硬盘是40G,还有20G未被加载使用

[root@kiccleaf ~]# fdisk -l
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 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: 0x76042835

Device     Boot Start      End  Sectors Size Id Type
/dev/vda1  *     2048 41943039 41940992  20G 83 Linux

先查看一下你的系统盘是否默认20G或是30G大小,这里我选择了CentOS8.2 x64版本的,默认为20G:/dev/vda1 xfs 20G 2.4G 18G 12% /
用df -Th命令查看/dev/vda1盘,xfs盘格式,最新的系统一般都采用此格式,老的有ext3–ext4等。

[root@kiccleaf ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs          tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs          tmpfs     1.9G  448K  1.9G   1% /run
tmpfs          tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/vda1      xfs        20G  2.4G   18G  12% /
tmpfs          tmpfs     378M     0  378M   0% /run/user/0

用命令growpart /dev/vda 1 分区热扩展vda和1中间有空格

[root@kiccleaf ~]# growpart /dev/vda 1
CHANGED: partition=1 start=2048 old: size=41940992 end=41943040 new: size=83883999,end=83886047

xfs格式的硬盘采用xfs_growfs /命令即可,表示为扩容系统盘的/dev/vda1分区的文件系统。其中根目录(/)为/dev/vda1的挂载点。
如果是其他格式采用:ext*文件系统(例如ext3和ext4):运行resize2fs /dev/vda1命令。

[root@kiccleaf ~]# xfs_growfs /
meta-data=/dev/vda1              isize=512    agcount=4, agsize=1310656 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=5242624, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 5242624 to 10485499

用命令df -h 查看一下系统盘容量是否已经到40G了

[root@kiccleaf ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        1.9G     0  1.9G   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           1.9G  448K  1.9G   1% /run
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/vda1        40G  2.6G   38G   7% /
tmpfs           378M     0  378M   0% /run/user/0
Leave a Comment

CentOS8挂载新硬盘

创建新硬盘分区命令参数:
fdisk可以用m命令来看fdisk命令的内部命令;
a:命令指定启动分区;
d:命令删除一个存在的分区;
l:命令显示分区ID号的列表;
m:查看fdisk命令帮助;
n:命令创建一个新分区;
p:命令显示分区列表;
t:命令修改分区的类型ID号;
w:命令是将对分区表的修改存盘让它发生作用

[root@kiccleaf ~]# fdisk -l
Disk /dev/sda: 1000 GiB, 1073741824000 bytes, 2097152000 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: 0x16aee8ac

Device     Boot   Start        End    Sectors  Size Id Type
/dev/sda1  *       2048    2099199    2097152    1G 83 Linux
/dev/sda2       2099200 2097151999 2095052800  999G 8e Linux LVM


//新硬盘
Disk /dev/sdb: 1000 GiB, 1073741824000 bytes, 2097152000 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


Disk /dev/mapper/cl-root: 50 GiB, 53687091200 bytes, 104857600 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


Disk /dev/mapper/cl-swap: 7.9 GiB, 8468299776 bytes, 16539648 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


Disk /dev/mapper/cl-home: 941.1 GiB, 1010508496896 bytes, 1973649408 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
[root@kiccleaf ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xa5c1ca20.

Command (m for help): n
Partition type
   //输入p分为主分区
   p   primary (0 primary, 0 extended, 4 free)
   //输入e分为逻辑分区
   e   extended (container for logical partitions)
Select (default p): p
//输入该主分区为第几个主分区,由于是新盘我们输入1来分第一个主分区
Partition number (1-4, default 1): 1
 
//First sector 是选择该分区的起始扇区,直接回车
First sector (2048-2097151999, default 2048): 
//使用全部可用存储额,直接回车
Last sector, +sectors or +size{K,M,G,T,P} (2048-2097151999, default 2097151999): 

Created a new partition 1 of type 'Linux' and of size 1000 GiB.

//w保存
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
//mkfs.xfs命令带-f强制格式化
[root@kiccleaf ~]# mkfs.xfs -f /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=65535936 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=262143744, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=127999, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
//用命令blkid 查看一下已是xfs格式
[root@kiccleaf data]# blkid /dev/sdb1
/dev/sdb1: UUID="813681bd-a154-43d8-88dc-27750eacfcc1" TYPE="xfs" PARTUUID="a5c1ca20-01"
//创建挂载目录
[root@kiccleaf ~]# mkdir /data
//mount直接挂载硬盘至data
[root@kiccleaf ~]# mount /dev/sdb1 /data
//查看一下挂载的硬盘data已经有了
[root@kiccleaf ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             3.8G     0  3.8G   0% /dev
tmpfs                3.9G     0  3.9G   0% /dev/shm
tmpfs                3.9G  9.0M  3.8G   1% /run
tmpfs                3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/cl-root   50G  6.3G   44G  13% /
/dev/mapper/cl-home  941G  6.7G  935G   1% /home
/dev/sda1            976M  198M  711M  22% /boot
tmpfs                779M     0  779M   0% /run/user/0
/dev/sdb1            984G   77M  934G   1% /data
//系统重启自动挂载该分区对fstab进行编辑
[root@kiccleaf ~]# vim /etc/fstab

系统重启自动挂载该分区可修改/etc/fstab文件,在最后加入添加:/dev/sdb1 /data xfs defaults 0 0

格式说明:/dev/sdb1 代表哪个分区, /data是挂载目录, xfs是该分区的格式,defaults 是挂载时所要设定的参数(只读,读写,启用quota等),输入defaults包括的参数有(rw、dev、exec、auto、nouser、async) ,1是使用dump是否要记录,0是不要。 2是开机时检查的顺序,是boot系统文件就为1,其他文件系统都为2,如不要检查就为0

# 
# /etc/fstab
# Created by anaconda on Fri Sep  4 12:04:04 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cl-root     /                       xfs     defaults        0 0
UUID=86a7eaa3-61db-49cd-be3d-54b724f24878 /boot                   ext4    defaults        1 2
/dev/mapper/cl-home     /home                   xfs     defaults        0 0
/dev/mapper/cl-swap     swap                    swap    defaults        0 0
/dev/sdb1 /data                                 xfs    defaults        0 0

xfs格式是一种非常优秀的日志文件系统,它是SGI公司设计的。xfs被称为业界最先进的、最具可升级性的文件系统技术,xfs是一个64位文件系统,最大支持8EB减1字节的单个文件系统,实际部署时取决于宿主操作系统的最大块限制。对于一个32位Linux系统,文件和文件系统的大小会被限制在16TB
xfs在很多方面确实做的比ext4好,ext4受限制于磁盘结构和兼容问题,可扩展性和scalability确实不如xfs。具体详细的区别请自行了解,采用df -T 命令查看系统硬盘的格式

[root@kiccleaf ~]# df -T
Filesystem          Type      1K-blocks    Used  Available Use% Mounted on
devtmpfs            devtmpfs    3968364       0    3968364   0% /dev
tmpfs               tmpfs       3985404       0    3985404   0% /dev/shm
tmpfs               tmpfs       3985404    9176    3976228   1% /run
tmpfs               tmpfs       3985404       0    3985404   0% /sys/fs/cgroup
/dev/mapper/cl-root xfs        52403200 6583040   45820160  13% /
/dev/sdb1           xfs      1048062980 7340272 1040722708   1% /data
/dev/sda1           ext4         999320  202436     728072  22% /boot
/dev/mapper/cl-home xfs       986342856 6965148  979377708   1% /home
tmpfs               tmpfs        797080       0     797080   0% /run/user/0
Leave a Comment

Linux/FreeBSD 下tar加密压缩命令

加密压缩

tar -czvf - file | openssl des3 -salt -k password -out kiccleaf.tar.gz

解密解压

openssl des3 -d -k password -salt -in kiccleaf.tar.gz | tar zxvf -

file:可以是文件或是目录,多文件/目录空格隔开
password:需要设定的密码

需要注意事项:
在命令行直接输入命令进行加密操作,一般系统在用户的命令历史Linux【.bash_history】/FreeBSD下【.history】文件里面会记录了命令行也就知道了密码,所以如果系统记录了操作的命令行则需要清掉涉及的历史记录或清空,也可以在加密时候不要使用 -k 参数以及后面的密码串,等询问时候再进行输入,解压输入 密码串,这样就不会泄漏密串。如下操作:

加密码提示输入密串,需要输入两次
[root@kiccleaf ~]# tar -czvf - kiccleaf | openssl des3 -salt -out kiccleaf.tar.gz
test.sh
enter des-ede3-cbc encryption password:
Verifying - enter des-ede3-cbc encryption password:

直接解压不可以咯
[root@kiccleaf ~]# tar zxvf kiccleaf.tar.gz 

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now

解压提示输入密串
[root@kiccleaf ~]# openssl des3 -d -salt -in kiccleaf.tar.gz | tar zxvf -
enter des-ede3-cbc decryption password:
test.sh

Leave a Comment

CentOS8/FreeBSD12的Nginx+php-fpm.conf优化配置

首先优化配置会结合机器硬件的配置进行的,不能无限制无目的的进行,所以先了解自己的cpu,内存,硬盘等信息,然后进行系统的优化,再然后才到应用类的优化设置。

测试环境:CPU E3-1231 V3 四核八线程,内存32G

FreeBSD中Nginx.conf文件配置

user  www www;
worker_processes  auto;
worker_cpu_affinity auto;
worker_rlimit_nofile 51200;

#worker_rlimit_nofile 是nginx能打开文件的最大句柄数,我们需要把这个数字设大一点。
#linux系统的文件查看数限制查看是用 ulimit -n ,修改这个限制是用 ulimit -HSn 65535

events {
        worker_connections 51200;
}

#开启gzip减少带宽
http {

        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";
}

CentOS8中的Nginx.conf文件配置

user  www www;

worker_processes auto;
worker_cpu_affinity auto;
worker_rlimit_nofile 51200;
#worker_rlimit_nofile 是nginx能打开文件的最大句柄数,我们需要把这个数字设大一点。
#linux系统的文件查看数限制查看是用 ulimit -n ,修改这个限制是用 ulimit -HSn 65535
events
    {
        use epoll;
        worker_connections 51200;
        multi_accept off;
        accept_mutex off;
    }
http
    {
        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

events模块中use设置说明
use epoll
使用epoll的I/O 模型(值得注意的是如果你不知道Nginx该使用哪种轮询方法的话,它会选择一个最适合你操作系统的)
补充说明:与apache相类,nginx针对不同的操作系统,有不同的事件模型
A)标准事件模型
Select、poll属于标准事件模型,如果当前系统不存在更有效的方法,nginx会选择select或poll
B)高效事件模型
Kqueue:使用于FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 和 MacOS X.使用双处理器的MacOS X系统使用kqueue可能会造成内核崩溃。
Epoll:使用于Linux内核2.6版本及以后的系统。
/dev/poll:使用于Solaris 7 11/99+, HP/UX 11.22+ (eventport), IRIX 6.5.15+ 和 Tru64 UNIX 5.1A+。
Eventport:使用于Solaris 10. 为了防止出现内核崩溃的问题, 有必要安装安全补丁
查看linux版本号可以使用 cat /proc/version命令

worker_processes,工作进程数
1.默认:worker_processes: 1
这里直接设置为auto,根据需求自动调整

worker_cpu_affinity auto;
允许将工作进程自动绑定到可用的CPU

worker_connections,单个工作进程可以允许同时建立外部连接的数量,数字越大,能同时处理的连接越多
1.默认:worker_connections: 1024

worker_connections解析
1.connections不是随便设置的,而是与两个指标有重要关联,一是内存,二是操作系统级别的“进程最大可打开文件数”。
2.进程最大可打开文件数:进程最大可打开文件数受限于操作系统,可通过 ulimit -n 命令查询,以前是1024,现在是65535。(常规系统都配置成65535)

这些官方信息更全面,我这里只讲我优化配置的点,因为服务器需求不同,这些配置会做相应调整,不能盲目的认为这些值是固定的。

接下去说一下php-fpm.conf文件的配置

FreeBSD文件配置默认情况在:/usr/local/etc/php-fpm.d/www.conf

CentOS8文件配置默认情况在:/usr/local/php/etc/php-fpm.conf

#最大子进程数量,一般每个php-cgi所耗费的内存为20M左右
#如果这个值设置的比较小,那么等待的请求时间会出现502超时
#32G内存服务器可以设置1600,但实际应用中不会这样配置,而是根据自己需求进行设定
pm.max_children = 800

#启动时创建的子进程数,常规10~20之间就可以,20个的话是400M内存
pm.start_servers = 40

#为避免内存泄露,php-fpm有这么一个机制,
#当一个php-cgi进程处理的请求数达到这个配置后,则会自动重启该进程,
#所以在高并发中,经常导致502错误,解决方法就是把这个值设置大一些,
#减少进程重启次数,减少高并发情况下502错误。
pm.max_requests = 10240

#单个请求的超时中止时间,超时后会终止进程,nginx发现信号断了,
#就会给客户端返回502错误。和php.ini的max_execution_time配置不冲突,
#谁先达到时间谁先起作用。
request_terminate_timeout = 100

#保证空闲进程数最小值,如果空闲进程小于此值,则创建新的子进程
pm.min_spare_servers = 40

#保证空闲进程数最大值,如果空闲进程大于此值,此进行清理
pm.max_spare_servers = 80

#空闲进程超时时间10秒
pm.process_idle_timeout = 10s

#状态页,可以通过该状态页了解监控 php-fpm 的状态,status可以修改成自己的名称
#pm.status_path = /status
pm.status_path = /kiccleaf
    server {
        listen       80;
        server_name  localhost;
        #Nginx状态页,监控Nginx状态增加以下内容
        location /nginx_status {
                stub_status on;
                access_log off;
                #允许内网访问IP
                allow 192.168.1.8;
                allow 127.0.0.1;
                deny all;
        }
        #php-fpm监控页,增加以下内容
        location = /kiccleaf {
                include fastcgi_params;
                fastcgi_pass unix:/tmp/php-cgi.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
}

打开http://网址/nginx_status 显示:

Active connections: 2 
server accepts handled requests
 6 6 78 
Reading: 0 Writing: 1 Waiting: 1 

打开http://网址/kiccleaf 显示:

pool:                 www
process manager:      dynamic
start time:           31/Aug/2020:15:59:56 +0800
start since:          12
accepted conn:        14
listen queue:         0
max listen queue:     0
listen queue len:     0
idle processes:       39
active processes:     1
total processes:      40
max active processes: 1
max children reached: 0
slow requests:        0
Leave a Comment

CentOS8系统时间同步解决方法

装了新的CentOS8,才发现有很多原来使用的工具在新版本中已经被其他工具替代,今天把常规的系统时间同步问题解决一下,CentOS7及以下的都是采用NTP来解决,《linux中rc.local设置开机自启没有生效解决方案》。

找了一下方法,原来是使用了另一个工具替代了,记录一下先

[root@kiccleaf home]# yum install -y chrony

Installed:
  chrony-3.5-1.el8.x86_64                                                                                            timedatex-0.5-3.el8.x86_64                                                                                           

Complete!
安装好工具,先启动
[root@kiccleaf home]# systemctl start chronyd
设为系统自动启动
[root@kiccleaf home]# systemctl enable chronyd
编辑一下配置文件
[root@kiccleaf home]# vim /etc/chrony.conf

/etc/chrony.conf配置文件内容:

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#pool 2.centos.pool.ntp.org iburst (这一行注释掉,增加以下两行)
server ntp.aliyun.com iburst
server cn.ntp.org.cn iburst
重新加载配置
[root@kiccleaf home]# systemctl restart chronyd.service
[root@kiccleaf home]# chronyc sources -v
210 Number of sources = 2

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 203.107.6.88                  2   6     7     2   -188us[+6871us] +/-   24ms
^- 61.177.189.190                3   6    17    19   +663us[ +663us] +/-   97ms

[root@kiccleaf home]# date
Sat Aug 29 16:26:08 CST 2020
1 Comment

CentOS8下安装Go环境安装

Go 语言支持以下系统:

  • Linux
  • FreeBSD
  • Mac OS X(也称为 Darwin)
  • Window

先打开网址:https://golang.google.cn/dl/ 下载需要的版本,Win,Mac,Linux自行选择自己的环境 ,这里只介绍Linux环境的配置。

[root@kiccleaf ~]# wget https://golang.google.cn/dl/go1.15.linux-amd64.tar.gz
[root@kiccleaf ~]# tar zxvf go1.15.linux-amd64.tar.gz
[root@kiccleaf ~]# mv go /usr/local/
[root@kiccleaf ~]# vim /etc/profile
在文件底部增加:
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
保存退出后
[root@kiccleaf ~]# source /etc/profile
[root@kiccleaf ~]# go version
go version go1.15 linux/amd64
显示go环境安装成功,是不是有点太简单了?
来吧,第一个go程序
[root@kiccleaf ~]# vim helloword.go

helloword.go内容:

package main
import "fmt"
func main(){
   fmt.Printf("Hello Word!\n");
}
[root@kiccleaf ~]# go build helloword.go 
[root@kiccleaf ~]# ./helloword 
Hello Word!
[root@kiccleaf ~]# du -sh helloword
2.0M	helloword
编译好的文件还是有点大的,简单的一个Hello Word!需要2M的大小。
Leave a Comment

CentOS8安装PHP8

最新系统上来了这大半年都没有时间安装用用,php-8.0.0beta2 也发布出来了,先记录一下,CentOS8安装选择最小安装(跟原来安装差不多没变化),所以安装速度很快,因为是最小安装所以有些工具没有,能少则少的原则

简单说一下yum源修改

先安装wget工具:

yum install -y wget
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo

或者用

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
yum makecache 生成缓存

系统缺少命令ifconfig,netstat,whois等命令需要安装net-tools.x86_64,另外习惯使用vim编辑器,所以每次都会安装,常用的screen也是要安装的,但在CentOS8系统下直接yum install screen是安装失败的

[root@kiccleaf ~]# yum install screen
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Last metadata expiration check: 0:01:32 ago on Tue 25 Aug 2020 02:16:39 PM CST.
No match for argument: screen
Error: Unable to find a match: screen
办法总是有的,先安装epel-release
[root@kiccleaf ~]# yum install -y epel-release
Installed:
  epel-release-8-8.el8.noarch                                                                                                                                                                                                               

Complete!
[root@kiccleaf ~]# yum install -y screen
Installed:
  screen-4.6.2-10.el8.x86_64                                                                                                                                                                                                                

Complete!
[root@kiccleaf ~]# 
安装成功了!测试一下
[root@kiccleaf ~]# screen -S kiccleaf
新的窗体里面了
[root@kiccleaf ~]#
Ctrl+ad  临时退出窗体
[detached from 35676.kiccleaf]

重新进入刚才的窗体
[root@kiccleaf ~]# screen -r kiccleaf
退出窗体
[root@kiccleaf ~]# exit
exit
[screen is terminating]
到此完美使用screen工具了。
接下去安装vim和网络命令
[root@kiccleaf ~]# yum install -y net-tools.x86_64 vim 
来看一下系统的版本吧
[root@kiccleaf ~]# cat /etc/redhat-release 
CentOS Linux release 8.2.2004 (Core) 
[root@kiccleaf ~]# 

先下载PHP8源码包,下载网址:https://downloads.php.net/~pollita/

[root@kiccleaf ]# wget https://downloads.php.net/~pollita/php-8.0.0beta2.tar.gz
[root@kiccleaf ]# tar zxvf php-8.0.0beta2.tar.gz
[root@kiccleaf ]# cd php-8.0.0beta2
根据自己的需求进行配置安装相应的扩展
[root@kiccleaf php-8.0.0beta2]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-fpm --enable-static --enable-sockets --with-zip --enable-calendar --enable-bcmath --enable-mbstring --with-zlib --with-iconv=/usr/local/libiconv --enable-gd --enable-mbstring --with-curl --with-freetype --disable-ipv6 --disable-debug --with-openssl --enable-intl --enable-opcache

[root@kiccleaf php-8.0.0beta2]# make 
[root@kiccleaf php-8.0.0beta2]# make install

在执行中可能会遇到一些问题,这里简单说明一下:

1. configure: error: iconv does not support errno

[root@kiccleaf ]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
[root@kiccleaf ]# tar zxvf libiconv-1.15.tar.gz
[root@kiccleaf libiconv-1.15]#  cd libiconv-1.15
[root@kiccleaf libiconv-1.15]# ./configure --prefix=/usr/local/libiconv
[root@kiccleaf libiconv-1.15]#  make 
[root@kiccleaf libiconv-1.15]#  make install
安装好PHP8后配置进行启动
[root@kiccleaf php-8.0.0beta2]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@kiccleaf php-8.0.0beta2]# chmod a+x /etc/init.d/php-fpm
[root@kiccleaf php-8.0.0beta2]# service php-fpm start
[root@kiccleaf php-8.0.0beta2]# php -v
PHP 8.0.0beta2 (cli) (built: Aug 24 2020 13:47:39) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
Leave a Comment

CentOS7/8和FreeBSD-12修改主机名字

默认情况下Linux主机的名称是localhost如:

[root@localhost ~]# hostname
localhost.localdomain

修改如下:

 [root@localhost ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

把中间的localhost.localdomain修改成自己的名称:kiccleaf

127.0.0.1 localhost kiccleaf localhost4 localhost4.localdomain4
::1 localhost kiccleaf localhost6 localhost6.localdomain6

[root@localhost ~]# vim /etc/hostname
把localhost名称修改成自己的名称:kiccleaf

重启一下系统

[root@localhost ~]# reboot
Connecting to *.*.*.*:22...
Connection established.
To escape to local shell, press Ctrl+Alt+].

          Welcome to CentOS 8
  _     _            _                 ___
 | |   (_)          | |               / __)
 | |  _ _  ____ ____| | _____ _____ _| |__
 | |_/ ) |/ ___) ___) || ___ (____ (_   __)
 |  _ (| ( (__( (___| || ____/ ___ | | |
 |_| \_)_|\____)____)\_)_____)_____| |_|

Last login: Tue Aug 25 11:57:55 2020 from *.*.*.*
[root@kiccleaf ~]# hostname
kiccleaf

FreeBSD修改名称比较简单

root@localhost:~ # vim /etc/rc.conf
hostname="kiccleaf"
root@localhost:~ # reboot

#重启后连接显示
Connecting to *.*.*.*:22...
Connection established.
To escape to local shell, press Ctrl+Alt+].

Last login: Mon Aug 24 18:06:00 2020 from *.*.*.*
FreeBSD 12.1-RELEASE r354233 GENERIC 
  
      Welcome to FreeBSD!
   _     _            _                 ___
  | |   (_)          | |               / __)
  | |  _ _  ____ ____| | _____ _____ _| |__
  | |_/ ) |/ ___) ___) || ___ (____ (_   __)
  |  _ (| ( (__( (___| || ____/ ___ | | |
  |_| \_)_|\____)____)\_)_____)_____| |_|

root@kiccleaf:~ # uname -a
FreeBSD kiccleaf 12.1-RELEASE FreeBSD 12.1-RELEASE r354233 GENERIC  amd64

Leave a Comment

Centos7安装php7.4.9+redis扩展

本文只讲php的编译及Redis扩展的安装,其他nginx的安装什么都相同方式无非就是配置需要修改一下。

php7.4.9安装包下载:https://www.php.net/downloads.php#v7.4.9

我下载了:https://www.php.net/distributions/php-7.4.9.tar.bz2

解压 tar jzvf php-7.4.9.tar.bz2,并打开php-7.4.9目录,需要安装的扩展自行增减,然后进行编译:

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-fpm-user=www --with-fpm-group=www --with-curl --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-zip --disable-fileinfo
进行make时会提示错误:
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1

需要:make ZEND_EXTRA_LIBS=’-liconv’ 进行编译操作

等编译后make install安装完成!

把php-fpm做成系统启动,先复制 php-7.4.9目录下./sapi/fpm/init.d.php-fpm至/etc/init.d/目录下

cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

复制完,执行service php-fpm start 会提示错误:env: /etc/init.d/php-fpm: Permission denied,因为 init.d目录下需要给相应的权限才可执行:

chmod a+x /etc/init.d/php-fpm

执行service php-fpm start 提示:Starting php-fpm done 说明启动成功!

然后第二步安装Redis扩展,下载地址:https://pecl.php.net/package/redis 选择自己适合的扩展,我选择了最新的Redis5.3.1版本

wget https://pecl.php.net/get/redis-5.3.1.tgz
tar zxvf redis-5.3.1.tgz
cd redis-5.3.1
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install

–with-php-config=/usr/local/php/bin/php-config 根据自己安装的位置找到php-config

编辑php.ini文件

vim /usr/local/php/etc/php.ini

找到extension区域,增加:extension=redis.so,然后保存退出

重启php进程 service php-fpm restart

查看php是否已经安装了redis模块:

[root@localhost php-7.4.9]# php -m
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
filter
gettext
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
redis
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvsem
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
zlib

[Zend Modules]

这里特别注意:–with-config-file-path=/usr/local/php/etc编译PHP是指定目录 php.ini文件,如果非此目录的php.ini文件增加扩展,重启是不会加载扩展。新手要特别注意!!!

写一个php文件:phpinfo.php

<?php
  phpinfo();
?>

找到此配置信息项:

Configuration File (php.ini) Path/usr/local/php/etc
Loaded Configuration File/usr/local/php/etc/php.ini

转载请注明出处!

Leave a Comment

个性化Linux/FreeBSD字符界面,登录输出显示信息

很多年以前写过Linux登录时输出个性信息,被各大平台及个人博客转载,遗憾的是他们从来没有写上原文从哪里转载过来,我个人支持大家相互学习和转载,但请转载注明一下出处可以吗?怎么说也是我的小小劳动成果。

Linux及FreeBSD下编辑/etc/motd

vi /etc/motd

         Welcome to Linux
  _     _            _                 ___
 | |   (_)          | |               / __)
 | |  _ _  ____ ____| | _____ _____ _| |__
 | |_/ ) |/ ___) ___) || ___ (____ (_   __)
 |  _ (| ( (__( (___| || ____/ ___ | | |
 |_| \_)_|\____)____)\_)_____)_____| |_|

FreeBSD就添加相应的提示信息(清空原FreeBSD下/etc/motd文件自带的信息,会比较多,全清掉即可)

FreeBSD 12.1-RELEASE r354233 GENERIC
  
          Welcome to FreeBSD!
   _     _            _                 ___
  | |   (_)          | |               / __)
  | |  _ _  ____ ____| | _____ _____ _| |__
  | |_/ ) |/ ___) ___) || ___ (____ (_   __)
  |  _ (| ( (__( (___| || ____/ ___ | | |
  |_| \_)_|\____)____)\_)_____)_____| |_|

欢迎转载,请注明出处,谢谢!

原来《个性化Linux字符界面,登录输出显示信息》中有颜色更漂亮,但是针对使用WinSCP软件SFTP登录时会有错误提示:WinSCP登陆服务器提示收到了太大的SFTP包 支持的最大包大小1024000B,总有得失,看个人喜欢。

Leave a Comment