Author Archives: dawnco

LNMP 调优

查看 每个 php-fpm 进程占用的平均内存
```
ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'
```
案例
```
[root@localhost web]# ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'
8M
```

YUM 安装 mysql8.0 ,重置密码等

yum 安装十分简单, 如果安装有mariadb 需要先移除, 并删除掉 repo文件
```
yum remove MariaDB MariaDB-server
rm /etc/yum.repos.d/MariaDB.repo
rm -rf /var/lib/mysql
rm -rf /etc/my.conf
rm -rf /etc/my.conf.d
```
安装
```
rpm -ivh https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
yum install -y mysql mysql-server
```

初始化, 需要先删除 rm -rf /var/lib/mysql
```
mysqld --initialize --console
```

mysql8.0安装后会自动生成密码, 找到默认密码
```
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
2019-06-29T01:35:29.486721Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Q,Fflgfye6w.
[root@localhost ~]#
```

初始化
```
mysql_secure_installation
```

开启远程登陆
```
CREATE USER 'root'@'%' IDENTIFIED BY 'Q,Fflgfye6w.';
GRANT ALL ON *.* TO 'root'@'%';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Q,Fflgfye6w.';
FLUSH PRIVILEGES;

# 修改本地
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Q,Fflgfye6w.';

```

忘记密码

修改 my.cnf
```
echo 'skip-grant-tables' >> /etc/my.cnf
systemctl restart mysqld
```
清空密码
```
[root@izbp13d8lkv9kzxvm67ax5z conf.d]# mysql
mysql> use mysql;
mysql> update user set authentication_string = '' where user = 'root';

```

针对1G 服务器配置
```

#慢日志
long_query_time = 1
slow_query_log = ON
slow_query_log_file = /var/log/mysql-slow.log
log_queries_not_using_indexes = ON

performance_schema=Off
table_definition_cache=300
table_open_cache=300
performance_schema_max_table_instances=100
innodb_buffer_pool_size=8M
innodb_log_file_size=8M
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=2M
innodb_thread_concurrency=1
key_buffer_size=8M
tmp_table_size=32M
read_buffer_size=2M
read_rnd_buffer_size=2M
sort_buffer_size=8M
max_connections=100

# 忽略大小写
lower_case_table_names=1

# 开启独享表空间,并指定ibdata1大小为128M 可以修改为1G,ibdata2大小64M,自动扩张。
innodb_data_home_dir = /var/lib/mysql
innodb_data_file_path = ibdata1:128M;ibdata2:64M:autoextend
innodb_file_per_table=1

```

参考
https://dev.mysql.com/downloads/repo/yum/

https://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html#yum-repo-setup

https://dev.mysql.com/doc/refman/5.7/en/replace-third-party-yum.html

PPTP VPN 配置

检查是否支持PPTP
```
[root@iZt4newzwl5axiunurprquZ ~]# modprobe ppp-compress-18 && echo ok
ok
```

## 安装
```
rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install ppp pptpd iptables
```
## 配置
1. 分配IP
```
vim /etc/pptpd.conf
```
最后增加
```
#客户端ip分配范围
localip 192.168.16.1
remoteip 192.168.16.10-15
```
2. 账号
```
vim /etc/ppp/chap-secrets
```
修改成如下
```
# client server secret IP addresses
"dawnco" pptpd "qaz" "*"
#用户名 类型 密码 分配的ip * 表示随即分配
```
3. DNS
```
vim /etc/ppp/options.pptpd
```
新增/修改
```
ms-dns 8.8.8.8
ms-dns 8.8.4.4
```
4. 开启转发
```
vim /etc/sysctl.conf
```
新增
```
net.ipv4.ip_forward=1
```
运行下面命令使内核修改生效:
```
sysctl -p
```
5. 设置防火墙
```
vim /usr/lib/firewalld/services/pptpd.xml
```
```


pptpd
PPTP

```
5. 设置转发规则
```
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --permanent --zone=public --add-port=8388/tcp
firewall-cmd --permanent --zone=public --add-port=443/tcp
firewall-cmd --permanent --zone=public --add-port=22/tcp
firewall-cmd --permanent --zone=public --add-port=21/tcp
firewall-cmd --permanent --zone=public --add-port=47/tcp
firewall-cmd --permanent --zone=public --add-port=1723/tcp
#
firewall-cmd --permanent --zone=public --add-service=pptpd
firewall-cmd --add-masquerade
firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -p gre -j ACCEPT
firewall-cmd --permanent --direct --add-rule ipv4 filter OUTPUT 0 -p gre -j ACCEPT
firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -i ppp+ -o eth0 -j ACCEPT
firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -i eth0 -o ppp+ -j ACCEPT
firewall-cmd --permanent --direct --passthrough ipv4 -t nat -I POSTROUTING -o eth0 -j MASQUERADE -s 192.168.16.0/24
```
重启并开机启动
```
firewall-cmd --reload
systemctl restart pptpd
systemctl enable pptpd.service
systemctl enable firewalld
```

### 问题处理
1. 问题1
```
Jun 25 10:41:49 AliYun pptpd[13835]: GRE: read(fd=6,buffer=55d87eb67480,len=8196) from PTY f
ailed: status = -1 error = Input/output error, usually caused by unexpected termination of p
ppd, check option syntax and pppd logs
Jun 25 10:41:49 AliYun pptpd[13835]: CTRL: PTY read or GRE write failed (pty,gre)=(6,7)
Jun 25 10:41:49 AliYun pptpd[13835]: CTRL: Client x.x.x.x control connection finished
Jun 25 10:42:10 AliYun pptpd[13730]: CTRL: Couldn't write packet to client.
Jun 25 10:42:10 AliYun pptpd[13730]: CTRL: Error sending GRE, aborting call
```
修改
```
vim /etc/ppp/options.pptpd
```
去掉 debug 和 dump 前的 #

2. 日志显示
```
Jul 2 08:39:53 iZj6ca3h0xhsuadr9za60eZ pppd[20902]: Cannot determine ethernet address for prox
y ARP
```
可能 firewalld 没启动 启动
```
systemctl start firewalld
```

Supervisor 安装配置

安装
```
yum install supervisor
```

配置
```
vim /etc/supervisord.d/mchregister.ini
```

```
[program:mch-register]
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/php/bin/php /data/wwwroot/platform/mch/artisan queue:work --quiet --queue=register --delay=3 --sleep=3
autostart=true ; 在supervisord启动的时候也自动启动
autorestart=true ; 在supervisord启动的时候也自动启动
user=apache ; 用哪个用户启动进程
numprocs=5 ; 开启几个进程
redirect_stderr=true ; 把stderr重定向到stdout,默认false

[program:mch-project]
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/php/bin/php /data/wwwroot/platform/mch/artisan queue:work --quiet --queue=project --delay=3 --sleep=3
autostart=true
autorestart=true
user=apache
numprocs=8
redirect_stderr=true

[program:mch-settled]
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/php/bin/php /data/wwwroot/platform/mch/artisan queue:work --quiet --queue=project_settled --delay=3 --sleep=3
autostart=true
autorestart=true
user=apache
numprocs=8
redirect_stderr=true
```

启动
```
supervisord -c /etc/supervisord.conf
```
开机运行
```
systemctl enable supervisord
```
运行
```
supervisorctl reread
supervisorctl update
supervisorctl start mch-register:*
supervisorctl start mch-project:*
supervisorctl start mch-settled:*
```

文档
http://supervisord.org/introduction.html

参考
https://www.cnblogs.com/xuezhigu/p/7660203.html

git 基本操作

## 记住/清理 密码
#### linux 下
记住密码
```
git config --global credential.helper store
```
输入密码后下次会记住

清理密码
```
rm ~/.git-credentials
```

#### windows 下

记住密码
```
git config --global credential.helper store
```
下次输入密码后就记住了

清理密码
```
git config --system --unset credential.helper
git credential-manager uninstall
```

## 添加远程地址
添加远程地址 v2
```
git remote add V2 https://gitee.com/ch.git
```
推送到远程
```
git push v2
```

```
git push origin master #意思推送到 origin 远程的 master 分支
```

利用 ImDisk 使用内存当磁盘

介绍
ImDisk是Windows NT / 2000 / XP / Vista / 7/8 / 8.1 / 10和Windows Server 2003/2003 R2 / 2008/2008 R2 / 2012/2012 R2,32和64位版本的虚拟磁盘驱动程序。它可以使用图像文件或系统内存创建虚拟硬盘,软盘或CD / DVD驱动器。
ImDisk 是开源免费的。

最新版本是 ImDisk 2.0.9
官网地址
```
http://www.ltr-data.se/opencode.html/
```
开机启动, 磁盘R 当做内存磁盘, 使用NTFS 格式
编辑文件 c:/uboot/cachedisk.bat 然后添加到 启动里面
步骤 计算机配置 -> Windows设置/脚本(启动/关机)-> 添加保存的c:/uboot/cachedisk.bat文件

内容
```
imdisk -a -s 1G -m R: -p "/fs:ntfs /q /y"
```

### 其他
windows 10 设置开机启动
gpedit.msc win10 没有,需要开启
编辑文件 a.cmd, 然后运行 即可
```
@echo off
pushd "%~dp0"
dir /b C:\Windows\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~3*.mum >List.txt
dir /b C:\Windows\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientTools-Package~3*.mum >>List.txt
for /f %%i in ('findstr /i . List.txt 2^>nul') do dism /online /norestart /add-package:"C:\Windows\servicing\Packages\%%i"
pause
```

参考
https://blog.csdn.net/u013642500/article/details/80138799