CentOS系统 服务器环境配置

远程连接

Mac系统,终端terminal
ssh 服务器用户名@ip (如:ssh root@xxx.xxx.xxx.xxx)
输入密码

python3安装

开发依赖:

# yum -y groupinstall development
# yum -y install zlib-devel

安装python:

[root@VM_58_11_centos ~]# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz  获取安装包

[root@VM_58_11_centos ~]# tar -zxf Python-3.6.1.tgz  解压缩

[root@VM_58_11_centos ~]# cd Python-3.6.1   定位到文件夹

#查看安装包文件
[root@VM_58_11_centos Python-3.6.1]# ls
[root@localhost Python-3.6.1]# ./configure  添加配置
[root@localhost Python-3.6.1]# make      编译源码
[root@localhost Python-3.6.1]# make install     执行安装

xampp

xampp安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# wget http://sourceforge.net/projects/xampp/files/XAMPP%20Linux/5.6.14/xampp-linux-x64-5.6.14-0-installer.run  xampp下载
# chmod 777 xampp-linux-x64-5.6.14-0-installer.run 赋执行权限
# ./xampp-linux-x64-5.6.14-0-installer.run    安装
# /opt/lampp/lampp start 启动xampp
# /opt/lampp/lampp stop 停止xampp
# /opt/lampp/lampp security 设置密码

卸载xampp
# /opt/lampp/lampp stop
# rm -rf /opt/lampp

添加开机启动服务
sudo ln -s /opt/lampp/lampp /etc/init.d/lampp
sudo chkconfig --add lampp

远程连接mysql报错

2013 - Lost connection to MySQL server at ‘reading initial communication packet’, system error: 0

未解决

MySQL

安装

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm 
[root@localhost src]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm 
[root@localhost src]#  yum -y install mysql-server 

配置my.cnf

vim /etc/my.cnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server_id = 1
expire_logs_days = 3

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

启动mysql服务

service mysqld restart

重置密码

获取随机产生的密码
# grep "password" /var/log/mysqld.log    
1
2
[root@VM_32_16_centos ~]# grep "password" /var/log/mysqld.log
2018-11-28T07:30:50.436132Z 1 [Note] A temporary password is generated for root@localhost: La2aQvn&M=o-
使用该密码进入数据库

[root@VM_32_16_centos ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.24

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
重置密码前无法操作数据库
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
修改密码

密码需为包含大小写,数字及符号的字符串
alter user ‘root’@’localhost’ identified by ‘包含大小写,数字及符号的字符串’;

添加新用户
grant all on *.* to 'newroot'@'%' identified by '密码'  with grant option;

@’%’可以任意IP登录,@IP地址则限制只能让指定IP登录

刷新权限
 flush privileges;

远程连接

2003 - Can't connect to MySQL server on 'XXX.xxx.xxx.xxx'

参考Remote Access MySQL connection error:https://stackoverflow.com/questions/29370829/remote-access-mysql-connection-error?spm=a2c4e.11153940.blogcont614613.12.57664a72R9A5pg

检查tcp

[root@VM_32_16_centos ~]# nc -l -p 3306
Ncat: bind to :::3306: Address already in use. QUITTING.

如果没有安装nc,先安装

# yum install nc

检查端口

[root@VM_32_16_centos ~]# nc ip地址 3306
Ncat: Connection timed out.

If this is not working, this is not a mysql server configuration issue but a network issue, and you must check your router firewall rules.
Otherwise, your problem comes from mysql server settings. Check your mysql configuration file for bind-address, and remove them to make mysqld accept clients from any IP address.

防火墙问题。

解决方法(已解决)

通过使用SSH通过连接。端口22,用户名密码为使用ssh登陆服务器时的用户名密码,常规里ip为localhost,端口3306,用户名密码为mysql的用户名密码。