hfcrwx

Home

Dev

Published May 18, 2021

CentOS 7

systemctl status firewalld
systemctl stop firewalld
systemctl disable firewalld

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0

关闭windows防火墙

yum update

yum grouplist
yum groupinfo Development Tools
yum groupinstall Development Tools

yum install lrzsz

yum repolist all

yum install epel-release
yum clean all
yum makecache

yum install cmake3
ln -sf /usr/bin/cmake3 /usr/bin/cmake

yum install centos-release-scl
yum clean all
yum makecache

yum install rh-git227
scl -l
vim ~/.bashrc
	source scl_source enable rh-git227 httpd24
//scl enable rh-git218 bash

//yum install clang
yum install llvm-toolset-7-git-clang-format
scl -l
vim ~/.bashrc
	source scl_source enable llvm-toolset-7

yum install devtoolset-10
scl -l
vim ~/.bashrc
	source scl_source enable devtoolset-10

Git

https://docs.github.com/cn/github/authenticating-to-github/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account

ssh-keygen -t ed25519 -C "hfcrwx@163.com"

https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings

git config --global core.autocrlf input

git clone –recursive

git clone https://github.com/xxx/xxx.git
vim .gitmodules
	github.com --> github.com.cnpmjs.org
	OR
	https://github.com/yyy/yyy.git --> git@github.com:yyy/yyy.git
git submodule sync
git submodule update --init

git 移除submodule

git submodule deinit xxx
git rm xxx

git 合作

https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/syncing-a-fork

fork
git clone ...
git checkout -b dev
...
git push origin dev:dev
//git checkout -b dev origin/dev

git remote add upstream ...
git fetch upstream
git checkout master
git merge upstream/master

git push origin --delete dev
git checkout -b new_dev

muduo

yum install boost-devel protobuf-devel c-ares-devel libcurl-devel gd-devel thrift-devel python-thrift hiredis-devel mariadb-devel

//git clone https://github.com/chenshuo/muduo.git
git clone https://github.com.cnpmjs.org/hfcrwx/muduo.git
git checkout -b mariadb-client origin/mariadb-client

//export CMAKE_LIBRARY_PATH=/usr/lib64/mysql	//用于find_library(MARIADBCLIENT_LIBRARY NAMES mysqlclient)
//export LIBRARY_PATH=/usr/lib64/mysql
export BUILD_TYPE=debug
./build.sh

libevent

yum install libevent-devel

git clone https://github.com/libevent/libevent.git
git checkout release-2.0.22-stable

./autogen.sh
./configure
make

wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz
tar -xzvf libevent-2.1.12-stable.tar.gz
cd libevent-2.1.12-stable
mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Debug 

redis

yum install redis
vim /etc/redis.conf
	# bind 127.0.0.1
	requirepass 123456

systemctl start redis
systemctl status redis
systemctl enable redis

git clone https://github.com/huangz1990/redis-3.0-annotated.git

git clone https://github.com.cnpmjs.org/redis/redis.git

git checkout 3.2.12
make
cd /root/redis/deps/hiredis
make
make hiredis-example hiredis-example-ae hiredis-example-libevent

git checkout 6.0.13
yum install centos-release-scl
yum install devtoolset-9-gcc
scl -l
scl enable devtoolset-9 bash
make
vim /root/redis/deps/hiredis/Makefile
-       $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. -I$(AE_DIR) $< $(AE_DIR)/ae.o $(AE_DIR)/zmalloc.o $(AE_DIR)/../deps/jemalloc/lib/libjemalloc.a -pthread $(STLIBNAME)
+       $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. -I$(AE_DIR) $< $(AE_DIR)/ae.o $(AE_DIR)/zmalloc.o $(AE_DIR)/../deps/jemalloc/lib/libjemalloc.a -pthread -ldl $(STLIBNAME)

hiredis

yum install hiredis-devel
yum install libevent-devel

git clone https://github.com/redis/hiredis.git
git checkout v0.12.1

make OPTIMIZATION=-O0
make hiredis-example hiredis-example-libevent OPTIMIZATION=-O0
export AE_DIR=/root/redis/src/
make hiredis-example-ae OPTIMIZATION=-O0
make install LIBRARY_PATH=lib

git checkout v1.0.0
cmake .. -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DCMAKE_C_FLAGS="-std=gnu99"

curl

git clone https://github.com.cnpmjs.org/curl/curl.git
git checkout curl-7_29_0

./buildconf
./configure
make

/root/curl/docs/examples/Makefile
# These examples require external dependencies that may not be commonly
# available on POSIX systems, so don't bother attempting to compile them here.
COMPLICATED_EXAMPLES = curlgtk.c curlx.c htmltitle.cpp cacertinmem.c       \
  ftpuploadresume.c ghiper.c hiperfifo.c htmltidy.c multithread.c          \
  opensslthreadlock.c sampleconv.c synctime.c threaded-ssl.c evhiperfifo.c \
  smooth-gtk-thread.c version-check.pl href_extractor.c asiohiper.cpp

/root/curl/docs/examples/README
/root/curl/docs/examples/Makefile.example

gcc -o hiperfifo hiperfifo.c -lcurl -levent
g++ -o asiohiper asiohiper.cpp -lcurl -lboost_system

mariadbclient

git clone https://github.com/mariadb-corporation/mariadb-connector-c.git
git checkout v_2.3.7

yum install mariadb-devel	--> mysql-community-devel
yum install mariadb-libs	--> mysql-community-libs

mariadb

git clone --recursive https://github.com/MariaDB/server.git
git checkout mariadb-5.5.68

https://mariadb.com/kb/en/Build_Environment_Setup_for_Linux/
yum install ncurses-devel

mkdir build && cd build && cmake ..
server/client/async_example
server/tests/async_queries

evpp

yum install glog-devel gflags-devel
git clone --recursive https://github.com/Qihoo360/evpp.git
cmake .. -DCMAKE_BUILD_TYPE=Debug

mysql

安装 yum repo

https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

https://dev.mysql.com/downloads/repo/yum/ https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm http://repo.mysql.com/ https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm https://repo.mysql.com/mysql80-community-release-el7.rpm

rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
yum repolist all | grep mysql

选择版本

vim /etc/yum.repos.d/mysql-community.repo
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

yum repolist enabled | grep mysql

安装 mysql-community-server

yum install mysql-community-server
systemctl start mysqld
systemctl status mysqld

配置 mysql 5.7

grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p

SHOW VARIABLES LIKE 'validate_password_policy';
SHOW VARIABLES LIKE 'validate_password_length';
//降低密码安全性规则
mysql> SET GLOBAL validate_password_policy=LOW;
mysql> SET GLOBAL validate_password_length=1;

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

配置 mysql 5.6

mysql_secure_installation

Enter current password for root (enter for none):
	123456
Change the root password? [Y/n] y
Disallow root login remotely? [Y/n] n

mysql -uroot -p
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

安装 mysql-community-devel

yum install mysql-community-devel
//export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/include/mysql
export LIBRARY_PATH=$LIBRARY_PATH:/usr/lib64/mysql
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64/mysql

nginx

https://nginx.org/en/docs/configure.html
https://nginx.org/en/docs/beginners_guide.html
https://docs.nginx.com/nginx/admin-guide/
https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/

wget https://nginx.org/download/nginx-1.16.1.tar.gz
tar -xzvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
./configure --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_secure_link_module --with-http_stub_status_module --with-http_gzip_static_module

yum install nginx
nginx
curl -I 127.0.0.1

systemctl start nginx
systemctl status nginx
systemctl enable nginx

mongodb

https://docs.mongodb.com/guides/server/install/
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat-tarball/
https://docs.mongodb.com/v3.6/tutorial/install-mongodb-on-red-hat/

visual studio code

官方文档

https://code.visualstudio.com/docs/remote/ssh

安装ssh client/server

https://code.visualstudio.com/docs/remote/troubleshooting#_installing-a-supported-ssh-client

client

ssh-keygen -t rsa -b 2048
C:\Users\hfcrwx\.ssh\id_rsa.pub

server

rz
cat id_rsa.pub >> ~/.ssh/authorized_keys

安装插件Remote - SSH

左下角插件图标 -> Remote-SSH: Connect to Host… -> +Add New SSH Host… -> ssh root@182.92.195.224 -> C:\Users\hfcrwx.ssh\config -> Connect

连接成功后,选 Linux -> Continue,Open folder…

安装插件C/C++

ctrl + shift + P -> C/C++: Edit Configurations (UI) -> 修改Include path、C++ standard

.vscode/c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

编译

ctrl + shift + P -> Tasks: Configure Task -> Create tasks.json file from template ->Others

.vscode/tasks.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "export BUILD_TYPE=debug && ./build.sh"
        }
    ]
}

ctrl + shift + P -> Tasks: Run Task -> build -> Continue…

调试

ctrl + shift + P -> View: Show Run and Debug -> create a launch.json file. -> C++ (GDB/LLDB)

Add Configuration… -> C/C++ (gdb) Attach

.vscode/launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Attach",
            "type": "cppdbg",
            "request": "attach",
            "program": "${workspaceFolder}/../build/debug-cpp11/bin/echoserver_unittest",
            "processId": "${command:pickProcess}",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/../build/debug-cpp11/bin/echoserver_unittest",
            "args": [
                "2"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

Unable to watch for file chages in this large workspace folder.

https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-changes-in-this-large-workspace-error-enospc

cat /proc/sys/fs/inotify/max_user_watches
vim /etc/sysctl.conf
	fs.inotify.max_user_watches = 524288
sysctl -p
cat /proc/sys/fs/inotify/max_user_watches

Remote-Containers

Remote-Containers: Attach to Running Container…

gdb

https://www.sourceware.org/gdb/wiki/STLSupport

mkdir gdb_printers
cd gdb_printers
svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python

~/.gdbinit

python
import sys
sys.path.append("/usr/share/gcc-4.8.5/python")
sys.path.insert(0, '/root/gdb_printers/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end

tars

https://tarscloud.github.io/TarsDocs/installation/source.html

准备 CentOS 7 开发环境

安装 mysql-community-server 5.6

安装依赖

yum install zlib-devel
git clone --branch=v2.4.20 --depth=1 git@github.com:TarsCloud/Tars.git --recursive

安装 tarsframework

cd framework/build
./build.sh all
./build.sh install

cd framework/build
cmake .. -LH
cmake .. -DCMAKE_BUILD_TYPE=Debug -DONLY_LIB=OFF
make
make install

安装 tarsweb

cp -rf  web/ /usr/local/tars/cpp/deploy/

cd /usr/local/tars/cpp/deploy/
./linux-install.sh 172.29.233.88 123456 eth0 false false root 3306

浏览器打开:http://39.105.159.68:3000
/usr/local/app/tars/tars-stop.sh
/usr/local/app/tars/tars-start.sh

c++: internal compiler error: Killed (program cc1plus)

dd if=/dev/zero of=/swapfile bs=64M count=16
mkswap /swapfile
swapon /swapfile

After compiling, you may wish to

swapoff /swapfile
rm /swapfile

vs code: 过程试图写入的管道不存在

ssh-keygen -R 39.105.159.68
or
rm -rf ~/.ssh/known_hosts

git submodule

git submodule add https://github.com/chenshuo/muduo.git 3rdparty/muduo
git submodule add https://github.com/redis/hiredis.git 3rdparty/hiredis

cmake .. -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXAMPLES=ON -DCMAKE_C_FLAGS="-std=gnu99"

clang-format

https://clang.llvm.org/docs/ClangFormat.html

yum install clang

clang-format -style=google -dump-config > .clang-format
find . -regex '.*\.\(cpp\|hpp\|cu\|c\|h\)' -exec clang-format -style=file -i {} \;
clang-format -style=file -i main.cc

find . -regex '.*\.\(h\|hh\|hpp\|hxx\|H\|c\|cc\|cpp\|cxx\|C\)' -exec clang-format -style=file -i {} \;

boost.asio

yum install centos-release-scl
yum install devtoolset-10
scl -l
scl enable devtoolset-10 bash

https://www.boost.org/users/history/version_1_74_0.html
https://www.boost.org/doc/libs/1_74_0/more/getting_started/unix-variants.html
https://www.boost.org/doc/libs/1_74_0/doc/html/boost_asio/using.html

wget https://boostorg.jfrog.io/artifactory/main/release/1.74.0/source/boost_1_74_0.tar.bz2
tar --bzip2 -xf boost_1_74_0.tar.bz2
cd boost_1_74_0
./bootstrap.sh --help
./bootstrap.sh
./b2 --help
./b2 variant=debug

example:

cd /root/boost_1_74_0/libs/asio/example/cpp03/tutorial
/root/boost_1_74_0/b2

cd /root/boost_1_74_0/libs/asio/example/cpp17/coroutines_ts
g++ -o echo echo_server.cpp -g -std=c++20 -fcoroutines -I/root/boost_1_74_0/ -pthread

socks5

yum install openldap-devel pam-devel openssl-devel
wget https://jaist.dl.sourceforge.net/project/ss5/ss5/3.8.9-2/ss5-3.8.9-2.tar.gz
tar -xzvf ss5-3.8.9-2.tar.gz
cd ss5-3.8.9
./configure
vim src/Makefile
	LIBS = -lpthread -rdynamic -ldl -lssl -lcrypto -lldap -lpam -lpam_misc
make && make install

vim /etc/opt/ss5/ss5.conf
	auth    0.0.0.0/0               -               -
	permit -        0.0.0.0/0       -       0.0.0.0/0       -       -       -       -       -
chmod u+x /etc/rc.d/init.d/ss5

chkconfig --add ss5
chkconfig ss5 on
systemctl start ss5
systemctl enable ss5

squid

[root@iZ2ze7qslbwa07f03lfmehZ ~]# yum -y install squid
[root@iZ2ze7qslbwa07f03lfmehZ ~]# systemctl start squid
[root@iZ2ze7qslbwa07f03lfmehZ bin]# curl -v -x http://127.0.0.1:3128 http://127.0.0.1:9981/
* About to connect() to proxy 127.0.0.1 port 3128 (#0)
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 3128 (#0)
> GET http://127.0.0.1:9981/ HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 127.0.0.1:9981
> Accept: */*
> Proxy-Connection: Keep-Alive
> 
< HTTP/1.1 200 OK
< Content-Type: text/html
< Date: Sat, 14 Aug 2021 11:44:15 GMT
< Content-Length: 884
< X-Cache: MISS from iZ2ze7qslbwa07f03lfmehZ
< X-Cache-Lookup: MISS from iZ2ze7qslbwa07f03lfmehZ:3128
< Via: 1.1 iZ2ze7qslbwa07f03lfmehZ (squid/3.5.20)
< Connection: keep-alive
< 
<!DOCTYPE html>
<html>
 <head>
  <meta charset='utf-8'>
  <title>/</title>
  <base href='/'>
 </head>
 <body>
  <h1>/</h1>
  <ul>
    <li><a href="sbin">sbin</a>
    <li><a href="mnt">mnt</a>
    <li><a href="tmp">tmp</a>
    <li><a href="media">media</a>
    <li><a href="..">..</a>
    <li><a href="srv">srv</a>
    <li><a href="proc">proc</a>
    <li><a href="sys">sys</a>
    <li><a href="var">var</a>
    <li><a href="lib64">lib64</a>
    <li><a href="lib">lib</a>
    <li><a href="bin">bin</a>
    <li><a href="home">home</a>
    <li><a href="run">run</a>
    <li><a href="dev">dev</a>
    <li><a href=".">.</a>
    <li><a href="boot">boot</a>
    <li><a href="lost+found">lost+found</a>
    <li><a href="usr">usr</a>
    <li><a href=".autorelabel">.autorelabel</a>
    <li><a href="opt">opt</a>
    <li><a href="root">root</a>
    <li><a href="etc">etc</a>
</ul></body></html>
* Connection #0 to host 127.0.0.1 left intact

thrift

wget http://archive.apache.org/dist/thrift/0.9.1/thrift-0.9.1.tar.gz
tar -xzvf thrift-0.9.1.tar.gz
./configure CXXFLAGS='-g -O0'
gdb /root/thrift-0.9.1/tutorial/cpp/.libs/TutorialServer

protobuf

wget https://github.com/protocolbuffers/protobuf/releases/download/v2.5.0/protobuf-2.5.0.tar.bz2
tar -xjvf protobuf-2.5.0.tar.bz2
cd protobuf-2.5.0
./configure CXXFLAGS='-g -O0'
make
export PKG_CONFIG_PATH=/root/protobuf-2.5.0
export LD_LIBRARY_PATH=/usr/local/lib
cd examples
vim Makefile
	c++ add_person.cc addressbook.pb.cc -o add_person_cpp `pkg-config --cflags --libs protobuf` -g -O0
	c++ list_people.cc addressbook.pb.cc -o list_people_cpp `pkg-config --cflags --libs protobuf` -g -O0
make cpp

CppMicroServices

git clone git@github.com:CppMicroServices/CppMicroServices.git --recursive
vi CMakeLists.txt
	-us_cache_var(CMAKE_DEBUG_POSTFIX d STRING "Executable and library debug name postfix" ADVANCED)
    +# us_cache_var(CMAKE_DEBUG_POSTFIX d STRING "Executable and library debug name postfix" ADVANCED)
cmake3 .. -DUS_BUILD_EXAMPLES:BOOL=ON

msys2 mingw64

https://www.msys2.org/
PATH: C:\msys64\mingw64\bin
ln -sf /mingw64/bin/mingw32-make /mingw64/bin/make.exe
cmake .. -G"MinGW Makefiles"

https://www.msys2.org/docs/terminals/

https://www.msys2.org/wiki/Launchers/

docker

https://docs.docker.com/desktop/windows/install/

Download and install the Linux kernel update package

https://docs.microsoft.com/zh-cn/windows/wsl/install-win10#step-4—download-the-linux-kernel-update-package

If your admin account is different to your user account, you must add the user to the docker-users group. Run Computer Management as an administrator and navigate to Local Users and Groups > Groups > docker-users. Right-click to add the user to the group. Log out and log back in for the changes to take effect.

Docker Desktop for Windows

https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe

cmd:

docker run -d -p 2222:22 --name centos7 --privileged=true centos:centos7.9.2009 /usr/sbin/init

docker exec -it centos7 /bin/bash
yum install openssh-server
systemctl start sshd
systemctl enable sshd

passwd
123456

exit
docker start centos7

ssh

ssh root@127.0.0.1 -p 2222

https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/about-ssh

https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

vmhgfs-fuse .host:/ /mnt/hgfs

某git仓库同步到云服务器

云服务器:

adduser git
收集所有需要登录的用户公钥,然后导入到/home/git/.ssh/authorized_keys文件
假设仓库位于/srv/xxx/sample.git,在/srv/xxx目录下输入命令:
git init --bare sample.git
chown -R git:git sample.git

某git仓库所在PC:

git remote add aliyun git@182.92.195.224:/srv/xxx/sample.git
git push -u aliyun master
git push -u aliyun dev
git push --all aliyun

云服务器:

git clone /srv/xxx/sample.git
git clone git@182.92.195.224:/srv/xxx/sample.git

错误:

[root@localhost cttp]# git push
枚举对象: 21, 完成.
对象计数中: 100% (21/21), 完成.
写入对象中: 100% (21/21), 15.82 KiB | 2.26 MiB/s, 完成.
总共 21(差异 0),复用 0(差异 0),包复用 0
remote: error: insufficient permission for adding an object to repository database ./objects
remote: fatal: failed to write object
error: 远程解包失败:unpack-objects abnormal exit
To 182.92.195.224:/srv/xxx/sample.git
 ! [remote rejected] dev -> dev (unpacker error)
error: 推送一些引用到 '182.92.195.224:/srv/xxx/sample.git' 失败

解决:

chown -R git:git /srv/xxx/sample.git/

cmake_format

yum install python-pip
pip3 install --upgrade pip
pip3 install cmake_format

nanolog

git clone --branch=0.91 --depth=1 --recursive git@github.com:PlatformLab/NanoLog.git

代码行数

find . "(" -name "*.cc" -or -name "*.h" ")" -print | xargs wc -l

export CPLUS_INCLUDE_PATH=/opt/include

cmake ..

shfmt

https://github.com/mvdan/sh

https://github.com/mvdan/sh/blob/master/cmd/shfmt/shfmt.1.scd

export GOPROXY=https://proxy.golang.com.cn,direct
go install mvdan.cc/sh/v3/cmd/shfmt@v3.4.3
/root/go/bin/shfmt --version
shfmt -i 2 -ci -bn script.sh

隔离cpu

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux_for_real_time/7/html/tuning_guide/isolating_cpus_using_tuned-profiles-realtime

1.安装 hwloc
yum install hwloc
yum install numactl

2.查看cup分布情况
    1)lstopo-no-graphics --no-io --no-legend --of txt

    2)numactl --hardware

3.安装 tuned-profiles工具集
   yum install tuned-profiles-cpu-partitioning

4.查看当前配置
    tuned-adm active
    记住,用来恢复

4.修改配置
     /etc/tuned/cpu-partitioning-variables.conf
    当前修改:
     isolated_cores=0,2,4,6,8,10,12,14
5.载入配置
   tuned-adm profile cpu-partitioning

6.重启
  管理员 reboot

7. 重启后
   1)cat /proc/cmdline | grep isolcpus 查看情况   

   2)top/htop 等工具确认

top -p pid
taskset -p pid

tuned-adm profile
tuned-adm profile virtual-guest

Secure CRT

Options -> Terminal -> Audio bell: no

​ Auto reconnect: yes

​ Send protocaol NO-OP: yes

​ -> Appearance -> White/Black

​ -> Front

​ -> Blingking: no

Chang ALL sesseions(no undo)

虚拟机添加硬盘、扩容

[root@localhost ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0     1T  0 disk 
├─sda1            8:1    0     1G  0 part /boot
└─sda2            8:2    0  1023G  0 part 
  ├─centos-root 253:0    0    50G  0 lvm  /
  ├─centos-swap 253:1    0   3.9G  0 lvm  [SWAP]
  └─centos-home 253:2    0 969.1G  0 lvm  /home
sdb               8:16   0   1.5T  0 disk 
sr0              11:0    1  1024M  0 rom  
[root@localhost ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0x8e3b7aa0 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1):1
起始 扇区 (2048-3221225471,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-3221225471,默认为 3221225471):
将使用默认值 3221225471
分区 1 已设置为 Linux 类型,大小设为 1.5 TiB

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@localhost ~]# file /dev/sdb1
/dev/sdb1: block special
[root@localhost ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=100663232 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=402652928, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=196607, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# vim /etc/fstab 
[root@localhost ~]# mount -a
mount: 挂载点 /home/croot_code1 不存在
[root@localhost ~]# mkdir /home/croot_code1
[root@localhost ~]# vim /etc/fstab 
/dev/sdb1 /new                     xfs     defaults        0 0
[root@localhost ~]# mkdir /new
[root@localhost ~]# mount -a
[root@localhost ~]# df -lh
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 2.0G     0  2.0G    0% /dev
tmpfs                    2.0G     0  2.0G    0% /dev/shm
tmpfs                    2.0G   13M  2.0G    1% /run
tmpfs                    2.0G     0  2.0G    0% /sys/fs/cgroup
/dev/mapper/centos-root   50G  5.4G   45G   11% /
/dev/mapper/centos-home  969G  801G  169G   83% /home
/dev/sda1               1014M  172M  843M   17% /boot
tmpfs                    394M   20K  394M    1% /run/user/0
/dev/sdb1                1.5T   33M  1.5T    1% /new
[root@localhost ~]# yum install cloud-utils-growpart
[root@localhost ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0     1T  0 disk 
├─sda1            8:1    0     1G  0 part /boot
└─sda2            8:2    0  1023G  0 part 
  ├─centos-root 253:0    0    50G  0 lvm  /
  ├─centos-swap 253:1    0   3.9G  0 lvm  [SWAP]
  └─centos-home 253:2    0 969.1G  0 lvm  /home
sdb               8:16   0    30G  0 disk 
└─sdb1            8:17   0    20G  0 part /home/mt
sr0              11:0    1  1024M  0 rom  
[root@localhost ~]# growpart /dev/sdb 1
unexpected output in sfdisk --version [sfdisk,来自 util-linux 2.23.2]
[root@localhost ~]# echo $?
2
[root@localhost ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0     1T  0 disk 
├─sda1            8:1    0     1G  0 part /boot
└─sda2            8:2    0  1023G  0 part 
  ├─centos-root 253:0    0    50G  0 lvm  /
  ├─centos-swap 253:1    0   3.9G  0 lvm  [SWAP]
  └─centos-home 253:2    0 969.1G  0 lvm  /home
sdb               8:16   0    30G  0 disk 
└─sdb1            8:17   0    20G  0 part /home/mt
sr0              11:0    1  1024M  0 rom  
[root@localhost ~]# LANG=en_US.UTF-8
[root@localhost ~]# growpart /dev/sdb 1
CHANGED: partition=1 start=2048 old: size=41940992 end=41943040 new: size=62912479 end=62914527
[root@localhost ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0     1T  0 disk 
├─sda1            8:1    0     1G  0 part /boot
└─sda2            8:2    0  1023G  0 part 
  ├─centos-root 253:0    0    50G  0 lvm  /
  ├─centos-swap 253:1    0   3.9G  0 lvm  [SWAP]
  └─centos-home 253:2    0 969.1G  0 lvm  /home
sdb               8:16   0    30G  0 disk 
└─sdb1            8:17   0    30G  0 part /home/mt
sr0              11:0    1  1024M  0 rom  
[root@localhost mt]# xfs_growfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=1310656 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=5242624, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 5242624 to 7864059
[root@localhost mt]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 2.0G     0  2.0G    0% /dev
tmpfs                    2.0G     0  2.0G    0% /dev/shm
tmpfs                    2.0G   13M  2.0G    1% /run
tmpfs                    2.0G     0  2.0G    0% /sys/fs/cgroup
/dev/mapper/centos-root   50G  5.4G   45G   11% /
/dev/sda1               1014M  172M  843M   17% /boot
/dev/mapper/centos-home  969G  801G  169G   83% /home
tmpfs                    394M  4.0K  394M    1% /run/user/42
tmpfs                    394M   20K  394M    1% /run/user/0
/dev/sdb1                 30G  170M   30G    1% /home/mt