--- title: "Centos部署笔记" date: 2019-09-12T20:50:05+08:00 draft: false toc: true images: tags: [centos] categories: server --- 本文记录笔记全部基于CentOS7版本。 ## 系统安装 ### 权限控制和分区 - 登录报错`-- lniwn: /home/lniwn: change directory failed: Permission denied Logging in with /home="/".` 首先确认权限: ```shell chown -R lniwn:lniwn /home/lniwn chmod -R 700 /home/lniwn ``` 然后确认SELinux配置,恢复文件上下文: ```shell restorecon -R /home ``` - 挂载/home分区到指定的磁盘 ```shell # 分区 parted select /dev/sdb1 # 切换磁盘 mklabel gpt # 创建分区表 mkpart extended 1 100% # 分区 mkfs.ext4 /dev/sdb1 # 格式化磁盘 print # 打印当前分区概况 exit # /home转移 mkdir -p /srv/home mount /dev/sdb1 /srv/home cp -aR /home/* /srv/home/ diff -r /home /srv/home rm -rf /home/* umount /srv/home mount /dev/sdb1 /home # 开机自动挂载 blkid /dev/sdb1 # 编辑/etc/fstab文件,添加如下行 UUID=e087e709-20f9-42a4-a4dc-d74544c490a6 /home ext4 defaults 0 2 ``` > - **UUID** – specifies the block device, you can alternatively use the device file **/dev/sdb1**. > - **/home** – this is the mount point. > - **etx4** – describes the filesystem type on the device/partition. > - **defaults** – mount options, (here this value means rw, suid, dev, exec, auto, nouser, and async). > - **0** – used by dump tool, 0 meaning don’t dump if filesystem is not present. > - **2** – used by fsck tool for discovering filesystem check order, this value means check this device after root filesystem. - 关闭SELinux 检查状态 ```shell sestatus ``` 禁用 ```shell setenforce 0 ``` 编辑文件`/etc/selinux/config`,将`SELINUX`值修改为`disabled`。 重启系统生效。 ### SSH默认端口修改 - 修改sshd默认端口 打开配置文件`vim /etc/ssh/sshd_config` 修改端口号`Port 12456` 防火墙增加端口白名单 ```shell firewall-cmd --zone=public --add-port 123456/tcp --permanent ``` 刷新防火墙配置`firewall-cmd --reload` 重启sshd服务`systemctl restart sshd` 切记:*使用新端口正常连接后,再断开原有的连接,否则可能会永远连不上ssh了* ### 启动模式修改 - 切换GUI和CLI启动模式 ```shell systemctl set-default multi-user.target ``` ```shell systemctl set-default graphical.target ``` 获取当前启动模式`systemctl get-default` 从CLI启动图形界面`startx` - 配置启动时自动连接网络 ```shell cd /etc/sysconfig/network-scripts/ sed -i -e 's@^ONBOOT="no@ONBOOT="yes@' ifcfg-eth0 ``` ## 应用安装 ### mongodb安装 官方安装文档