CentOS安装完成后, 一些环境部署

1、Tab补全忽略大小写

        编辑~/.inputrc(没有的话,就新建一个),在最后加一行: 
        set completion-ignore-case on
        #历史记录
            "\e[A": history-search-backward
            "\e[B": history-search-forward

2、yum源配置

        #备份:cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
        #下载:wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
        #替换:mv CentOS7-Base-163.repo /etc/yum.repos.d/CentOS-Base.repo
        yum clean all    //清除缓存
        yum makecache    //将服务器上的软件包信息缓存到本地,以提高搜索安装软件的速度
        yum update        //更新系统
附#编译环境安装
yum -y install gcc make glibc-devel ncurses-devel openssl-devel xmlto kernel-devel perl perl-devel perl-Data-Dumper

3、CentOS7之后的firewall替换成防火墙iptables

        ①、关闭firewall:
        #停止firewall服务:systemctl stop firewalld.service
        #禁止firewall开机启动:systemctl disable firewalld.service         

        ②、安装iptables防火墙
        #安装:yum install iptables-services
        #编辑防火墙配置文件:vi /etc/sysconfig/iptables (这里以开启80端口和3306端口为例)

        # Firewall configuration written by system-config-firewall

        # Manual customization of this file is not recommended.

        *filter

        :INPUT ACCEPT [0:0]

        :FORWARD ACCEPT [0:0]

        :OUTPUT ACCEPT [0:0]

        -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

        -A INPUT -p icmp -j ACCEPT

        -A INPUT -i lo -j ACCEPT

        -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

        -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

        -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

        -A INPUT -j REJECT --reject-with icmp-host-prohibited

        -A FORWARD -j REJECT --reject-with icmp-host-prohibited

        COMMIT

        #保存退出::wq!
        #最后重启防火墙使配置生效:systemctl restart iptables.service
        #设置防火墙开机启动:systemctl enable iptables.service

4、关闭SELINUX

        (查看:getenforce 临时修改:setenforce 0)
        #修改配置文件:vi /etc/selinux/config
        #注释掉:
                   
#SELINUX=enforcing
                   #SELINUXTYPE=targeted
        #增加:SELINUX=disabled
        #保存退出::wq!
        #使配置立即生效:setenforce 0

5、Apache安装

        #安装:yum -y install httpd        
        #设置apache开机启动:systemctl enable httpd.service       
        #启动apache:systemctl start httpd.service     
        #停止apache:systemctl stop httpd.service     
        #重启apache:systemctl restart httpd.service

6、数据库Mariadb安装(Mysql在后面)

        #安装:yum -y install mariadb-server mariadb        
        mariadb数据库的相关命令:
        #启动MariaDB:systemctl start mariadb      
        #停止MariaDB:systemctl stop mariadb      
        #重启MariaDB:systemctl restart mariadb      
        #设置开机启动:systemctl enable mariadb     
        #登录>
        mysql -u root
            ①设置root密码
                set password for 'root'@'localhost' =password('password');
            ②新建用户
                create user 'username'@'%' identified by 'password';
            ③授权
                grant all privileges on *.* to 'username'@'%' identified by 'password';
                本地登录授权
                grant all privileges on *.* to 'username'@'localhost' identified by 'password';

7、php安装

        #安装:yum -y install php php-mysql
        #一些的扩展的安装:
        yum -y install php-pdo php-pdo_mysql php-json php-filter php-openssl php-mbstring php-zlib php-curl php-gd php-iconv

8、mysql安装

        ①下载安装包mysql-5.6.34-linux-glibc2.5-x86_64.tar(可前往官网自行下载:http://dev.mysql.com/downloads/mysql/)
        ②卸载系统自带的Mariadb
               rpm -qa|grep mariadb     // 查询出来已安装的mariadb  
               rpm -e --nodeps 文件名  // 卸载mariadb,文件名为上述命令查询出来的文件  
            删除etc目录下的my.cnf
               rm /etc/my.cnf            
        ③创建用户组
               groupadd mysql
            创建用户
               useradd -g mysql mysql
        ④解压安装包
               tar -xvf mysql-5.6.34-linux-glibc2.5-x86_64.tar 或者
               tar -zxvf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz
           解压的文件夹重命名为mysql
               mv 解压出来的文件夹名 mysql
        ⑤修改配置文件
               copy一份/usr/local/mysql/support-files/下的my-default.cnf文件到/etc下命名为my.cnf
            大概修改为如下

    [mysql]
    default-character-set=utf8mb4
    socket=/var/lib/mysql/mysql.sock


    [mysqld]

    socket=/var/lib/mysql/mysql.sock
    port=3306
    basedir=/usr/local/mysql/mysql-5
    datadir=/usr/local/mysql/mysql-5/data/db_0
    character-set-server=utf8mb4

    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

        ⑥运行安装脚本mysql目录下执行(对应版本,命令不同)

               当前版本mysql最上层目录执行./scripts/mysql_install_db --user=mysql   # MySQL 5.6.34
               bin/mysql_install_db --user=mysql    # MySQL 5.7.5
               bin/mysqld --initialize --user=mysql   # MySQL 5.7.6 and up
               bin/mysql_ssl_rsa_setup                   # MySQL 5.7.6 and up
               #复制服务启动到开机启动目录下:cp support-files/mysql.server /etc/init.d/mysqld
        ⑦socket目录找不到(这个问题不一定会出现)
               mkdir   /var/lib/mysql
               chmod 777  /var/lib/mysql
        ⑧登录密码问题

		>mysql登录错误

		    mysqladmin: connect to server at 'localhost' failed
		    error: 'Access denied for user 'root'@'localhost' (using password: YES)'

		>修改密码处理方案之一

		    ①停止服务 /etc/init.d/mysqld stop

		    ②mysqld_safe --skip-grant-tables &

		    ③输入 mysql -uroot -p 回车进入

		        >use mysql;
		        >update user set password=PASSWORD("newpass")where user="root"; 
                更改密码为 newpassord
		        > flush privileges; 更新权限
		        > quit 退出

		    ④/etc/init.d/mysqld restart

		    ⑤mysql -uroot -p新密码进入


        >登陆成功改密码以及创建新用户
            update user set password=PASSWORD("rootpass") where user="root"
			create user 'username'@'%' identified by 'userpass';
			grant all on *.* to 'username'@'%';
			flush privileges;

9、添加环境变量

                ①vi /etc/profile
                ②shift+g跳到最后一行o, 新增一行内容类似: 
                              export PATH=$PATH:/usr/local/mysql/bin
                ③source /etc/profile 生效
        
                
  

猜你喜欢

转载自blog.csdn.net/inaUI/article/details/81635029