标签: Centos

CentOS7.9.2009换源:换阿里云镜像源

1、下载CentOS 7的repo文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

2、更新镜像源
清除缓存:
yum clean all
生成缓存:
yum makecache


完整repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever – Base – mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever – Updates – mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever – Extras – mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever – Plus – mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#contrib – packages by Centos Users
[contrib]
name=CentOS-$releasever – Contrib – mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/a772304419/article/details/132147343

CentOS配置firewalld防火墙规则

firewall-cmd命令参数介绍

firewall-cmd –xx-
参数 功能
--get-default-zone 查询当前默认的区域名称
--set-default-zone=区域名称 设置默认的区域并使其永久生效
--get-zones 显示可用的区域
--get-services 显示命令支持的服务
--get-active-zones

显示当前正在使用的区域与网卡名称

Continue…

CentOS Stream 初始化

1、网络
IP设置:
/etc/NetworkManager/system-connections/*.nmconnection
nmcli命令可以配置此文件:
比如:
# nmcli connection modify ens192 +ipv4.routes “192.168.0.0/24 192.168.0.254, 192.168.2.0/24 192.168.0.254”
同:
route1=192.168.0.0/24,192.168.0.254
route2=192.168.2.0/24,192.168.0.254

2、时间
时区设置:
cd /etc
rm /etc/localtime -fr
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
hwclock –systohc
(同步硬件时间,无法使用NTP)

3、关闭SElinux
查看状态:/usr/sbin/sestatus -v
临时关闭SElinux: setenforce 0
永久关闭SElinux: vim /etc/selinux/config
SELINUX=disabled

4、修改SSH端口
启用SSH:默认启动
vim /etc/ssh/sshd_config
Port 22

5、关闭防火墙
关闭防火墙: systemctl stop firewalld
禁用防火墙: systemctl disable firewalld
查看防火墙状态: systemctl status firewalld

CentOS Stream 9安装PHP8.2

安装remi源

dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm

查看可以安装的PHP版本

dnf module list php
Remi's Modular repository for Enterprise Linux 9 - x86_64
Name      Stream        Profiles                        Summary
php       remi-7.4      common [d], devel, minimal      PHP scripting language
php       remi-8.0      common [d], devel, minimal      PHP scripting language
php       remi-8.1      common [d], devel, minimal      PHP scripting language
php       remi-8.2      common [d], devel, minimal      PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

启用PHP8.2版本

dnf module enable php:remi-8.2

安装PHP扩展

dnf install php-fpm php php-bcmath php-cli php-common php-gd php-imap php-mbstring php-mcrypt php-mysql php-mysqlnd php-pdo php-soap php-tidy php-xml php-xmlrpc php-opcache php-redis php-pecl-mcrypt -y

查看PHP版本

php -v
PHP 8.2.2 (cli) (built: Jan 31 2023 13:31:55) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.2, Copyright (c), by Zend Technologies

开启jit功能

cd /etc/php.d/

编辑扩展文件,在文件最后添加jit配置

vim 10-opcache.ini
opcache.jit_buffer_size=256M
opcache.jit=1255

重启PHP

systemctl restart php-fpm

查看jit是否开启成功

php -i|grep 'opcache.jit'
opcache.jit => 1255 => 1255
opcache.jit_bisect_limit => 0 => 0
opcache.jit_blacklist_root_trace => 16 => 16
opcache.jit_blacklist_side_trace => 8 => 8
opcache.jit_buffer_size => 256M => 256M
opcache.jit_debug => 0 => 0
opcache.jit_hot_func => 127 => 127
opcache.jit_hot_loop => 64 => 64
opcache.jit_hot_return => 8 => 8
opcache.jit_hot_side_exit => 8 => 8
opcache.jit_max_exit_counters => 8192 => 8192
opcache.jit_max_loop_unrolls => 8 => 8
opcache.jit_max_polymorphic_calls => 2 => 2
opcache.jit_max_recursive_calls => 2 => 2
opcache.jit_max_recursive_returns => 2 => 2
opcache.jit_max_root_traces => 1024 => 1024
opcache.jit_max_side_traces => 128 => 128
opcache.jit_prof_threshold => 0.005 => 0.005

设置PHP开机自启

systemctl enable php-fpm

转自:https://www.ggdoc.cn/archives/302

CentOS 添加新硬盘

一、添加新硬盘,查看硬盘情况
输入fdisk -l 查看系统磁盘,查看到/dev/sdb 为新添加的100G磁盘

二、对新添加的硬盘进行分区
2.1 fdisk /dev/sdb
2.2 输入n 新建硬盘分区
2.3 输入p 建立主分区(如输入e 表示建立扩展分区) 回车
2.4 输入分区号1-4, 默认为1 回车
2.5 输入起始扇区数,默认2048 按回车确认
2.6 按q 退出

三、格式化新添加的硬盘
3.1 mkfs -t ext4 /dev/sdb #将硬盘格式化为 ext4 格式
3.2 按y回车确认,格式化完成

四、挂载新硬盘
4.1 mkdir -p /mnt/dev1 #在/mnt 下创建一个目录 用于挂载新硬盘(创建目录路径根据自己需求自定义)
4.2 mount /dev/sdb /mnt/dev1 #将/dev/sdb 硬盘挂载到/mnt/dev1 目录下

五、查看新硬盘挂载情况
df -h

六、取消硬盘挂载
umount /dev/sdb #取消硬盘挂载,如想挂载到其他目录,重复步骤五

七、设置开机自动挂载
vim /etc/fstab 添加 /dev/sdb /mnt/dev1 ext4 defaults 0 1

Centos安装unrar并使用

https://www.rarlab.com/download.htm

wget https://www.rarlab.com/rar/rarlinux-x64-6.0.2.tar.gz
解压安装包到指定目录
tar xf rarlinux-x64-6.0.2.tar.gz -C /usr/local/
创建软连接
ln -s /usr/local/rar/rar /usr/local/bin/rar
ln -s /usr/local/rar/unrar /usr/local/bin/unrar

常用命令解压压缩文件到当前目录

unrar e test.rar
用绝对路径解压文件

unrar x test.rar
列出压缩包中的文件列表信息(简单)

unrar l test.rar
列出压缩包中的文件列表信息(详细)

unrar v test.rar
测试压缩文件


如果运行没问题则证明安装成功,如果报Couldn’t find path to unrar library则还需要系统编译安装unrar

安装依赖包
yum install -y gcc gcc-c++
下载unrar包
wget http://www.rarlab.com/rar/unrarsrc-5.4.5.tar.gz
tar zxf unrarsrc-5.4.5.tar.gz
cd unrar
编译、安装
make lib
make install-lib
使用make lib命令将会自动编译库文件,再使用make install-lib命令产生 libunrar.so 文件(一般在 /usr/lib 目录下面)

配置环境变量
vim /etc/profile
在末尾加上以下语句并保存
export UNRAR_LIB_PATH=/usr/lib/libunrar.so
使用以下命令使变量生效
source /etc/profile
再次执行第二步就不会报错了

原文链接:https://blog.csdn.net/qq_15603633/article/details/118731452

Linux安装Oracle11G

安装Oracle 11g依赖包

#yum -y install gcc make binutils gcc-c++ compat-libstdc++-33 elfutils-libelf-devel elfutils-libelf-devel-static elfutils-libelf-devel ksh libaio libaio-devel numactl-devel sysstat unixODBC unixODBC-devel pcre-devel

Continue…

CentOS7配置SSH 限制IP登录

环境:CentOS 7.0
引用:
https://blog.csdn.net/qq_34886247/article/details/81351175

方法一:
首先需要限制登录的ip(外网ip)
XXX为外网IP
Vim /etc/hosts.allow
输入

sshd:XXX.XXX.XXX.XXX:allow
vim /etc/hosts.deny
输入(表示除了上面允许的,其他的ip 都拒绝登陆ssh)

sshd:ALL
最后sshd重启
 /bin/systemctl restart sshd.service

方法二:
比如说你只允许XXX.XXX.XXX.XXX这个IP进入,其它都禁止:
vim /etc/ssh/sshd_config
添加一行:
allowusers xxx@XXX.XXX.XXX.XXX
注:xxx为你用来登入服务器的用户名

最后sshd重启

 /bin/systemctl restart sshd.service

CentOS安装、配置Nginx反向代理

https://www.cnblogs.com/xiaonangua/p/9176137.html

  • 添加Nginx存储库  sudo yum install epel-release
  • 安装Nginx  sudo yum install nginx
  • 启动Nginx  sudo systemctl start nginx
  • 如果正在运行防火墙,运行以下命令以允许HTTP和HTTPS通信
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --permanent --zone=public --add-port=8530/tcp
sudo firewall-cmd --reload
  • 在系统启动时启用Nginx    sudo systemctl enable nginx
  • 配置Nginx   ‘/etc/nginx/nginx.conf’
 server {
     listen        80;
     server_name   a.xxx.com aa.xxx.com;
     include /etc/nginx/default.d/*.conf;
     location / {
         proxy_pass         http://192.168.0.139:80;
         proxy_http_version 1.1;
         proxy_set_header   Upgrade $http_upgrade;
         proxy_set_header   Connection keep-alive;
         proxy_set_header   Host $http_host;
         proxy_cache_bypass $http_upgrade;
     }
 }

service nginx start

service nginx reload