开发环境初始化(centos7)

Posted in 2016-12-26 14:56 | Category: Linux | Tags: centos redis linux python mysql

新建用户

[root@localhost]# passwd honmaple
Changing password for user honmaple.
New password:
BAD PASSWORD: The password contains the user name in some form
Retype new password:
passwd: all authentication tokens updated successfully.

安装mysql

参考步骤: http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

下载安装

[root@localhost]# wget http://dev.mysql.com/get/mysql57-community-release-el6-8.noarch.rpm
[root@localhost]# rpm -Uvh mysql57-community-release-el6-8.noarch.rpm
[root@localhost]# yum list installed | grep mysql
mysql57-community-release.noarch     el6-8                          installed
[root@localhost]# yum install mysql-community-server
错误:软件包:2:postfix-2.10.1-6.el7.x86_64 (@anaconda)
          需要:libmysqlclient.so.18(libmysqlclient_18)(64bit)
          正在删除: 1:mariadb-libs-5.5.50-1.el7_2.x86_64 (@updates)
              libmysqlclient.so.18(libmysqlclient_18)(64bit)
          取代,由: mysql-community-libs-5.7.14-1.el6.x86_64 (mysql57-community)
              未找到
          可用: 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 (base)
              libmysqlclient.so.18(libmysqlclient_18)(64bit)
          可用: 1:mariadb-libs-5.5.47-1.el7_2.x86_64 (updates)
              libmysqlclient.so.18(libmysqlclient_18)(64bit)
错误:软件包:2:postfix-2.10.1-6.el7.x86_64 (@anaconda)
          需要:libmysqlclient.so.18()(64bit)
          正在删除: 1:mariadb-libs-5.5.50-1.el7_2.x86_64 (@updates)
              libmysqlclient.so.18()(64bit)
          取代,由: mysql-community-libs-5.7.14-1.el6.x86_64 (mysql57-community)
             ~libmysqlclient.so.20()(64bit)
          可用: 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 (base)
              libmysqlclient.so.18()(64bit)
          可用: 1:mariadb-libs-5.5.47-1.el7_2.x86_64 (updates)
              libmysqlclient.so.18()(64bit)
 您可以尝试添加 --skip-broken 选项来解决该问题
 您可以尝试执行:rpm -Va --nofiles --nodigest
[root@localhost]# yum remove mysql-libs
[root@localhost]# yum install mysql-community-server

Mysql初始化

[root@localhost]# mysqld_safe --skip-grant-tables &
[1] 21319
[root@localhost]# 2016-12-27T08:00:21.105902Z mysqld_safe Logging to '/var/log/mysqld.log'.
2016-12-27T08:00:21.108446Z mysqld_safe Logging to '/var/log/mysqld.log'.
2016-12-27T08:00:21.133704Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

进入mysql

设置root密码

[root@localhost]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'youpassword';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> show global variables like "%read_only%";
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| innodb_read_only | OFF   |
| read_only        | OFF   |
| super_read_only  | OFF   |
| tx_read_only     | OFF   |
+------------------+-------+
4 rows in set (0.00 sec)

mysql> set global read_only=ON;
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'youpassword';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'youpassword';
Query OK, 0 rows affected (0.00 sec)

mysql> set global read_only=OFF;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

新增mysql用户

参考链接: http://dev.mysql.com/doc/refman/5.7/en/adding-users.html

mysql> select host,user from user;
+-----------+-----------+
| host      | user      |
+-----------+-----------+
| localhost | mysql.sys |
| localhost | root      |
+-----------+-----------+
2 rows in set (0.00 sec)

mysql> CREATE USER 'yourname'@'%' IDENTIFIED BY 'yourpassword';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'yourname'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW GRANTS FOR 'yourname'@'%';
+-----------------------------------------------------------------+
| Grants for yourname@%                                           |
+-----------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'yourname'@'%' WITH GRANT OPTION |
+-----------------------------------------------------------------+
1 row in set (0.00 sec)

安装redis

首先运行

[root@localhost] # yum list redis

yum安装

[root@localhost] # yum install redis

编译安装

[root@localhost]# yum install gcc gcc-c++ tcl
[root@localhost]# wget http://download.redis.io/releases/redis-3.2.3.tar.gz
[root@localhost]# tar xzf redis-3.2.3.tar.gz
[root@localhost]# cd redis-3.2.3
[root@localhost redis-3.2.3]# ./configure --prefix=/opt/redis
[root@localhost redis-3.2.3]# make
[root@localhost redis-3.2.3]# cd src && make all
make[1]: 进入目录“/root/redis-3.2.3/src”
    CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录
 #include <jemalloc/jemalloc.h>
                               ^
编译中断。
make[1]: *** [adlist.o] 错误 1
make[1]: 离开目录“/root/redis-3.2.3/src”
make: *** [all] 错误 2

[root@localhost redis-3.2.3]# make MALLOC=libc
......
Hint: It's a good idea to run 'make test' ;)

make[1]: 离开目录“/root/redis-3.2.3/src”
[root@localhost redis-3.2.3]# make test
[root@localhost redis-3.2.3]# make install
[root@localhost redis-3.2.3]# cp redis.conf /etc/

安装指定版本的python

python2.7.11 为例

下载编译

下载地址https://www.python.org/downloads/

[root@localhost] # wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tar.xz
[root@localhost] # tar xvJf Python-2.7.11.tar.xz
[root@localhost] # cd Python-2.7.11
[root@localhost] # ./configure --prefix=/opt/python-2.7.11
[root@localhost] # make
[root@localhost] # make install

ln -s /opt/python-2.7.11/bin/python /usr/bin/python

更改头注释

#!/usr/bin/env python

TO

#!/usr/bin/env python2

位置

/usr/bin/yum
/usr/bin/pip
/usr/bin/virtualenv
/usr/libexec/urlgrabber-ext-down