OpenShift CLI

OpenShift CLI: oc

The OpenShift CLI “oc” can be installed on your computer, see Get Started with the CLI. Before issuing an oc command, you must login to the OpenShift master with oc login. It will ask for an URL to the master (if started for the first time) and for a username and password.

  • oc whoami
    If you can’t remember who you are, this tells it to you.
  • oc project $NAME
    Shows the currently active project to which all commands are run against. If a project ame is added to the command then the currently active project changes.
  • oc get projects
    Displays a list of projects to which the current user has access to
  • oc status
    Status overview of the current project
  • oc describe $TYPE $NAME
    Detailed information about an object.oc describe pod drupal-openshift-1-m3uvx
  • oc get event
    Shows all events in the current project. Very useful for finding out what happened.
  • oc logs [-f] $PODNAME
    Show the logs of a running pod. With -f it tails the log much like tail -f.
  • oc get pod [-w]
    List of pods in the current project. With -w it shows changes in pods. Note: watch oc get pod is a helpful way to watch for pod changes
  • oc rsh $PODNAME
    Start a remote shell in the running pod to execute commands
  • oc exec $PODNAME $COMMAND
    Execute a command in the running pod. The command’s output is sent to your shell.
  • oc delete events –all
    Cleanup all events. Useful if there are a lot of old events. Events are information about what is going on on the API objects and what problems exist (if there are any).
  • oc get builds
    List of builds. A build is a process of creating runnable images to be used on OpenShift.

oc logs build/$BUILDID
Build log of the build with the id “buildid”. This corresponds to the list of builds which are displayed with the command above.

MySql – Manage users and privileges

Use the instructions in this section to add users for the database and grant and revoke privileges.

Add users and privileges

When applications connect to the database using the root user, they usually have more privileges than they need. You can create a new user that applications can use to connect to the new database. In the following example, a user named demouser is created.

To create a new user, run the following command in the mysql shell:

mysql>CREATE USER ‘demouser‘@’localhost’ IDENTIFIED BY ‘demopassword‘;

You can verify that the user was created by running a SELECT query again:

SELECT User, Host, Password FROM mysql.user;
| User | Host | Password |
| root | localhost | 2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| root | demohost | 2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| root | | 2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| demouser | localhost | 0756A562377EDF6ED3AC45A00B356AAE6D3C6BB6 |

Grant database user privileges

Right after you create a new user, it has no privileges. The user can be used to log in to MySQL, but it can’t be used to make any database changes.

Give the user full privileges for your new database by running the following command:

GRANT ALL PRIVILEGES ON demodb.* to demouser@localhost;

Flush the privileges to make the change take effect.

Mysql> Flush Privileges

To verify that the privileges were set, run the following command:

SHOW GRANTS FOR ‘demouser‘@’localhost’;

MySQL returns the commands needed to reproduce that user’s privileges if you were to rebuild the server. The USAGE on \*.\* part means that the user gets no privileges on anything by default. That command is overridden by the second command, which is the grant you ran for the new database.

| Grants for demouser@localhost |
| GRANT USAGE ON *.* TO ‘demouser’@’localhost’ IDENTIFIED BY PASSWORD ‘*0756A562377EDF6ED3AC45A00B356AAE6D3C6BB6’ |
| GRANT ALL PRIVILEGES ON `demodb`.* TO ‘demouser’@’localhost’ |
2 rows in set (0.00 sec)

Revoke privileges

Sometimes you might need to revoke (remove) privileges from a user. For example: suppose that you were granting ALL privileges to ‘demouser’@’localhost’, but you accidentally granted privileges to all other databases, too:

+——————————————————————————————–+ | Grants for demouser@localhost | +——————————————————————————————–+ | GRANT USAGE ON *.* TO ‘demouser’@’localhost’ IDENTIFIED BY PASSWORD ‘*0756A562377EDF6ED3AC45A00B356AAE6D3C6BB6’ | | GRANT ALL PRIVILEGES ON *.* TO ‘demouser’@’localhost’ | +——————————————————————————————–+ 2 rows in set (0.00 sec)

To correct the mistake, you can use a REVOKE statement, followed by GRANT statement to apply the correct privileges.

REVOKE ALL ON *.* FROM demouser@localhost; GRANT ALL PRIVILEGES ON demodb.* to demouser@localhost; SHOW GRANTS FOR ‘demouser’@’localhost’; +——————————————————————————————–+ | Grants for demouser@localhost | +——————————————————————————————–+ | GRANT USAGE ON *.* TO ‘demouser’@’localhost’ IDENTIFIED BY PASSWORD ‘*0756A562377EDF6ED3AC45A00B356AAE6D3C6BB6’ | | GRANT ALL PRIVILEGES ON ‘demodb’TO ‘demouser’@’localhost’ | +——————————————————————————————–+ 2 rows in set (0.00 sec)

Now your user has the correct privileges, and therefore your database server is slightly more secure (granting privileges like ALL on *.* is deemed as a very bad practice). You should also read official MySQL documentation regarding possible privilege choices, to grant only those privileges truly needed, rather than using ALL

Installing a MySQL Server on CentOS

MySQL is an open-source relational database that is free and widely used. It is a good choice if you know that you need a database but don’t know much about all of the available options.

Note: CentOS 7 has replaced MySQL with MariaDB. To reflect this, instructions for MariaDB procedures are included in this article.

Install the MySQL database through the CentOS package manager (yum) by running the following commands at a command prompt:

#sudo yum install mysql-server
#sudo /sbin/service mysqld start

Run the following command:

sudo /usr/bin/mysql_secure_installation

Press Enter to give no password for root when prompted for it.

To apply some reasonable security to your new MySQL server answer yes to all the prompts. In order, those prompts enable you set the root password, remove anonymous users, disable remote root logins, delete the test database that the installer included, and then reload the privileges so that your changes will take effect.

Install MariaDB

Install the MariaDB server through the CentOS package manager (yum) by running the following command at a command prompt:

sudo yum install mariadb-server mariadb

Allow remote access

If you have iptables enabled and want to connect to the MySQL database from another computer, you must open a port in your server’s firewall (the default port is 3306). You don’t need to do this if the application that uses MySQL is running on the same server.

If you need to open a port, add the following rules in iptables to open port 3306

iptables -I INPUT -p tcpdport 3306 -m state –state NEW,ESTABLISHED -j ACCEPT
iptables -I OUTPUT -p tcp –sport 3306 -m state –state ESTABLISHED -j ACCEPT

Start and stop the database service

After the installation is complete, you can start the database service by using the commands in this section. If the system is already started, a message informs you that the service is already running.

Start and stop MySQL

Use the following command to start MySQL:

#sudo /sbin/service mysqld start

Use the following command to stop MySQL:

sudo /sbin/service mysqld stop

Start and stop MariaDB

Use the following command to start MariaDB:

#sudo systemctl start mariadb.service

Use the following command to stop MariaDB:

#sudo systemctl stop mariadb.service

Launch at reboot

To ensure that the database server launches after a reboot, you must enable the chkconfig utility. Use the following commands to do this.

Enable chkconfig on MySQL

#sudo chkconfig mysqld on

Enable chkconfig on MariaDB

#sudo systemctl enable mariadb.service

Start the mysql shell

There is more than one way to work with a MySQL server, but this article focuses on the most basic and compatible approach: the mysql shell.

At the command prompt, run the following command to launch the mysql shell and enter it as the root user:

#/usr/bin/mysql -u root -p
When you’re prompted for a password, enter the one that you set at installation or, if you haven’t set one, press Enter to submit no password.

The following mysql shell prompt should appear:


Set the root password

Because you have just installed the MySQL database server, the root account within MySQL has no password set yet. If you are logged in to the database server, set the root password by running the following command:

#/usr/bin/mysqladmin -u root password ‘new-password’

If you are not logged in to the database server you can remotely set the root password by specifying the hostname of your database server:

#/usr/bin/mysqladmin -u root –password=’new-password’ -h hostname-of-your-server ‘new-password’

How we get networking on Linux

How we get networking on Linux

just three commands.

Step One: Set Your IP Address

ifconfig eth0 netmask up

Step 2: Set Your Default Gateway

route add default gw

Step 3: Set Your DNS Server

echo “nameserver” > /etc/resolv.conf

That’s it.

Assuming you have valid addresses for yourself and your gateway


Running Process in Background on Linux

Adding & the end of the command

On Linux/Unix based systems you can put a task (such as command or script) in a background by appending a & at the end of the command line. In other words, you can say that easily send any process in the background.

# command &
# script-name &

# find / -name *.c > /root/output.txt &

Using & with nohup
You can use nohup command line-utility which allows to run command/process or shell script that can continue running in the background after you log out from a shell:

# nohup command-name &
# nohup find / -size +1k > /root/output.txt &