Avatar

Organizations

6 results for CentOS
  • 基于 CentOS 7

    让Linux系统与Windows系统之间,支持机器名访问,需要Linux安装NetBIOS。 而安装NetBIOS,不一定必须安装Samba,安装过程如下:

    安装库

    # 注意 这里并不会安装完整的samba
    $ yum install samba-winbind
    

    修改配置文件

    ; Nano /etc/nsswitch.conf
    ; add wins
    hosts:  files <wins> dns myhostname
    

    验证安装

    $ ll /etc/<lib|lib64>/libnss_winbind.so
    

    配置生效

    $ ldconfig
    

    配置服务

    $ systemctl start winbind
    $ systemctl status winbind
    

    参考

    wins netbios centos linux Created Wed, 23 Oct 2024 13:04:27 +0800
  • 安装

    $ yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
    
    # 安装服务端包
    $ yum install postgresql10-server postgresql10
    

    配置

    # 初始化数据库,设置自启动
    $ /usr/pgsql-10/bin/postgresql-10-setup initdb
    $ systemctl enable postgresql-10
    $ systemctl start postgresql-10
    
    # 设置防火墙规则
    $ iptables -A INPUT -p tcp -m tcp --dport 5432 -j ACCEPT              #开放Postgresql 5432端口
    
    $ service iptables save   # 保存防火墙规则
    

    配置远程访问

    # 切换至用户
    $ su - postgres
    
    ; ./10/data/postgres.conf
    - #listen_address
    + listen_address
    
    ; ./10/data/pg_hba.conf
    ; 允许所有IPv4地址
    + host all all 0.0.0.0/0 scram-sha-256
    

    登录数据库

    $ psql -U postgres
    
    -- 设置数据运行参数
    ALTER SYSTEM SET listen_addresses = '*';
    ALTER SYSTEM SET port = 5432;
    ALTER SYSTEM SET password_encryption = 'scram-sha-256';
    
    --  修改默认用户密码
    ALTER USER postgres with encrypted password '你的密码';
    
    -- 退出数据库
    \q
    
    -- 退出用户
    exit    
    

    重启服务

    systemctl restart postgresql-10
    
    postgresql centos Created Fri, 19 Jan 2024 13:37:15 +0800
  • 1、安装Composer镜像

    $ docker pull composer:1.9.0
    

    2、安装laravel

    # 启动Composer镜像
    $ docker run --rm \
                    -it \
                    -v ${PWD}:/app \
                    composer:1.9.0 /bin/bash
    
    # 创建composer.json文件
    $ composer init -n
    
    # 使用国内 Packagist镜像
    $ composer config repo.packagist composer https://mirrors.aliyun.com/composer/
    
    # 添加laravel包
    $ composer require -vvv \
                        --prefer-dist \
                        --prefer-stable \
                        laravel/installer
    
    # 看到以下输出,说明添加成功。
    Writing lock file
    Generating autoload files
    
    # 在当前目录覆盖安装laravel
    $ ./vendor/bin/laravel new
    
    # 看到以下输出,说明安装成功。
    Package manifest generated successfully.
    Application ready! Build something amazing.
    
    # 退出Composer镜像
    $ exit  
    

    将当前目录下的storage目录权限,设为757

    php docker centos laravel Created Fri, 19 Jan 2024 13:26:15 +0800
  • 使用Hyper-V安装CentOS虚拟机,使用起来非常方便。但遇到磁盘空间不够时,不像Windows虚拟机那样方便给磁盘空间扩容。 总体两分二步:

    1. vhdx扩容

    关闭虚拟机,然后给磁盘扩容,操作方便网上教程多,这里不再赘述。

    2. CentOS扩容

    2.1 查看分区表

    $ lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0   20G  0 disk 
    ├─sda1            8:1    0  200M  0 part /boot/efi
    ├─sda2            8:2    0    1G  0 part /boot
    └─sda3            8:3    0  8.8G  0 part 
      ├─centos-root 253:0    0  7.8G  0 lvm  /
      └─centos-swap 253:1    0    1G  0 lvm  [SWAP]
    

    以上内容可以看出,sda已经扩容到20G,但sda1+sda2+sda3只有10G说明vhdx扩容成功。

    2.2 建立新分区

    $ fdisk /dev/sda
    
    The device presents a logical sector size that is smaller than
    the physical sector size. Aligning to a physical sector (or optimal
    I/O) size boundary is recommended, or performance may be impacted.
    欢迎使用 fdisk (util-linux 2.23.2)
    更改将停留在内存中,直到您决定将更改写入磁盘。
    使用写入命令前请三思。
    
    
    命令(输入 m 获取帮助):n
    Partition type:
       p   primary (1 primary, 0 extended, 3 free)
       e   extended
    Select (default p): 
    Using default response p
    分区号 (2-4,默认 2)起始 扇区 (20971520-41943039,默认为 20971520)将使用默认值 20971520
    Last 扇区, +扇区 or +size{K,M,G} (20971520-41943039,默认为 41943039):+10G
    值超出范围。
    Last 扇区, +扇区 or +size{K,M,G} (20971520-41943039,默认为 41943039):+9.9G
    不支持的后缀:“.9G”。
    支持:10^N: KB (千字节), MB (兆字节), GB (吉字节)
                2^N: K  (约千字节), M  (约兆字节), G  (约吉字节)
    Last 扇区, +扇区 or +size{K,M,G} (20971520-41943039,默认为 41943039):+9G 
    分区 2 已设置为 Linux 类型,大小设为 9 GiB
    
    命令(输入 m 获取帮助):w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    正在同步磁盘。
    

    重读分区表时,发生错误

    $ partprobe
    Error: 备份 GPT 表不像应该的那样出现在磁盘的末尾。这可能意味这其它操作系统相信磁盘小一些。通过将备份移动到末尾 (并删除旧备份) 来修正?
    Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 20971520 blocks) or continue with the current setting? 
    

    查看分区表时,发现新分区未创建成功

    $ lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0   20G  0 disk 
    ├─sda1            8:1    0  200M  0 part /boot/efi
    ├─sda2            8:2    0    1G  0 part /boot
    └─sda3            8:3    0  8.8G  0 part 
      ├─centos-root 253:0    0  7.8G  0 lvm  /
      └─centos-swap 253:1    0    1G  0 lvm  [SWAP]
    

    使用 parted 修复分区表

    $ parted /dev/sda
    GNU Parted 3.1
    使用 /dev/sda
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) p                                                                
    错误: 备份 GPT 表不像应该的那样出现在磁盘的末尾。这可能意味这其它操作系统相信磁盘小一些。通过将备份移动到末尾 (并删除旧备份) 来修正?
    修正/Fix/忽略/Ignore/放弃/Cancel? fix                                     
    警告: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 20971520 blocks) or continue with the current
    setting? 
    修正/Fix/忽略/Ignore? fix                                                 
    Model: Msft Virtual Disk (scsi)
    Disk /dev/sda: 21.5GB
    Sector size (logical/physical): 512B/4096B
    Partition Table: gpt
    Disk Flags: 
    
    Number  Start   End     Size    File system  Name                  标志
     1      1049kB  211MB   210MB   fat16        EFI System Partition  启动
     2      211MB   1285MB  1074MB  xfs
     3      1285MB  10.7GB  9452MB                                     lvm
    
    (parted) p                                                                
    Model: Msft Virtual Disk (scsi)
    Disk /dev/sda: 21.5GB
    Sector size (logical/physical): 512B/4096B
    Partition Table: gpt
    Disk Flags: 
    
    Number  Start   End     Size    File system  Name                  标志
     1      1049kB  211MB   210MB   fat16        EFI System Partition  启动
     2      211MB   1285MB  1074MB  xfs
     3      1285MB  10.7GB  9452MB                                     lvm
    
    (parted) quit                                                             
    

    再次建立新分区

    $ fdisk /dev/sda
    WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
    欢迎使用 fdisk (util-linux 2.23.2)
    更改将停留在内存中,直到您决定将更改写入磁盘。
    使用写入命令前请三思。
    
    
    命令(输入 m 获取帮助):n
    分区号 (4-128,默认 4)第一个扇区 (34-41943006,默认 20969472)Last sector, +sectors or +size{K,M,G,T,P} (20969472-41943006,默认 41943006):+10G
    已创建分区 4
    
    
    命令(输入 m 获取帮助):w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    正在同步磁盘。
    

    2.3 重读分区表

    $ partprobe
    

    重读分区表,正常不会有任何输出

    CentOS Hyper-V windows Created Mon, 26 Dec 2022 21:01:32 +0800
  • 其实网上相关的文章已经非常多了,所以这篇文章的作用只是记录和明确一条确定可行的操作路径,为以后的操作节省时间,毕竟像我一样大部分人都不是专业的系统管理员,能够快速解决问题就可以了,并不想做过多的专业研究与探索。

    本操作手册是官方手册与网上手册的结合版本,集两家之所长,亲自操作可用。

    Debian

    # 安装 Docker 证书
    sudo apt-get install -y ca-certificates curl
    sudo install -m 0755 -d /etc/apt/keyrings
    sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
    sudo chmod a+r /etc/apt/keyrings/docker.asc\
    sudo echo
          "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian
          $(. /etc/os-release && echo "$VERSION_CODENAME") stable" |
          sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    sudo apt-get update
    
    # 安装 Docker
    sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    
    # 启动 Docker
    sudo systemctl enable docker.service
    sudo systemctl start docker.service
    
    # 测试
    sudo docker version
    > Client: Docker Engine - Community
    > ...
    > Server: Docker Engine - Community
    > ...
    sudo docker compose version
    > Docker Compose version v...
    
    # 使用非 root 用户管理 Docker
    # 创建 docker 用户组
    sudo groupadd docker
    # 将当前用户添加到 docker 用户组
    sudo usermod -aG docker $USER
    # 重启
    # 再次测试
    docker version
    > Client: Docker Engine - Community
    > ...
    > Server: Docker Engine - Community
    > ...
    docker compose version
    > Docker Compose version v...
    

    CentOS | Rocky

    # 查看系统版本
    cat /etc/redhat-release
    > CentOS Linux release 7.6.1810 (Core) // CentOs 7 以上版本
    
    # 查看系统内核版本
    uname -r
    > 4.10.4-1.el7.elrepo.x86_64 // 内核版本要>3.10
    
    # 卸载旧版本
    yum remove docker
                docker-client
                docker-client-latest
                docker-common
                docker-latest
                docker-latest-logrotate
                docker-logrotate
                docker-selinux
                docker-engine-selinux
                docker-engine
    
    # 安装依赖包
    yum install -y yum-utils lvm2
                    device-mapper-persistent-data
    
    # 添加 Docker 软件源
    # 如果系统已切换到阿里云镜像源地址,可跳过此步。
    # 阿里云镜像自带docker源
    yum-config-manager
        --add-repo
        https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
    
    # 使用官方源
    yum-config-manager
        --add-repo
        https://download.docker.com/linux/centos/docker-ce.repo
    
    yum makecache fast
    # CentOS 8 or Rocky 9 使用timer替换fast
    yum makecache timer
    
    # 安装 Docker
    # 如果在 Rocky 9 系统上,会提示containerd.io版本过低,或下载失败,需要独立安装containerd.io
    # 可以重试几次
    yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
    
    # 启动 Docker
    # 设为开机启动
    systemctl enable docker.service
    # 启动服务
    systemctl start docker.service
    
    # 测试
    docker run hello-world
    > Unable to find image 'hello-world:latest' locally
    > latest: Pulling from library/hello-world
    > 1b930d010525: Pull complete
    > Digest: sha256:6540fc08ee6e6b7b63468dc3317e3303aae178cb8a45ed3123180328bcc1d20f
    > Status: Downloaded newer image for hello-world:latest
    > 
    > Hello from Docker!
    > This message shows that your installation appears to be working correctly.
    > 
    > To generate this message, Docker took the following steps:
    >  1. The Docker client contacted the Docker daemon.
    >  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    >     (amd64)
    >  3. The Docker daemon created a new container from that image which runs the
    >     executable that produces the output you are currently reading.
    >  4. The Docker daemon streamed that output to the Docker client, which sent it
    >     to your terminal.
    > 
    > To try something more ambitious, you can run an Ubuntu container with:
    >  docker run -it ubuntu bash
    > 
    > Share images, automate workflows, and more with a free Docker ID:
    >  https://hub.docker.com/
    > 
    > For more examples and ideas, visit:
    >  https://docs.docker.com/get-started/
    
    docker compose version
    > Docker Compose version v...
    

    若能正常输出以上信息,则说明安装成功。

    linux CentOS Debian rocky Docker Created Fri, 06 May 2022 11:05:23 +0800
  • APT

    Debian 全球镜像站

    查找延迟最小的镜像

    sudo apt install -y netselect-apt \
        && sudo netselect-apt \
        && sudo apt autoremove -y netselect-apt \
        && rm -f sources.list
    
    The fastest 10 servers seem to be:
    
            http://mirrors.bfsu.edu.cn/debian/
            http://mirrors.tuna.tsinghua.edu.cn/debian/
            http://mirrors.neusoft.edu.cn/debian/
            http://mirrors.jlu.edu.cn/debian/
            http://ftp.cn.debian.org/debian/
            http://debian.cs.nycu.edu.tw/debian/
            http://mirror.i3d.net/debian/
            http://mirrors.163.com/debian/
            http://mirror.bizflycloud.vn/debian/
            http://ftp.kaist.ac.kr/debian/
    
    Of the hosts tested we choose the fastest valid for http:
            http://mirrors.bfsu.edu.cn/debian/
    
    Writing sources.list.
    Done.
    

    修改仓库

    # PVE QEMU debian-12-generic-amd64.qcow2
    # echo 'http://mirrors.bfsu.edu.cn/debian/' | sudo tee /etc/apt/mirrors/debian.list
    # echo 'http://mirrors.bfsu.edu.cn/debian-security/' | sudo tee -a /etc/apt/mirrors/debian-security.list
    sed -i -e "s/deb.debian.org/mirrors.bfsu.edu.cn/" /etc/apt/mirrors/debian.list
    sed -i -e "s/deb.debian.org/mirrors.bfsu.edu.cn/" /etc/apt/mirrors/debian-security.list
    
    # PVE LXC debian-12-standard_12.7-1_amd64.tar.zst
    sed -i -e "s/deb.debian.org/mirrors.bfsu.edu.cn/" /etc/apt/sources.list
    sed -i -e "s/security.debian.org/mirrors.bfsu.edu.cn\/debian-serurity/" /etc/apt/sources.list
    
    # Docker imaage debian:12
    sed -i -e "s/deb.debian.org/mirrors.bfsu.edu.cn/" /etc/apt/sources.list.d/debian.sources
    
    # update    
    apt update
    

    YUM

    查询仓库

    yum repolist
    # 显示所有仓库
    yum repolist all
    # 显示所有启动的仓库
    yum repolist enabled
    # 显示所有禁用的仓库
    yum repolist disabled
    

    修改仓库

    最常用的修改操作就是启动和停用, 可以使用以下命令实现:

    CentOS debian repo yum apt Created Tue, 08 Feb 2022 10:28:50 +0800