运维备忘录(持续完善)
2021-11-02 10:00:00
CentOS 7.x
查看系统发行版本
cat /etc/redhat-release
修改主机名
hostnamectl set-hostname xxx
修改时区
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
Extra Packages for Enterprise Linux
yum install epel-release
Nginx
systemctl reload nginx
curl
--data-urlencode "key=value"
--header "Content-Type:application/x-www-form-urlencoded"
lsof
yum install lsof
lsof -i | grep ^sshd
split
split -b 20M output.log
chown
chown -R mysql:mysql /home/work/mysql
fuser
yum install psmisc
fuser -m /home/work
tar exclude
tar -zcf config.tar.gz config --exclude=ip
tar salt
tar -zcf - hello.txt | openssl des3 -salt -k pwd -out hello.tar.gz
openssl des3 -d -k pwd -salt -in hello.tar.gz | tar zxf -
MySQL
SHOW VARIABLES LIKE '%read_only';
SHOW VARIABLES LIKE 'general_log%';
SET GLOBAL general_log = ON;
SHOW VARIABLES LIKE 'log_timestamps';
SET GLOBAL log_timestamps = SYSTEM;
PURGE BINARY LOGS BEFORE '2021-11-01 00:00:00';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'192.168.0.2' IDENTIFIED BY '123456';
FLUSH PRIVILEGES;
firewalld
systemctl stop firewalld
systemctl disable firewalld
firewall-cmd --permanent --zone=public --add-port=3306/tcp
firewall-cmd --reload
firewall-cmd --list-all
firewall-cmd --list-ports
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.0/24" port port="1-65535" protocol="tcp" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.0/24" accept"
GitLab
curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash
yum install gitlab-ce
gitlab-ctl reconfigure
可考虑修改 /etc/gitlab/gitlab.rb
- external_url 可携带端口
- git_data_dirs 加密盘目录(取消注释)
git 仓库迁移
git clone --mirror http://172.20.10.10/root/repo.git
cd repo.git
git remote set-url origin http://172.20.10.10/root/newrepo.git
git push -f origin
git 多仓库备份(检出所有分支)
#!/bin/bash
backup() {
git clone http://172.20.10.10/$1.git
cd ${1#*/}
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
cd ..
}
for v in "root/repo" "root/newrepo"
do backup $v; done
git lfs
git lfs migrate import --everything --include="largefile,largefile.zip"
git push --force --all
git lfs push --object-id http://172.20.10.10/root/repo.git hash
注:Settings -> Repository -> Protected branches -> Allowed to force push
PHP(ThinkPHP)
yum install epel-release
yum install nginx
systemctl start nginx
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64 php70w-pecl-redis.x86_64
yum -y install php70w-fpm php70w-opcache
systemctl start php-fpm
echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php
# 修改 nginx.conf
chown -R apache:apache runtime log
Nginx 配置
set $root /usr/share/nginx/html;
root $root;
index index.html index.php;
charset utf-8;
location / {
if ( !-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ .+\.php($|/) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
include fastcgi_params;
}
Beyond Compare(Mac)
rm /Users/$(whoami)/Library/Application\ Support/Beyond\ Compare/registry.dat