CentOS 7 workaround

centos7Switching from CentOS 6 to CentOS 7 might be a little pain for many users. The main reason is that in CentOS 7, there are several changes which make the end-users feel not comfortable.  This quick note will introduce some new way to do some regular commands in CentOS 7.

1. Using systemctl

In CentOS 6, you can use service nginx start but in CentOS 7, you must use

systemctl start nginx.service

To view current status of a service:

systemctl status nginx.service

To enable a service at startup:

systemctl enable nginx.service

2. No ifconfig by default

ifconfig is used for getting common network information. In addition, it is used in csf firewall. We can install it by

yum install net-tools

3. Changing SSH port

In CentOS 6, changing SSH port is a trivial work which we can simply edit the /etc/ssh/sshd_config file. However, in CentOS 7, we must also make change in SELinux.

First, install semanage:

yum install -y policycoreutils-python

Then, we can see the current SSH port in SELinux with

semanage port -l | grep ssh

. We can add a new port

semanage port -a -t ssh_port_t -p tcp 777

or we can also add it to firewall as follows:

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

. We then also need to change the SSH port in /etc/ssh/sshd_config to this new port.

Next, restart the SSH service:

systemctl restart sshd.service

FInally, disable linux firewall:

systemctl stop firewalld
systemctl disable firewalld

4. Using CSF firewall

As mentioned in the previous point, we must

  • Install ifconfig command
  • Disable linux firewall
  • Change SELinux if necessary

5. Default Webroot folder

Due to SELinux, if we need to set the webroot folder from /home/website/, we must clearly specify it with

chcon -R -t httpd_sys_content_t /home

6. Only less space (2G) in disk partion

In some OS image, the OS only has a very small partition. In my case, it has only 2G in / while the SSD disksize is 120G. Checking with it:

[root@TEST ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1       2.0G  1.9G     0 100% /
devtmpfs        3.9G     0  3.9G   0% /dev
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           3.9G   25M  3.8G   1% /run
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
tmpfs           783M     0  783M   0% /run/user/0

[root@TEST ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1 1024M  0 rom  
vda    253:0    0  120G  0 disk 
├─vda1 253:1    0  116G  0 part /
└─vda2 253:2    0    4G  0 part [SWAP]

In this case, as disk is mounted, and /dev/vda1 should has 116G instead of only 2G (4G is for SWAP). So to solve this, simply use

resize2fs /dev/vda1

and all will be set.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *