centos笔记


运行centos8容器

docker pull registry.cn-shenzhen.aliyuncs.com/pythonschool/pythonschool:centos
docker tag d2f4318c4278 pythonschool:centos8
docker run -dit -p 800:80 -p 8443:443 -p 1022:22 -p 3306:3306 -e MYSQL\_ROOT\_PASSWORD=123456 --privileged=true --name=centos8 pythonschool:centos8 /usr/sbin/init
docker exec -it centos8 /bin/bash

Waiting for process with pid 53 to finish.

ps uax | grep 53
kill -9 53

更新yum源为阿里云

// 安装wget
yum install wget -y
// 备份/etc/yum.repos.d/CentOS-Linux-Base.repo
mv /etc/yum.repos.d/CentOS-Linux-BaseOS.repo /etc/yum.repos.d/CentOS-Linux-BaseOS.repo.backup
// 下载aliyun的yum源配置文件
wget -O /etc/yum.repos.d/CentOS-Linux-BaseOS.repo http://mirrors.aliyun.com/repo/Centos-8.repo
// 运行yum makecache生成缓存
yum makecache
// 更新yum
yum update -y

SSH免密码登录

// 安装vim
yum install vim -y

vim /etc/ssh/sshd_config

#Port 22
PermitRootLogin yes
// centos8修改密码
yum install -y passwd
passwd root [root]
// 安装ssh工具
yum install -y openssl openssh-server openssh-clients.x86_64
systemctl status sshd
systemctl restart sshd
// 生成密钥
ssh-keygen -t rsa -C "centos8"
// 将本地公钥上传到服务器的用户目录
scp -P 1022 ~/.ssh/id_rsa.pub root@localhost:~ 
// 将本地公钥添加到服务器已认证密钥中
cat ~/id_rsa.pub >> .ssh/authorized_keys

安装php73

// 安装EPEL YUM源
yum install epel-release yum-utils -y
// 会对系统类型安装相应的包
yum install http://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
// 查看yum的php信息
yum info php
// 安装php73
yum install php73-php-fpm php73-php-xml php73-php-cli php73-php-gd php73-php-json php73-php-mysql php73-php-sqlite3 php73-php-bz2 php73-php-mbstring php73-php-zip -y
// 开启php服务
systemctl enable php73-php-fpm.service
systemctl restart php73-php-fpm.service
// 查找文件名包括php73的文件名
find / -name php73*

安装git

// 安装git
yum install git -y

安装composer

// composer镜像下载
wget https://mirrors.aliyun.com/composer/composer.phar
// 添加软链接
yum install which -y
which php73
link /usr/bin/php73 /usr/local/bin/php
# 测试composer是否安装成功
php composer.phar about
# 加入本地全局命令
mv composer.phar /usr/local/bin/composer
# 增加本地composer执行权限
chmod +x /usr/local/bin/composer

安装nginx

vim /etc/yum.repos.d/nginx.repo

# nginx.repo

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
// 查看yum的nginx信息
yum info nginx
// 安装nginx
yum install nginx -y
// 启动nginx
systemctl enable nginx
systemctl restart nginx
// 查看网站路径
cat /etc/nginx/conf.d/default.conf | egrep '^[ ]+root'

安装redis

// 安装redis
yum -y install redis 
// 启动redis
systemctl enable redis
systemctl start redis

安装mysql8

// mysql8源地址:https://dev.mysql.com/downloads/file/?id=489467
wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
// 安装mysql8数据源
yum install mysql80-community-release-el8-1.noarch.rpm -y
// 查看数据源
yum repolist enabled | grep "mysql.*-community.*"
// 禁用CentOS8自带mysql模块,否则会提示被模块过滤掉
yum module disable -y mysql
// 安装mysql
yum install mysql-community-server -y
// 开启mysql
service mysqld start
/bin/systemctl start mysqld.service
// 查看mysql的状态
service mysqld status
// 关闭mysql
service mysqld stop
/bin/systemctl stop mysqld.service

mysql8修改密码

// 显示mysql的随机密码
grep 'temporary password' /var/log/mysqld.log
// 登录mysql
mysql -u root -p
// 先修改成"Moments_2021",满足它的策略
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Moments_2021';
// 查看密码策略
SHOW VARIABLES LIKE 'validate_password%';
// 修改密码长度:
set global validate_password.length=6;
// 修改密码等级:
set global validate_password.policy=0;
// 设置成自己想要的密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

validate_password_policy

Policy Tests Performed
0 or LOW Length
1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters
2 or STRONG Length; numeric, lowercase/uppercase, and special characters; dictionary file

配置远程登录用户

// 删除用户
drop user 'Moments'@'%';
// 创建用户并设置密码
create user 'Moments'@'%' identified by '123456';
// 权限配置
grant all privileges on *.* to 'Moments'@'%' with grant option;
// 权限配置项立即生效
flush privileges;

MySQL said: Can't connect to MySQL server on 'xxxx' (60)

可能是阿里云的3306端口没有开放

MySQL said: Authentication plugin 'caching_sha2_password' cannot be loaded

// 更改加密方式为mysql_native_password
alter user 'Moments'@'%' identified with mysql_native_password by '123456';
// 权限配置项立即生效
flush privileges;

web服务器配置

yum install -y sudo

Linux支持的信号列表

信号 取值 默认动作 含义(发出信号的原因)
SIGHUP 1 Term 终端的挂断或进程死亡
SIGINT 2 Term 来自键盘的中断信号
SIGQUIT 3 Core 来自键盘的离开信号
SIGILL 4 Core 非法指令
SIGABRT 6 Core 来自abort的异常信号
SIGFPE 8 Core 浮点例外
SIGKILL 9 Term 杀死
SIGSEGV 11 Core 段非法错误(内存引用无效)
SIGPIPE 13 Term 管道损坏:向一个没有读进程的管道写数据
SIGALRM 14 Term 来自alarm的计时器到时信号
SIGTERM 15 Term 终止
SIGUSR1 30,10,16 Term 用户自定义信号1
SIGUSR2 31,12,17 Term 用户自定义信号2
SIGCHLD 20,17,18 Ign 子进程停止或终止
SIGCONT 19,18,25 Cont 如果停止,继续执行
SIGSTOP 17,19,23 Stop 非来自终端的停止信号
SIGTSTP 18,20,24 Stop 来自终端的停止信号
SIGTTIN 21,21,26 Stop 后台进程读终端
SIGTTOU 22,22,27 Stop 后台进程写终端
SIGBUS 10,7,10 Core 总线错误(内存访问错误)
SIGPOLL Term Pollable事件发生(Sys V),与SIGIO同义
SIGPROF 27,27,29 Term 统计分布图用计时器到时
SIGSYS 12,-,12 Core 非法系统调用(SVr4)
SIGTRAP 5 Core 跟踪/断点自陷
SIGURG 16,23,21 Ign socket紧急信号(4.2BSD)
SIGVTALRM 26,26,28 Term 虚拟计时器到时(4.2BSD)
SIGXCPU 24,24,30 Core 超过CPU时限(4.2BSD)
SIGXFSZ 25,25,31 Core 超过文件长度限制(4.2BSD)
SIGIOT 6 Core IOT自陷,与SIGABRT同义
SIGEMT 7,-,7 Term
SIGSTKFLT -,16,- Term 协处理器堆栈错误(不使用)
SIGIO 23,29,22 Term 描述符上可以进行I/O操作
SIGCLD -,-,18 Ign 与SIGCHLD同义
SIGPWR 29,30,19 Term 电力故障(System V)
SIGINFO 29,-,- 与SIGPWR同义
SIGLOST -,-,- Term 文件锁丢失
SIGWINCH 28,28,20 Ign 窗口大小改变(4.3BSD, Sun)
SIGUNUSED -,31,- Term 未使用信号(will be SIGSYS)