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

[bash]systemctl start nginx.service[/bash]

To view current status of a service:

[bash]systemctl status nginx.service[/bash]

To enable a service at startup:

[bash]systemctl enable nginx.service[/bash]

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

[bash]yum install net-tools[/bash]

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:

[bash]yum install -y policycoreutils-python[/bash]

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

[bash]semanage port -l | grep ssh[/bash]

. We can add a new port

[bash]semanage port -a -t ssh_port_t -p tcp 777[/bash]

or we can also add it to firewall as follows:

[bash]firewall-cmd –permanent –zone=public –add-port=777/tcp[/bash]

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

Next, restart the SSH service:

[bash]systemctl restart sshd.service[/bash]

FInally, disable linux firewall:

[bash]systemctl stop firewalld
systemctl disable firewalld[/bash]

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

[bash]chcon -R -t httpd_sys_content_t /home[/bash]

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:
[bash][[email protected] ~]# 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

[[email protected] ~]# 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][/bash]

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
[bash]resize2fs /dev/vda1[/bash]
and all will be set.

Leave a Reply