无言

不语


  • 首页

  • 分类

  • 归档

  • 标签

  • 关于

crontab

发表于 2018-06-13 | 分类于 gitlab

执行时间设置

1
2
3
4
5
6
7
8
9
10
11
每五分钟执行 */5 * * * *
每小时执行 0 * * * *
每天执行 0 0 * * *
每周执行 0 0 * * 0
每月执行 0 0 1 * *
每年执行 0 0 1 1 *

日志设置

错误方式:

1
*/1 * * * * /data/crontab/test.sh 2>&1 >> /data/crontab/log/test.log

正确方式:

1
*/1 * * * * /data/crontab/test.sh >> /data/crontab/log/test.log 2>&1

linux 安装openvpn

发表于 2018-06-11 | 分类于 系统

安装openvpn,easy-rsa软件

1
yum install -y openvpn easy-rsa

拷贝文件

1
2
3
cp /usr/share/doc/openvpn-2.4.6/sample/sample-config-files/server.conf /etc/openvpn/
cp -r /usr/share/easy-rsa/3.0.3/* /etc/openvpn/

设置默认参数

1
2
3
4
5
6
7
8
9
10
11
12
13
cd /etc/openvpn
vim vars
export KEY_SIZE=4096
export KEY_COUNTRY="CN"
export KEY_PROVINCE="SH"
export KEY_CITY="SH"
export KEY_ORG="xxx"
export KEY_EMAIL="xxx"
chmod +x vars

使用easy-rsa生成服务器端证书

1
2
3
4
5
6
7
cd /etc/openvpn
./easyrsa init-pki #创建空的pki,创建后会多一个pki的目录,初始化后,不要再初始化了。
./easyrsa build-ca nopass #创建新的CA,不使用密码,一路回车
./easyrsa gen-req server nopass #创建服务端证书,一路回车
./easyrsa sign server server #使用CA证书对服务器端证书,进行签名
./easyrsa gen-dh #创建 Diffie-Hellman,一种密钥交换算法

使用easy-rsa生成客户端证书

1
2
./easyrsa gen-req test nopass
./easyrsa sign client test

查看easy-rsa创建的pki目录结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
tree
.
├── ca.crt
├── certs_by_serial
│   ├── 4F6A847EF9A70413EA6E24BFD6AAA3CE.pem
│   └── C2833F45701214C377138DC1303D7935.pem
├── dh.pem
├── index.txt
├── index.txt.attr
├── index.txt.attr.old
├── index.txt.old
├── issued
│   ├── server.crt
│   └── test.crt
├── private
│   ├── server.key
│   ├── ca.key
│   └── test.key
├── reqs
│   ├── server.req
│   └── test.req
├── serial
└── serial.old

生成ta.key文件

1
openvpn --genkey --secret /etc/openvpn/ta.key

创建日志目录

1
mkdir -p /var/log/openvpn/

编辑服务配置文件 vim /etc/openvpn/server.conf

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
;local a.b.c.d
# 设置监听端口,必须要对应的在防火墙里面打开
port 1194
# 设置用TCP还是UDP协议?
;proto tcp
proto tcp
# 设置创建tun的路由IP通道,还是创建tap的以太网通道,由于路由IP容易控制,所以推荐使用tunnel;
# 但如果如IPX等必须使用第二层才能通过的通讯,则可以用tap方式,tap也就是以太网桥接
;dev tap
dev tun
# 这里是重点,必须指定SSL/TLS root certificate (ca),
# certificate(cert), and private key (key)
# ca文件是服务端和客户端都必须使用的,但不需要ca.key
# 服务端和客户端指定各自的.crt和.key
# 请注意路径,可以使用以配置文件开始为根的相对路径,
# 也可以使用绝对路径
# 请小心存放.key密钥文件
ca pki/ca.crt
cert pki/issued/server.crt
key pki/private/server.key
#(默认是2048,如果生成ca的时候修改过dh参数“export KEY_SIZE”则改为对应的数字)
dh pki/dh.pem
# 配置VPN使用的网段,OpenVPN会自动提供基于该网段的DHCP服务,但不能和任何一方的局域网段重复,保证唯一
server 10.20.0.0 255.255.255.0
# 维持一个客户端和virtual IP的对应表,以方便客户端重新连接可以获得同样的IP
ifconfig-pool-persist ipp.txt
# 为客户端创建对应的路由,以另其通达公司网内部服务器
# 但记住,公司网内部服务器也需要有可用路由返回到客户端
;push "route 192.168.20.0 255.255.255.0"
push "route 10.X.0.0 255.255.0.0"
# (X按照机房网段修改)
# 若客户端希望所有的流量都通过VPN传输,则可以使用该语句
# 其会自动改变客户端的网关为VPN服务器,推荐关闭
#一旦设置,请小心服务端的DHCP设置问题
;push "redirect-gateway def1 bypass-dhcp"
# 用OpenVPN的DHCP功能为客户端提供指定的DNS、WINS等
;push "dhcp-option DNS 208.67.222.222"
;push "dhcp-option DNS 208.67.220.220"
# 默认客户端之间是不能直接通讯的,除非把下面的语句注释掉
client-to-client
# 下面是一些对安全性增强的措施
# For extra security beyond that provided by SSL/TLS, create an "HMAC firewall"
# to help block DoS attacks and UDP port flooding.
#
# Generate with:
# openvpn --genkey --secret ta.key
#
# The server and each client must have a copy of this key.
# The second parameter should be 0 on the server and 1 on the clients.
; tls-auth ta.key 0 # This file is secret
#(这句要注释掉)
# 使用lzo压缩的通讯,服务端和客户端都必须配置
comp-lzo
# 输出短日志,每分钟刷新一次,以显示当前的客户端
status /var/log/openvpn/openvpn-status.log
# 缺省日志会记录在系统日志中,但也可以导向到其他地方
# 建议调试的使用先不要设置,调试完成后再定义
log /var/log/openvpn/openvpn.log
log-append /var/log/openvpn/openvpn.log
# 设置日志的级别
#
# 0 is silent, except for fatal errors
# 4 is reasonable for general usage
# 5 and 6 can help to debug connection problems
# 9 is extremely verbose
verb 3

启动服务:

1
2
3
service openvpn start
#设置开机启动
chkconfig openvpn on

开启路由转发功能

1
2
3
4
5
vim /etc/sysctl.conf
找到net.ipv4.ip_forward = 0
把0改成1
sysctl -p #生效

设置防火墙

1
2
3
4
5
6
# 设置iptables(这一条至关重要,通过配置nat将vpn网段IP转发到server内网)
iptables -t nat -A POSTROUTING -s 10.20.0.0/24 -o eth0 -j MASQUERADE
# openvpn端口通过
iptables -A INPUT -p TCP --dport 1194 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
service iptables save

创建客户端文件

1
2
cd /home/test
vim test.opvn

填入内容

1
2
3
4
5
6
7
8
9
10
client
dev tun
proto tcp
remote xxx.xxx.xxx.xxx 1194
ca ca.crt
cert test.crt
key test.key
comp-lzo
persist-key
persist-tun

拷贝客户端文件

1
2
3
4
cp /etc/openvpn/pki/ca.crt /home/test
cp /etc/openvpn/pki/issued/test.crt /home/test
cp /etc/openvpn/pki/private/test.key /home/test
cp /etc/openvpn/ta.key /home/test

打包下载文件

1
2
3
cd /home/test
zip test.zip *
sz test.zip

下载openvpn客户端,打开test.opvn,即可连上服务器了。

linux 磁盘格式化

发表于 2018-06-11 | 分类于 系统

卸载硬盘

1
umount -v 挂载路径

如果磁盘busy

1
lsof |grep 挂载路径

找出正在使用磁盘的进程,kill掉。

查看磁盘分区格式

1
df -T

格式化磁盘分区

1
mkfs -t ext4 /dev/sdb

centos 6.5 安装mysql 5.7

发表于 2018-05-31 | 分类于 mysql

centos 6.5 安装mysql 5.7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/bash
yum -y remove mysql-libs*
yum install -y numactl
yum install -y perl
yum install -y libaio
rpm -ivh mysql-community-common-5.7.21-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.21-1.el6.x86_64.rpm
rpm -ivh mysql-community-client-5.7.21-1.el6.x86_64.rpm
rpm -ivh mysql-community-server-5.7.21-1.el6.x86_64.rpm
service mysqld start
mkdir /data/mysql
mkdir /data/tmp
chmod 777 /data/tmp
mkdir -p /data/log/mysql/
chown mysql:mysql /data/mysql
chown mysql:mysql /data/log/mysql/

修改myql5.7密码

进入安全模式

service mysqld stop
mysqld_safe --skip-grant-tables &

修改密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use mysql;
set global validate_password_policy=0;
SET PASSWORD = PASSWORD('bits@20180528!hhhaj11ddh~');
ALTER USER 'root'@'localhost' IDENTIFIED BY 'bits@asdfasdf2019019';
flush privileges;
quit;
set password=password("11@20180528!hzhz1d1dzh~");
service mysqld stop
service mysqld start

修改8.0密码

1
2
3
4
5
6
mysqld --initialize-insecure --user=mysql
use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
FLUSH PRIVILEGES;

添加用户

1
2
3
4
5
6
7
8
9
10
11
12
13
set global validate_password_policy=0;
Delete FROM user Where User='xcredit' and Host='%';
flush privileges;
create user dd identified by 'Cq&asdfasd9!#jq^J4K';
GRANT ALL PRIVILEGES ON *.* TO 'dd'@'%' WITH GRANT OPTION;
flush privileges;

设置root能远程访问

1
2
3
4
5
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'dd@201dafds90ddf19' WITH GRANT OPTION;
FLUSH PRIVILEGES

mysql5.7 GTID主从同步

发表于 2018-05-31 | 分类于 mysql

机器:

db1: 10.19.2.11
db2: 10.19.113.140

mysql版本

Server version: 5.7.21-log MySQL Community Server (GPL)

db1 my.cnf配置

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
[mysqld]
#是内存情况配置,理想为 70%的物理内存
innodb_buffer_pool_size = 45G
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 1073741824
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
#thread_concurrency = 8
binlog_cache_size = 4M
expire_logs_days = 10
max_connections = 1000
log_timestamps=SYSTEM
default-time_zone = '+8:00'
#
datadir=/data/mysql
socket=/data/mysql/mysql.sock
lower_case_table_names=1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
secure-file-priv = ""
tmpdir=/data/tmp
validate_password_policy=0
# 记录慢速查询
slow_query_log=1
slow_query_log_file=/data/log/mysql/mysql-slow.log
# # 慢查询最小值,大于此时间,则为慢查询,单位为秒
long_query_time=6
#GTID 主从同步
gtid_mode=on
enforce_gtid_consistency=on
#唯一的服务辨识号,数值位于 1 到 2^32-1之间.
server_id=1
log-bin=mysql-bin
log-slave-updates=1
binlog_format=row
#当binlog_format=row时,用于记录原始的sql语句,不记录了
#binlog_rows_query_log_events=on
slave-skip-errors=all
auto-increment-offset=1
auto-increment-increment=2
#忽略下列的库表
#replicate-wild-ignore-table=mysql.%
#replicate-wild-ignore-table=test.%
#replicate-wild-ignore-table=performance_schema.%
[client]
socket=/data/mysql/mysql.sock

db2 my.cnf配置

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
[mysqld]
#是内存情况配置,理想为 70%的物理内存
innodb_buffer_pool_size = 45G
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 1073741824
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
#thread_concurrency = 8
binlog_cache_size = 4M
max_connections = 1000
log_timestamps=SYSTEM
default-time_zone = '+8:00'
#
datadir=/data/mysql
socket=/data/mysql/mysql.sock
lower_case_table_names=1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
secure-file-priv = ""
tmpdir=/data/tmp
validate_password_policy=0
# 记录慢速查询
slow_query_log=1
slow_query_log_file=/data/log/mysql/mysql-slow.log
# 慢查询最小值,大于此时间,则为慢查询,单位为秒
long_query_time=6
#GTID 主从同步
gtid_mode=on
enforce_gtid_consistency=on
#唯一的服务辨识号,数值位于 1 到 2^32-1之间.
server_id=2
log-bin=mysql-bin
log-slave-updates=1
binlog_format=row
#当binlog_format=row时,用于记录原始的sql语句,不记录了
#binlog_rows_query_log_events=on
slave-skip-errors=all
#在主主同步配置时,需要将两台服务器的auto_increment_increment增长量都配置为2,而要把auto_increment_offset分别配置为1和2。这样才可以避免两台服务器同时做更新时自增长字段的值之间发生冲突。参考:http://dev.mysql.com/doc/refman/5.0/en/replication-options-master.html
auto-increment-offset=2
auto-increment-increment=2
##忽略下列的库表
#replicate-wild-ignore-table=mysql.%
#replicate-wild-ignore-table=test.%
#replicate-wild-ignore-table=performance_schema.%
#
[client]
socket=/data/mysql/mysql.sock

db1 创建同步用户

1
2
3
create user 'slave'@'10.19.%.%' identified by 'slave123#@!b11d';
grant replication slave on *.* to 'slave'@'10.19.%.%';
flush privileges;

mysql 8.13

1
2
3
4
create user 'slave'@'%' identified WITH mysql_native_password by 'slave1ddd23#@!b11dddd';
grant replication slave on *.* to 'slave'@'%';
flush privileges;

db2 上开启同步db1

1
2
3
4
5
6
7
change master to master_host='10.19.2.11',
master_user='slave',
master_password='slave123#@!b11d',
MASTER_AUTO_POSITION=1;
start slave;

查看是否成功

show master logs;
show master status;

通过show slave status \G 查看slave状态

也可以通过 select user,host from mysql.user; 来查看同步用户是否已经建立好,
如果建立好,代表已经同步成功。

8.13无法复制用户过来在db2新建账号

1
2
3
create user 'slave'@'%' identified WITH mysql_native_password by 'slave1ddd23#@!b11dddd';
grant replication slave on *.* to 'slave'@'%';
flush privileges;

db1 上开启同步db2

1
2
3
4
5
6
change master to master_host='10.19.113.140',
master_user='slave',
master_password='slave123#@!b11d',
MASTER_AUTO_POSITION=1;
start slave;

测试同步复制

db2从db1同步测试

在db1上执行以下语句:

1
2
3
4
create database test_db1;
use test_db1;
create table temp(id int primary key not null auto_increment,a int,b int,c int as (a*b));
insert into temp (a,b)values(1,2),(3,4),(5,6);

在db2上查看是否正常同步,如果正常,即成功。

在db2上执行以下语句:

db1从db2同步测试

1
2
3
4
create database test_db2;
use test_db2;
create table temp(id int primary key not null auto_increment,a int,b int,c int as (a*b));
insert into temp (a,b)values(1,2),(3,4),(5,6);

在db1上查看是否正常同步,如果正常,即成功。

停机测试

  1. 停止db2的数据库,在db1上执行
  2. 启动db2,查看是否正常同步,如果正常同步,即成功。
1
insert into temp (a,b)values(7,8),(9,10);

停止同步slave 模式,然后再启动测试,看数据是否同步

  1. 停止db2的slave

    1
    stop slave;

    在db1上执行

    1
    insert into temp (a,b)values(11,12);
  2. 启动db2,查看是否正常同步,如果正常同步,即成功。

    1
    start slave;
12345
huawei

huawei

1

25 日志
17 分类
32 标签
GitHub
© 2019 huawei
由 Hexo 强力驱动
主题 - NexT.Pisces