跳到主要内容

CentOS7操作备忘

以下所有操作在CentOS7.9.2009_x64平台上测试有效

换源

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.163.com/.help/CentOS7-Base-163.repo
yum clean all
yum makecache

启用EPEL源

yum -y install epel-release

更新系统

yum -y update

关闭SELinux

vi /etc/selinux/config

SELINUX=disabled

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

即时生效

setenforce 0

安装常用工具包

yum -y install yum-utils wget htop unzip screen git vim nano redhat-lsb net-tools curl lsof

安装常用编译依赖包

yum -y install build-essential gcc gcc-c++ gdb automake autoconf libtool make zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel kernel-devel

常用防火墙命令

封锁端口

firewall-cmd --zone=public --remove-port=10000/tcp --permanent 

放行端口

firewall-cmd --zone=public --permanent --add-port=28000/tcp 

重载防火墙

firewall-cmd --reload

查看放行端口

firewall-cmd --zone=public --list-ports

安装screenfetch

原地址:https://git.io/vaHfR (部分服务器无法下载)

curl -o /bin/screenfetch https://fastly.jsdelivr.net/gh/KittyKatt/screenFetch@master/screenfetch-dev && chmod +x /bin/screenfetch

安装perl

yum -y install perl perl-Net-SSLeay openssl perl-IO-Tty perl-Encode-Detect perl-Data-Dumper

安装java

yum -y install java-latest-openjdk java-latest-openjdk-devel

安装webmin

vi /etc/yum.repos.d/webmin.repo

[Webmin] name=Webmin Distribution Neutral #baseurl=https://download.webmin.com/download/yum mirrorlist=https://download.webmin.com/download/yum/mirrorlist enabled=1 gpgkey=https://download.webmin.com/jcameron-key.asc gpgcheck=1

wget https://download.webmin.com/jcameron-key.asc
rpm --import jcameron-key.asc
rm -f jcameron-key.asc
yum -y install webmin

修改web端口

vim /etc/webmin/miniserv.conf
sed -i 's/port=10000/port=18000/g' /etc/webmin/miniserv.conf

port=18000

service webmin restart

安装nps服务器

mkdir -p /home/installer/nps
cd /home/installer/nps
wget https://download.fastgit.org/ehang-io/nps/releases/download/v0.26.10/linux_amd64_server.tar.gz
tar -xvf linux_amd64_server.tar.gz
cd ./conf
vim ./nps.conf

修改用户名密码等信息

./nps install
cd ..
rm -rf /home/installer

安装openssl1.1.1l

mkdir /home/openssl
cd /home/openssl
wget https://www.openssl.org/source/openssl-1.1.1l.tar.gz
tar -xvf openssl-1.1.1l.tar.gz
cd openssl-1.1.1l
./config --prefix=/usr/local/openssl
make -j4
make install

mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/lib64/openssl /usr/lib64/openssl.old
mv /usr/lib64/libssl.so /usr/lib64/libssl.so.old
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/lib/libssl.so /usr/lib64/libssl.so
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig -v

openssl version

安装emqx

yum -y install yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://repos.emqx.io/emqx-ce/redhat/centos/7/emqx-ce.repo
yum -y install emqx
emqx start

安装MCSManager

cd /opt
git clone https://hub.fastgit.org/Suwings/MCSManager.git
cd mcsmanager/
npm install

启动一次以创建配置文件并以自己需求配置

npm start
vim ./property.js

写入系统服务

# 使用which node查看node路径
which node
vim /lib/systemd/system/mcsm.service

[Unit] Description=MCSManager

[Service] ExecStart=/usr/local/bin/node /opt/MCSManager/app.js Restart=always Environment=PATH=/usr/bin:/usr/local/bin:/usr/local/node/bin Environment=NODE_ENV=production WorkingDirectory=/opt/MCSManager/

[Install] WantedBy=multi-user.target

systemctl start mcsm
systemctl status mcsm
systemctl enable mcsm

安装Redis

yum -y install http://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm \
&& yum --enablerepo=remi -y install redis \
&& systemctl enable --now redis

screen基础操作

创建一个

-A  将所有的视窗都调整为目前终端机的大小。
-d<作业名称>  将指定的screen作业离线。
-h<行数>  指定视窗的缓冲区行数。
-m  即使目前已在作业中的screen作业,仍强制建立新的screen作业。
-r<作业名称>  恢复离线的screen作业。
-R  先试图恢复离线的作业。若找不到离线的作业,即建立新的screen作业。
-s<shell>  指定建立新视窗时,所要执行的shell。
-S<作业名称>  指定screen作业的名称。
-v  显示版本信息。
-x  恢复之前离线的screen作业。
-ls或--list  显示目前所有的screen作业。
-wipe  检查目前所有的screen作业,并删除已经无法使用的screen作业。

调整cpu性能策略

performance 运行于最大频率 powersave 运行于最小频率 userspace 运行于用户指定的频率 ondemand 按需快速动态调整CPU频率, 一有cpu计算量的任务,就会立即达到最大频率运行,空闲时间增加就降低频率 conservative 按需快速动态调整CPU频率, 比 ondemand 的调整更保守 schedutil 基于调度程序调整 CPU 频率

yum install -y cpupowerutils
cpupower frequency-info
grep "cpu MHz" /proc/cpuinfo
cpupower frequency-set -g performance
grep "cpu MHz" /proc/cpuinfo

安装CloudCMD

npm install -g bufferutil \
&& npm install -g utf-8-validate \
&& npm install -g gritty \
&& npm install -g cloudcmd
ln -s /usr/local/nodejs/bin/cloudcmd /usr/local/bin
cloudcmd --save --no-server --username root --password 123456 --auth --show-file-name --packer tar --root / --port 28000 --confirm-copy --confirm-move --name "ddi Server" --keys-panel --console --terminal --terminal-path "/usr/bin/gritty" --no-terminal-command --log --no-online --no-open --no-one-file-panel --no-contact --sync-console-path --no-dropbox --columns "name-size-date"
cloudcmd
vim /etc/systemd/system/cloudcmd.service

[Unit] Description = Cloud Commander

[Service] TimeoutStartSec = 0 Restart = always ExecStart = /usr/bin/cloudcmd User = root

[Install] WantedBy = multi-user.target

systemctl enable --now cloudcmd

安装Supervisor

需要python

pip3 install supervisor
ln -s /usr/local/python3/bin/echo_supervisord_conf /usr/bin/echo_supervisord_conf
ln -s /usr/local/python3/bin/supervisord /usr/bin/supervisord
ln -s /usr/local/python3/bin/supervisorctl /usr/bin/supervisorctl
mkdir /etc/supervisor
mkdir /home/supervisor_conf
echo_supervisord_conf > /etc/supervisor/supervisord.conf
vim /etc/supervisor/supervisord.conf
vim /usr/lib/systemd/system/supervisord.service
# supervisord service for systemd (CentOS 7.0+)

[Unit]
Description=Supervisor daemon

[Service]
Type=forking
ExecStart=/usr/bin/supervisord
ExecStop=/usr/bin/supervisorctl -c /etc/supervisor/supervisord.conf shutdown
ExecReload=/usr/bin/supervisorctl -c /etc/supervisor/supervisord.conf reload
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target