ubuntu搭建LNMP環境(一)

1.安裝 MySQL 5.7

安裝 MySQL 運行命令:
1. apt-get -y install mysql-server mysql-client

這裏寫圖片描述

第一步報錯在命令前加sudo 然後提示密碼;解決問題。
然後提示進程佔用問題
原因:apt-get被ubuntu軟件中心佔用,終端輸入命令:ps -e,可以查看到apt-get進程
總得來說系統中apt-get只能被一個佔用。
解決方案
強制解鎖,命令

sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock

這裏寫圖片描述

2.你會被要求提供MySQL的root用戶密碼 :
New password for the MySQL “root” user: <– yourrootsqlpassword
Repeat password for the MySQL “root” user: <– yourrootsqlpassword

3.執行命令

root@server1:~# mysql_secure_installation

你會問這些問題:
保護MySQL服務器部署。
Enter password for user root: <– Enter the MySQL root password
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: <– Press y if you want this function or press Enter otherwise.
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : <– Press enter
… skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : <– y
Success.
Normally, root should only be allowed to connect from
‘localhost’. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : <– y
Success.
By default, MySQL comes with a database named ‘test’ that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : <– y
– Dropping test database…
Success.
– Removing privileges on test database…
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : <– y
Success.
All done!
MySQL is secured now.

4.mysql初始化完畢後,我們現在來創建zabbix數據庫及其用戶,使用如下命令:
mysql -uroot -pzabbix’ -e “create database zabbix default character set utf8 collate utf8_bin;”
mysql -uroot -p
zabbix’ -e “grant all on zabbix.* to ‘zabbix’@’%’ identified by ‘zabbix’;”
第二條語句有誤,查資料後解決:

這裏寫圖片描述

但因爲我建數據庫時手賤,把密碼等級選了第二個,應該選low
這裏寫圖片描述

通過 SET GLOBAL validate_password_policy='LOW'; 命令,降低安全等級後,就可以直接使用,限制是必須8個字符以上;
這裏寫圖片描述

現在來測試剛剛創建的zabbix用戶,是否可以連接mysql數據庫,如下:

mysql -uzabbix -pzabbix

mysql> show databases;
——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |
| sys |
| zabbix |
+——————–+
5 rows in set (0.06 sec)
通過上圖,我們可以很明顯的看出zabbix用戶是可以正常連接數據庫的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章