跳至主要內容

centos笔记

Moments大约 5 分钟

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

PolicyTests Performed
0 or LOWLength
1 or MEDIUMLength; numeric, lowercase/uppercase, and special characters
2 or STRONGLength; 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支持的信号列表

信号取值默认动作含义(发出信号的原因)
SIGHUP1Term终端的挂断或进程死亡
SIGINT2Term来自键盘的中断信号
SIGQUIT3Core来自键盘的离开信号
SIGILL4Core非法指令
SIGABRT6Core来自abort的异常信号
SIGFPE8Core浮点例外
SIGKILL9Term杀死
SIGSEGV11Core段非法错误(内存引用无效)
SIGPIPE13Term管道损坏:向一个没有读进程的管道写数据
SIGALRM14Term来自alarm的计时器到时信号
SIGTERM15Term终止
SIGUSR130,10,16Term用户自定义信号1
SIGUSR231,12,17Term用户自定义信号2
SIGCHLD20,17,18Ign子进程停止或终止
SIGCONT19,18,25Cont如果停止,继续执行
SIGSTOP17,19,23Stop非来自终端的停止信号
SIGTSTP18,20,24Stop来自终端的停止信号
SIGTTIN21,21,26Stop后台进程读终端
SIGTTOU22,22,27Stop后台进程写终端
SIGBUS10,7,10Core总线错误(内存访问错误)
SIGPOLLTermPollable事件发生(Sys V),与SIGIO同义
SIGPROF27,27,29Term统计分布图用计时器到时
SIGSYS12,-,12Core非法系统调用(SVr4)
SIGTRAP5Core跟踪/断点自陷
SIGURG16,23,21Ignsocket紧急信号(4.2BSD)
SIGVTALRM26,26,28Term虚拟计时器到时(4.2BSD)
SIGXCPU24,24,30Core超过CPU时限(4.2BSD)
SIGXFSZ25,25,31Core超过文件长度限制(4.2BSD)
SIGIOT6CoreIOT自陷,与SIGABRT同义
SIGEMT7,-,7Term
SIGSTKFLT-,16,-Term协处理器堆栈错误(不使用)
SIGIO23,29,22Term描述符上可以进行I/O操作
SIGCLD-,-,18Ign与SIGCHLD同义
SIGPWR29,30,19Term电力故障(System V)
SIGINFO29,-,-与SIGPWR同义
SIGLOST-,-,-Term文件锁丢失
SIGWINCH28,28,20Ign窗口大小改变(4.3BSD, Sun)
SIGUNUSED-,31,-Term未使用信号(will be SIGSYS)
上次编辑于:
贡献者: Moments