CentOS7-swap

调整Swap分区大小

查看磁盘使用情况

1
df -h

添加swap文件并设置其大小为2G

1
2
3
4
5
6
# if 表示infile
# of 表示outfile
# bs=1MB 代表增加的模块大小
# count=2048 代表2048个模块,也就是2G空间,
# 将目的文件设置为swap分区文件
dd if=/dev/zero of=/tmp/swap bs=1MB count=2048

使用mkswap命令创建swap空间

1
mkswap /tmp/swap

启用新的swap

1
swapon /tmp/swap

查看swap是否生效

1
free -h

永久生效该分区,需要修改 /etc/fstab 文件,在文件最后增加以下内容:

1
/tmp/swap swap swap defaults 0 0

清除不再需要的swap分区

1
swapoff /tmp/swap

CentOS7-显卡

安装所需要的驱动

从NVIDIA官网上下载所需要的驱动文件(.run)。 https://www.nvidia.cn/Download/index.aspx?lang=cn

具体的选择是:Quadro Series -> K4000 -> Linux 64bit -> English(US)。

安装依赖关系

三个依赖:gcc,kernel-devel,dkms。要注意kernel-devel要与当前内核版本一致,检查方式如下:

1
2
uname -r # 检查当前内核版本
rpm -aq | grep kernel-devel # 检查安装的kernel-devel版本

我的检查结果是源码有多个版本共存,但后面安装过程正常,应该没什么问题。

屏蔽系统的nouveau

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# <方法一> 修改/lib下的dist-blacklist.conf文件:
$ sudo vi /lib/modprobe.d/dist-blacklist.conf

#把"nvidiafb"注释掉:

# blacklist nvidiafb

#添加语句:

blacklist nouveau
options nouveau modeset=0

# 重新建立initramfs image文件
$ sudo mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak

$ sudo dracut /boot/initramfs-$(uname -r).img $(uname -r)

# 重启
$ reboot

安装驱动

先修改.run文件的权限为可执行

$ chmod +x NVIDIA-Linux-x86_64-xxxxxx.run

然后执行!

$ sudo ./NVIDIA-Linux-x86_64-xxxxxx.run

在这过程中遇到的选择:
1: “XXXXXX” 大体意思是现在没有完全退出X Windows

A:退出驱动安装,确认系统完全退出图形界面。比如:

$ init 5 # 进入图形界面

$ systemctl set-default multi-user.target # 准备进入文本模式

$ reboot # 重启后自动进入文本模式,之后再重新run

2:Install NVIDIA‘s 32-bit compatibility libraries?

A:选择NO继续。

3:Would you like to run the nvidia-xconfigutility to automatically update your x configuration so that the NVIDIA x driver will be used when you restart x? Any pre-existing x confile will be backed up.

A:选择YES继续。

安装完成!

CentOS7 更新 make

安装过程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 官方地址
https://ftp.gnu.org/gnu/make/

# 解压
tar -zxvf make-4.2.1.tar.gz

# 安装
cd make-4.2.1
# 建立编译目录
mkdir build
cd build
# 执行
../configure --prefix=/usr

# 执行完,这里需要编译,会生成build.sh文件,然后执行这个文件
sh build.sh
# 然后安装
make install

# 然后就安装完成了,查看版本
make -v
GNU Make 4.2.1

安装bison

1
yum install -y bison

CentOS7 更新 gcc

前置条件:建议更新make

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

yum -y install wget bzip2 gcc gcc-c++ glibc-headers

# 下载gcc包到自己的目录,-P后面的下载目录自己指定
# 下载这个文件可以直接去官网下,反而更快一些,
# 下载地址:https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc(自己选择版本)
wget -c -P /opt/software/ https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-8.2.0/gcc-8.2.0.tar.gz

# 解压
cd /opt/software/
tar -zxvf gcc-8.2.0.tar.gz
# 解压要好久,可以喝杯茶放松一下

cd gcc-8.2.0
./contrib/download_prerequisites #下载gmp mpfr mpc等供编译需求的依赖项

# 不能在source目录下configure,必须在上一层的目录下
mkdir build

cd bulid

../configure --prefix=/usr/local/gcc-8.2.0 --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib

# 启用cpu 12个线程进行编译
make -j12
# 结果:

# 接下来安装它
make install

# 写配置文件
echo -e '\nexport PATH=/usr/local/gcc-8.2.0/bin:$PATH\n' >> /etc/profile.d/gcc.sh && source /etc/profile.d/gcc.sh

# 导出头文件
ln -sv /usr/local/gcc-9.2.0/include/ /usr/include/gcc

#配置生效
ldconfig -v
# 结果:

# 导出验证
ldconfig -p |grep gcc
# 结果:

# 查看版本
gcc -v

CentOS7 更新 glibc

前置条件更新gcc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
官网下载Glibc2.28,官网地址:http://ftp.gnu.org/gnu/glibc/(选择你想要的版本)

# 完整步骤:
tar -xf glibc-2.28.tar.gz
cd glibc-2.28
mkdir build
cd build

../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin

make -j12
make install # 这一步的2个问题可以忽略

ls -l /lib64/libc.so.6

# 最后来看看我们的结果吧
strings /lib64/libc.so.6 | grep GLIBC

# 编译glibc会出现中文不支持的情况
make localedata/install-locales # 用来处理安装glibc后中文变乱码的现象,几乎所有教程没有,这就"安装失败"了

# 如果出现找不到就自己手动link一下
cd /usr/local/lib64
cp libstdc++.so.6.0.22 /usr/lib64/
cd /usr/lib64/
mv libstdc++.so.6 libstdc++.so.6.OLD
ln -sf libstdc++.so.6.0.22 libstdc++.so.6

Redis安装

Centos7安装Redis

安装gcc依赖

由于 redis 是用 C 语言开发,安装之前必先确认是否安装 gcc 环境(gcc -v),如果没有安装,执行以下命令进行安装

1
yum install -y gcc

安装

1
2
3
4
5
6
7
8
9
10
wget http://download.redis.io/releases/redis-5.0.3.tar.gz

tar -zxvf redis-5.0.3.tar.gz

#cd切换到redis解压目录下,执行编译
cd redis-5.0.3
make

#安装并指定安装目录
make install PREFIX=/usr/local/redis

启动服务

5.1前台启动

1
2
3
cd /usr/local/redis/bin/

./redis-server

5.2后台启动

从 redis 的源码目录中复制 redis.conf 到 redis 的安装目录

1
cp /usr/local/redis-5.0.3/redis.conf /usr/local/redis/bin/

修改 redis.conf 文件,把 daemonize no 改为 daemonize yes

1
vi redis.conf

后台启动

1
./redis-server redis.conf

设置开机启动

添加开机启动服务

1
vi /etc/systemd/system/redis.service

复制粘贴以下内容:

1
2
3
4
5
6
7
8
9
10
11
[Unit]
Description=redis-server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

复制代码
注意:ExecStart配置成自己的路径

设置开机启动

1
2
3
systemctl daemon-reload
systemctl start redis.service
systemctl enable redis.service

创建 redis 命令软链接

1
ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis

测试 redis

服务操作命令

1
2
3
4
5
6
systemctl start redis.service   #启动redis服务
systemctl stop redis.service #停止redis服务
systemctl restart redis.service #重新启动服务
systemctl status redis.service #查看服务当前状态
systemctl enable redis.service #设置开机自启动
systemctl disable redis.service #停止开机自启动

MySQL主从同步

CentOS7 安装MySQL

下载rpm并安装

1
2
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm

使用yum命令即可完成安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 安装
yum install mysql-server

# 启动msyql:
systemctl start mysqld

# 获取安装时的临时密码(在第一次登录时就是用这个密码):
grep 'temporary password' /var/log/mysqld.log

# 登录
mysql -u root -p

# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

#刷新
flush privileges;

七、其他配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

# 设置安全选项:
mysql_secure_installation

# 关闭MySQL
systemctl stop mysqld

# 重启MySQL
systemctl restart mysqld

# 查看MySQL运行状态
systemctl status mysqld

# 设置开机启动
systemctl enable mysqld

# 关闭开机启动
systemctl disable mysqld

# 配置默认编码为utf8:
vi /etc/my.cnf #添加 [mysqld] character_set_server=utf8 init_connect='SET NAMES utf8'

# 其他默认配置文件路径:
#配置文件:
/etc/my.cnf
#日志文件:
/var/log//var/log/mysqld.log
#服务启动脚本:
/usr/lib/systemd/system/mysqld.service
#socket文件:
/var/run/mysqld/mysqld.pid

# 查看版本
select version();

准备:
两台MySQL服务器:
1、Master:192.168.172.110
2、Slave:192.168.172.111
端口都是3306

配置详解:
一、主库配置:
1、编辑配置文件:

1
2
3
4
5
6
7
8
9
10
11
$ vim /etc/my.cnf

server-id=110 #设置主服务器的ID(不能和别的服务器重复,建议使用ip的最后一段)
innodb_flush_log_at_trx_commit=2 #可以配置的值:0/1/2; 0、效率最高,最不安全;1、最安全,但是效率最低;2、安全和效率平衡的取舍,在服务器系统挂掉的情况下会丢失数据;
sync_binlog=1 #,值可设置 1、500、1000;可自己根据测试性能配置
log-bin=mysql-bin #binlog日志文件名
binlog-ignore-db=mysql # 表示不同步mysql库
binlog-ignore-db=information_schema # 表示不同步information_schema库
binlog-ignore-db=performance_schema
binlog-ignore-db=sys
binlog-do-db=xxxx # 这个表示只同步某个库 (如果没有此项,表示同步所有的库)

2、创建用于主从同步的账户:

1
2
3
4
5
6
#登录MySQL 
$ mysql -u root -p
mysql> create user 'sync'@'%' identified by 'Sync@0000'; # 5.7要求密码必须含有大小写英文,符号和数字
mysql> grant FILe on *.* to 'sync'@'192.168.172.111' identified by 'Sync@0000'; #赋予FILE权限,允许从从库ip访问主库
mysql> grant replication slave on *.* to 'sync'@'192.168.172.111' identified by 'Sync@0000'; #赋予主从同步权限
mysql> flush privileges;

3、重启MySQL,使my.cnf 配置生效;查看主库状态:

1
2
3
4
5
6
7
8
9
$ service mysqld restart #重启MySQL
mysql -u root -p
mysql> show master status; #查看主库的状态 file,position 这两个值很有用,记一下;需要放到slave配置中
+--------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+--------------------+----------+--------------+------------------+-------------------+
| mysql-bin.00001 | 156 | xxxx | | |
+--------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

二、从库配置:
1、编辑配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ vim /etc/my.cnf

server-id=111
#log-bin=mysql-bin #从库提高性能可以不开bin-log日志
replicate-ignore-db=mysql #配置不需要复制的库mysql
replicate-ignore-db=information_schema
replicate-ignore-db=performance_schema
replicate-ignore-db=sys
replicate_do_db=python #标记出需要同步的数据库名,在多从配置时可以按需配置
innodb_flush_log_at_trx_commit=2 # 可以配置的值:0/1/2; 0、效率最高,最不安全;1、最安全,但是效率最低;2、安全和效率平衡的取舍,在服务器系统挂掉的情况下会丢失数据;
sync_binlog=1000 # 每进行n次事务提交之后,MySQL将binlog_cache中的数据强制写入磁盘。
slave_parallel_workers=4 #根据实际情况决定开启多少个线程用于主从复制
slave_parallel_type=logical_clock #基于组提交的并行复制方式
master_info_repository=TABLE
relay_log_info_repository=TABLE
relay_log_recovery=ON

2、配置完成后,重启从库的MySQL;

1
2
3
4
5
6
$ service mysqld restart #重启MySQL
$ mysql -u root -p #登录mysql
mysql> stop slave; #关闭从库
mysql> change master to master_host='192.168.172.110', master_user='sync' ,master_password='Sync@0000', master_log_file='mysql-bin.00001' ,master_log_pos=156; #配置主库信息
mysql> start slave; #开启从库
mysql> show slave status \G; #Slave_IO_Running,Slave_SQL_Running 都为Yes的时候表示配置成功

3、验证主从:
可以在主库上对数据进行操作,再在从库上刷新是否同步;

MySQL的主从配置很简单

Got fatal error 1236 from master when reading data from binary log: ‘Could not find first log file name in binary log index file’系列一:
主库添加log-bin-index 参数后,从库报这个错误:Got fatal error 1236 from master when reading data from binary log: ‘Could not find first log file name in binary log index file’

Got fatal error 1236 from master when reading data from binary log: ‘could not find next log’

可以

1
2
3
stop slave;
reset slave;
start slave;

常用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 创建数据库和用户
create database databasename default charset utf8 collate utf8_general_ci;
create user 'username'@'%' identified by 'password';
grant all privileges on databasename.* to 'username'@'%'
flush privileges;

# 替换文字
语法:UPDATE 表名 SET 字段名=replace(字段名, '被替换字符串', '新的字符串') ;
示例:UPDATE tb_user SET name=replace( name, '\'', '') ;

# 复制表结构
CREATE TABLE targetTable LIKE sourceTable;
# 复制表数据
INSERT INTO targetTable SELECT * FROM sourceTable;

HEXO使用

官网:Hexo!
文档:documentation
FAQ:troubleshooting
反馈:GitHub

快速入门

创建文章

1
$ hexo new "My New Post"

更多: Writing

运行服务

1
$ hexo server

更多: Server

生成静态文件

1
$ hexo generate

更多: Generating

部署到远程服务器

1
$ hexo deploy

更多: Deployment

多语言支持

更多: https://pygments.org/docs/lexers/

创建新的分类

1
$ hexo new page categories

RSS插件

安装

1
$ npm install hexo-generator-feed

配置

1
2
3
4
5
6
7
8
# Extensions
plugins:
hexo-generator-feed
#Feed Atom
feed:
type: atom
path: atom.xml
limit: 20

引用站内文章

1
{% post_link 文章文件名(不要后缀) 文章标题(可选) %}

安装图片支持

1
npm install https://github.com/CodeFalling/hexo-asset-image --save

安装加密

1
npm install --save hexo-blog-encrypt

数据库设计软件推荐

PDMan软件

信息

1
2
3
4
5
6
7
# Git地址 https://gitee.com/robergroup/pdman

#下载地址
# 主:https://gitee.com/robergroup/pdman/attach_files
# 备:
# MAC: http://static.kedaotech.com/PDMan-darwin_v2.1.6.dmg
# X86_64: http://static.kedaotech.com/PDMan-win64_v2.1.6.exe