对CentOS使用由来已久,只是没有系统的梳理过,现终于有时间来整理一些使用经验,以作备忘。本次是以(CentOS Linux release 8.2.2004)为原型,记录如下:
设置系统名称
[root@i ~] hostnamectl set-hostname i
安装 epel 源和 remi 源
Repository Path : /etc/yum.repos.d
rpm --import "https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-8" dnf -y install "https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm" dnf -y install "https://rpms.remirepo.net/enterprise/remi-release-8.rpm" dnf -y install yum-utils # 安装yum-utils包
移除源
dnf repolist # Search the for the package name installed by executing the following rpm command: ls /etc/yum.repos.d rpm -qf /etc/yum.repos.d/epel.repo # Remove the packages and repos. dnf remove epel-release # Generally it is a good practice to run the following command to clear any cached data regarding the installed packages as this can take up a lot of disk space. dnf clean all
创建:/etc/yum.repos.d/nginx.repo 并粘贴如下内容
[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true
nginx分为稳定和主线分支两个分支,默认为稳定分支,可以根据需要切换为主线分支 yum-config-manager –enable nginx-mainline
yum-config-manager --enable nginx-mainline dnf -y install nginx # 安装 nginx rpm -q nginx # 显示 nginx 版本信息
配置网站
cd /etc/nginx/conf.d
vim www.example.com
server { server_name www.example.com; root /usr/share/nginx/html/example; location / { # look for index.php/index.html/index.htm as "index file" index index.html index.htm index.php; # this is specifically for wordpress # makes it possible to have url rewrites try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { # if the file is not there show a error : mynonexistingpage.php -> 404 try_files $uri =404; # pass to the php-fpm server # fastcgi_pass 127.0.0.1:9000; # fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; # also for fastcgi try index.php fastcgi_pass unix:/run/php-fpm/www.sock; # also for fastcgi try index.php fastcgi_index index.php; # some tweaking fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # fastcgi_param SCRIPT_NAME $fastcgi_script_name; include fastcgi_params; # fastcgi_buffer_size 128k; # fastcgi_buffers 256 16k; # fastcgi_busy_buffers_size 256k; # fastcgi_temp_file_write_size 256k; } listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot # default error pages # note that wp already catches most error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } server { if ($host = www.example.com) { return 301 https://$host$request_uri; } # managed by Certbot server_name www.example.com; listen 80; return 404; # managed by Certbot }
# httping.x86_64 : Ping alike tool for http requests dnf -y install httping # 查看所有已启动的服务 systemctl list-units --type=service
MySQL初始化(官方文档)
MySQL 安装过程涉及初始化数据目录,包括mysql系统架构中定义 MySQL 帐户的授权表 。在所有平台上,MySQL 发行版都包含 mysql_secure_installation,这是一个命令行实用程序,可自动执行大部分保护 MySQL 安装的过程。默认情况下,对于使用mysqld –initialize手动执行的数据目录初始化 , mysqld生成初始随机密码,将其标记为过期,并将其写入服务器错误日志(/var/log/mysqld.log),随机密码格式如下:
[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: b;qw=shVl1G4 # 随机密码为: b;qw=shVl1G4 # 选择一个新密码来替换随机密码: mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root-password';
设置二进制日志格式不会激活服务器的二进制日志。该设置仅在服务器上启用二进制日志记录时生效,即log_bin系统变量设置为ON. 从 MySQL 8.0 开始,默认情况下启用二进制日志记录,只有 在启动时指定–skip-log-bin or –disable-log-bin选项时才会禁用 。
mysql> show variables like "%log_bin%"; +---------------------------------+-----------------------------+ | Variable_name | Value | +---------------------------------+-----------------------------+ | log_bin | ON | | log_bin_basename | /var/lib/mysql/binlog | | log_bin_index | /var/lib/mysql/binlog.index | | log_bin_trust_function_creators | OFF | | log_bin_use_v1_row_events | OFF | | sql_log_bin | ON | +---------------------------------+-----------------------------+ 6 rows in set (0.00 sec) # 该sql_log_bin变量控制是否为当前会话启用日志记录到二进制日志(假设二进制日志本身已启用)。默认值为ON。要为当前会话禁用或启用二进制日志记录,请将会话sql_log_bin变量设置为 OFF或ON。 # https://dev.mysql.com/doc/refman/8.0/en/set-sql-log-bin.html mysql> show variables like 'binlog_format'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | binlog_format | ROW | +---------------+-------+ 1 row in set (0.00 sec) mysql> show binary logs; +---------------+-----------+-----------+ | Log_name | File_size | Encrypted | +---------------+-----------+-----------+ | binlog.000001 | 179 | No | | binlog.000002 | 1147 | No | +---------------+-----------+-----------+ 2 rows in set (0.00 sec)
更改后
mysql> SET GLOBAL binlog_format = 'STATEMENT'; Query OK, 0 rows affected (0.00 sec) mysql> SET GLOBAL binlog_format = 'ROW'; Query OK, 0 rows affected (0.00 sec) mysql> SET GLOBAL binlog_format = 'MIXED'; Query OK, 0 rows affected (0.00 sec)
该PURGE BINARY LOGS语句删除指定索引文件名或日期之前在日志索引文件中列出的所有二进制日志文件。 BINARY和MASTER是同义词。删除的日志文件也会从索引文件中记录的列表中删除,以便给定的日志文件成为列表中的第一个。
PURGE BINARY LOGS TO 'mysql-bin.010'; PURGE BINARY LOGS BEFORE '2019-04-02 22:46:26';
MySQL的备份还原
https://linuxize.com/post/how-to-back-up-and-restore-mysql-databases-with-mysqldump/
更换域名的迁移工作
# 首先,要到你网站根目录下修改 wp-config.php 的数据库配置文件 select option_value from wp_options where option_name in('siteurl', 'home'); update wp_options set option_value = replace(option_value, 'https://www.isusee.com', 'https://www.abc.com') where option_name = 'home' or option_name = 'siteurl'; select guid from wp_posts; update wp_posts set guid = replace(guid, 'https://www.isusee.com', 'https://www.abc.com'); update wp_posts set post_content = replace(post_content, 'https://www.isusee.com', 'https://www.abc.com'); select meta_value from wp_postmeta where meta_value like 'https://%'; update wp_postmeta set meta_value = replace(meta_value, 'https://www.isusee.com', 'https://www.abc.com'); select comment_author_url from wp_comments where comment_author_url like 'https://www.isusee.com%'; update wp_comments set comment_author_url = replace(comment_author_url, 'https://www.isusee.com', 'https://www.abc.com') where comment_author_url = 'https://www.isusee.com'; select user_url from wp_users where user_url like 'https://www.isusee.com%'; update wp_users set user_url = replace(user_url , 'https://www.isusee.com', 'https://www.abc.com') where user_url = 'https://www.isusee.com';