Operations 8 min read

Common Linux Server Administration Tasks: Redis Password Setup, MySQL Replication Recovery, Nginx HTTPS Redirection, Security Measures, Zabbix Monitoring, and Configuration Tips

This guide provides step‑by‑step instructions for securing Redis with a password, recovering MySQL master‑slave replication, redirecting HTTP to HTTPS in Nginx, defending Linux servers against attacks, configuring Zabbix monitoring for MySQL, and various Nginx and MySQL configuration tricks.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Common Linux Server Administration Tasks: Redis Password Setup, MySQL Replication Recovery, Nginx HTTPS Redirection, Security Measures, Zabbix Monitoring, and Configuration Tips

1. Setting a password for Redis on Linux

Edit the Redis configuration file and enable the requirepass directive with your own password, then restart the service.

vim /etc/redis.conf

#requirepass foobared # remove the comment and replace foobared with your password

requirepass 123456

Restart Redis:

cd /usr/local/bin

./redis-server /etc/redis.conf

Test the connection:

./redis-cli

When prompted with (error) NOAUTH Authentication required. , authenticate:

auth 123456

2. Recovering MySQL master‑slave disconnection errors

Typical recovery steps:

slave stop;

SET GLOBAL sql_slave_skip_counter = 1;

slave start;

If a power outage caused desynchronization, extract the last bin‑log position from the master and re‑configure the slave:

mysqlbinlog mysql-bin.xxxx > binxxxx.txt

tail -n 100000 binxxxx.txt > tail-binxxxx.txt

Find the final Position value, then on the slave execute:

slave stop;

change master to master_host='ip', master_user='username', master_password='password', master_log_file='mysql-bin.xxxx', master_log_pos=xxxx;

slave start;

To skip specific errors (e.g., duplicate key, missing table), add to my.cnf :

slave-skip-errors = 1062,1032,1060

3. Redirecting Nginx port 80 to 443

Add the following to your server block:

if ($server_port = 80) {

return 301 https://$server_name$request_uri;

}

or

if ($scheme = http) {

return 301 https://$server_name$request_uri;

}

Also handle HTTP‑to‑HTTPS error:

error_page 497 https://$server_name$request_uri;

4. Responding to Linux server attacks

Identify the attack type: traffic‑based attacks can be mitigated with CDN; website defacement or malicious links can be handled with security tools such as “安全狗” or “者护卫神”. For massive DDoS, consider hardware firewalls.

Detection steps:

Use top to spot abnormal CPU/memory usage.

Inspect /var/log/secure for suspicious SSH attempts.

Run who to list logged‑in users.

Check deployed applications for known vulnerabilities.

Remediation actions:

Change all passwords immediately.

Notify network engineers to adjust firewall rules.

Enable the host firewall.

Change the default SSH port.

Close unused ports with netstat -ntlp and stop related services.

Disable unnecessary accounts in /etc/passwd .

Inspect processes with ps -ef and kill malicious ones.

Review HTTP server logs.

Use tcpdump -nn -i eth0 to capture suspicious traffic.

5. Monitoring MySQL with Zabbix

Zabbix collects metrics via its agent or SNMP and stores them in a database. Monitoring data is divided into historical tables (e.g., history_uint ) that record metric values over time.

6. Types of MySQL logs

MySQL maintains several logs:

Error log

General query log

Binary log (binlog)

Slow query log

7. Backing up MySQL without locking tables

For MyISAM, use:

mysqldump --skip-lock-tables …

For InnoDB, use a single‑transaction dump:

mysqldump --single-transaction …

8. Configuring Nginx IP‑based access control

Add the following to the location / block of the default site configuration:

allow 132.23.22.185;

deny all;

Then restart Nginx:

sudo service nginx restart

9. Defining custom error pages in Nginx

In nginx.conf , enable error interception:

fastcgi_intercept_errors on;

Define error pages inside the server block, for example:

error_page 404 = /404.htm;

Full example server configuration:

server {

listen 80;

server_name www.zhichun.com;

index index.html index.htm index.php;

error_page 404 = /404.htm;

include location.conf;

root /home/www/logs;

}

Place the custom 404 page in the site’s root directory, test the configuration with /usr/local/nginx/sbin/nginx -t , and restart if no errors are reported.

RedislinuxmysqlsecuritynginxServer Administration
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.